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()
                            ]
    

      

  • 相关阅读:
    推箱子
    去掉两个最高分、去掉两个最低分,求平均分
    投票选班长
    彩票
    闰年、平年
    闹钟
    手机号抽奖
    for练习--侦察兵
    兔子、棋盘放粮食、猴子吃桃
    for练习--凑法
  • 原文地址:https://www.cnblogs.com/marost/p/6900095.html
Copyright © 2011-2022 走看看