ArcGIS API for JS4.8二维地图状态控制

版权声明: https://blog.csdn.net/GISuuser/article/details/81385177

包括地图的缩放、旋转、平移。下面只写了禁止的方法,开启的方法对应着自己开发吧!

//二维视图
        var view = new MapView({
            map: map,
            container: "viewDiv",
            constraints: {
                rotationEnabled: false//禁止旋转
            }
        });


        view.when(function () {
            //禁止通过键盘+-缩放地图
            view.on("key-down", function(event){
                var prohibitedKeys = [ "+", "-", "Shift", "_", "=" ];
                var keyPressed = event.key;
                if(prohibitedKeys.indexOf(keyPressed) !== -1){
                    event.stopPropagation();
                }
            });
            //禁止滚轮缩放地图
            view.on("mouse-wheel", function(event){
                event.stopPropagation();
            });
            //禁止双击放大
            view.on("double-click", function(event){
                event.stopPropagation();
            });
            //禁止Ctrl+双击缩小
            view.on("double-click", ["Control"], function(event){
                event.stopPropagation();
            });
            //禁止移动地图
            view.on("drag", function(event){
                event.stopPropagation();
            });
            // 禁止通过上下左右箭头移动地图
            view.on("key-down", function(event){
                // prevents panning with the arrow keys
                var keyPressed = event.key;
                if(keyPressed.slice(0,5) === "Arrow"){
                    event.stopPropagation();
                }
            });
            //禁止Shift+拖拽拉框放大
            view.on("drag", ["Shift"], function(event){
                event.stopPropagation();
            });
            //禁止Shift+Ctrl+拖拽拉框缩小
            view.on("drag", ["Shift", "Control"], function(event){
                event.stopPropagation();
            });
        });

 

没有更多推荐了,返回首页