controler_zoom.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_zoom"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  11. </head>
  12. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
  13. <div id="map" style="width: 100%;height:100%"></div>
  14. <script type="text/javascript">
  15. var map,
  16. url = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/map-world/rest/maps/World";
  17. map = new ol.Map({
  18. target: 'map',
  19. controls: ol.control.defaults({attribution: false, zoom: false, rotate: false}),
  20. view: new ol.View({
  21. center: [0, 0],
  22. zoom: 3,
  23. projection: 'EPSG:4326',
  24. multiWorld: true
  25. })
  26. });
  27. var ele;
  28. //禁用双击缩放
  29. function disableDoubleClickZoom() {
  30. map.getInteractions().forEach(function (element, index, array) {
  31. if (element instanceof (ol.interaction.DoubleClickZoom)) {
  32. ele = element;
  33. ele.setActive(false);
  34. }
  35. });
  36. }
  37. //禁用拖动
  38. function disableDragPan() {
  39. map.getInteractions().forEach(function (element, index, array) {
  40. if (element instanceof ol.interaction.DragPan) {
  41. ele = element;
  42. ele.setActive(false);
  43. }
  44. });
  45. }
  46. //禁用鼠标wheel操作
  47. function disableMouseWheelZoom() {
  48. map.getInteractions().forEach(function (element, index, array) {
  49. if (element instanceof ol.interaction.MouseWheelZoom) {
  50. ele = element;
  51. ele.setActive(false);
  52. }
  53. });
  54. }
  55. disableDoubleClickZoom();
  56. disableDragPan();
  57. disableMouseWheelZoom();
  58. var layer = new ol.layer.Tile({
  59. source: new ol.source.TileSuperMapRest({
  60. url: url
  61. }),
  62. projection: 'EPSG:4326'
  63. });
  64. //zoom控件
  65. zoomControl = new ol.control.Zoom();
  66. map.addControl(zoomControl);
  67. //zoomBar控件
  68. map.addControl(new ol.control.ZoomSlider({}));
  69. map.addLayer(layer);
  70. </script>
  71. </body>
  72. </html>