zoukankan      html  css  js  c++  java
  • Openlayers 2 取消鼠标缩放地图的功能

    需要实现的功能:

    取消鼠标缩放地图,即滚动鼠标的滚轮地图没有响应事件,只能用鼠标平移地图

    版本:OpenLayers 2.13.1

    测试代码直接用官方例子http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/osm.html

    直接上代码

    原始代码:

            var map, layer;
            function init(){
                map = new OpenLayers.Map( 'map');
                layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
                map.addLayer(layer);
                map.setCenter(
                    new OpenLayers.LonLat(-71.147, 42.472).transform(
                        new OpenLayers.Projection("EPSG:4326"),
                        map.getProjectionObject()
                    ), 12
                );    
            }

    修改后的代码:

            var map, layer;
            function init(){
                map = new OpenLayers.Map('map',{
                            controls: [
                                new OpenLayers.Control.Navigation({ 'zoomWheelEnabled': false }),
                                new OpenLayers.Control.MousePosition(),
                                new OpenLayers.Control.Zoom()
                            ]
                        }
                );
                layer = new OpenLayers.Layer.OSM("Simple OSM Map");
                map.addLayer(layer);
                map.setCenter(
                    new OpenLayers.LonLat(-71.147, 42.472).transform(
                        new OpenLayers.Projection("EPSG:4326"),
                        map.getProjectionObject()
                    ), 12
                );    
            }

    可见在map实例化时,将默认的controls修改一下即可

    增加部分代码为:

                  controls: [
                                new OpenLayers.Control.Navigation({ 'zoomWheelEnabled': false }),
                                new OpenLayers.Control.MousePosition(),
                                new OpenLayers.Control.Zoom()
                            ]
    

      

  • 相关阅读:
    模板方法设计模式
    单一职责原则
    开闭原则
    uml
    迭代器模式
    观察者模式
    工厂模式
    代理模式
    idea本地Maven仓库不能下载依赖jar包的解决方案
    selenium 使用教程详解-java版本
  • 原文地址:https://www.cnblogs.com/marost/p/6900095.html
Copyright © 2011-2022 走看看