简体   繁体   English

Mapael JS禁用缩放

[英]Mapael js disable zoom

So I am trying to disable the zoom option in my Map when a user clicks on a map region, using the event handlers it works well for the attributtes like color and so, but not working to disable the zoom. 因此,当用户单击地图区域时,我尝试使用事件处理程序禁用“地图”中的“缩放”选项,该事件处理程序可很好地适用于诸如颜色等属性,但无法禁用缩放。

/*  ...  */

, defaultArea: {
    attrs : {
        fill : "#28282b"
        //, stroke: "#474c4b"
    }
    , attrsHover : {
        fill: "#3da879"
    }
    , text : {
        attrs : {
            fill : "#6d6d6d"
        }
        , attrsHover : {
            fill : "#fff"
        }
    }


    ,eventHandlers: {
        click: function (e, id, mapElem, textElem,elemOptions) {
            var newData = {
                'areas': {}
                ,'zoom': {}
            };                                         
            if (mapElem.originalAttrs.fill == "#28282b") {

                newData.areas[id] = {
                    attrs: {
                        fill: "#3da879"
                    }
                    , text : {
                        attrs : {
                            fill : "#fff"
                        }
                        , attrsHover : {
                            fill : "#fff"
                        }
                    }
                };

                newData.zoom[id] = {
                    enabled : false,
                    maxLevel : 10
                };



            } else {
                newData.areas[id] = {
                    attrs: {
                        fill: "#28282b"
                    }
                    , text : {
                        attrs : {
                            fill : "#6d6d6d"
                        }
                        , attrsHover : {
                            fill : "#fff"
                        }
                    }                                
                };
            }

            $(".mapcontainer").trigger('update', [newData]);
        }
    }

/*  ...  */     

Have you checked this JSFiddle example : http://jsfiddle.net/neveldo/ejf9dsL9/ ? 您是否检查过以下JSFiddle示例: http : //jsfiddle.net/neveldo/ejf9dsL9/ It shows how to zoom on a specific area by triggering a 'zoom' event when the user click on a button : 它显示了如何在用户单击按钮时通过触发“缩放”事件来缩放特定区域:

$maparea2.trigger('zoom', {level : 10, latitude : 45.758888888889, longitude : 4.8413888888889});

If you want to disable zoom feature after, you can unbind the 'mousewheel' event on the map container. 如果以后要禁用缩放功能,则可以取消绑定地图容器上的“ mousewheel”事件。

I hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM