1. 程式人生 > >(轉)OL2中設置鼠標的樣式

(轉)OL2中設置鼠標的樣式

format csdn 移動 初始 pbo led doc 代碼 detail

http://blog.csdn.net/gisshixisheng/article/details/49496289

概述:

在OL2中,鼠標默認是箭頭,地圖移動時,鼠標樣式是移動樣式;很多時候,為了形象起見,我們總是希望鼠標在地圖上的時候和移動地圖的時候鼠標的樣式不是默認的效果,本文講述如何實現這樣的效果。

實現方式:

通過下面的代碼實現修改鼠標樣式。

map.layerContainerDiv.style.cursor = ("url(img/openhand.cur),default");

在地圖初始化完成後,設置地圖的樣式,並添加map的move和moveend事件,實現的完整代碼如下:
[html] view plain copy print?
  1. <!DOCTYPE html>
  2. <html>
  3. <head lang="en">
  4. <meta charset="UTF-8">
  5. <title>openlayers map</title>
  6. <link rel="stylesheet" href="http://localhost/olapi/theme/default/style.css" type="text/css">
  7. <style>
  8. html, body{
  9. padding:0;
  10. margin:0;
  11. height:100%;
  12. width:100%;
  13. overflow: hidden;
  14. font-size: 12px;
  15. }
  16. #map1{
  17. width: 500px;
  18. height: 500px;
  19. float: left;
  20. overflow: hidden;
  21. border: 1px solid #f0e68c;
  22. }
  23. </style>
  24. <script src="../../../plugin/OpenLayers-2.13.1/OpenLayers.js"></script>
  25. <script src="../../../plugin/jquery/jquery-1.8.3.js"></script>
  26. <script>
  27. var map1;
  28. $(function(){
  29. var bounds = new OpenLayers.Bounds(
  30. 73.45100463562233, 18.16324718764174,
  31. 134.97679764650596, 53.531943152223576
  32. );
  33. var options = {
  34. controls: [],
  35. maxExtent: bounds,
  36. maxResolution: 0.2403351289487642,
  37. projection: "EPSG:4326",
  38. units: ‘degrees‘
  39. };
  40. map1 = new OpenLayers.Map(‘map1‘, options);
  41. var wms = new OpenLayers.Layer.WMS(
  42. "Geoserver layers - Tiled",
  43. "http://localhost:8088/geoserver/lzugis/wms",
  44. {
  45. "LAYERS": "province",
  46. "STYLES": ‘‘,
  47. format: ‘image/png‘
  48. },
  49. {
  50. buffer: 0,
  51. displayOutsideMaxExtent: true,
  52. isBaseLayer: true,
  53. yx : {‘EPSG:4326‘ : true}
  54. }
  55. );
  56. map1.addLayer(wms);
  57. map1.addControl(new OpenLayers.Control.Zoom());
  58. map1.addControl(new OpenLayers.Control.Navigation());
  59. map1.zoomToExtent(bounds);
  60. map1.layerContainerDiv.style.cursor = ("url(img/openhand.cur),default");
  61. map1.events.register("move", map1, function(){
  62. map1.layerContainerDiv.style.cursor = ("url(img/closedhand.cur),default");
  63. });
  64. map1.events.register("moveend", map1, function(){
  65. map1.layerContainerDiv.style.cursor = ("url(img/openhand.cur),default");
  66. });
  67. });
  68. </script>
  69. </head>
  70. <body>
  71. <div id="map1"></div>
  72. </body>
  73. </html>

(轉)OL2中設置鼠標的樣式