简体   繁体   English

带有Point的OpenLayers DrawFeature控件会破坏双击以进行缩放

[英]OpenLayers DrawFeature control with Point destroys double click to zoom

I have some simple code that I copied from one of the openlayers examples for drawing several different types of geometries on the map. 我有一些简单的代码是我从一个openlayers示例中复制的,用于在地图上绘制几种不同类型的几何图形。 The problem is, whenever the "point" geometry is selected, I lose the ability to double-click to zoom in. The only difference between the examples and my code is I'm registering the handlers to use MOD_SHIFT, because i want to retain the ability to pan/zoom. 问题是,无论何时选择“点”几何图形,我都无法双击放大。示例与代码之间的唯一区别是我正在注册处理程序以使用MOD_SHIFT,因为我想保留平移/缩放的能力。 Here is a snipit of code: 这是一段代码:

   point: new OpenLayers.Control.DrawFeature(this.geometryFilterLayer,
                            OpenLayers.Handler.Point, 

                            {
                                'done':  console.info("drew point")
                            },

                            {
                                keyMask: OpenLayers.Handler.MOD_SHIFT
                            }
                            ),
                        polygon: new OpenLayers.Control.DrawFeature(this.geometryFilterLayer,
                            OpenLayers.Handler.Polygon, 
                            {
                                'done':  console.info("drew polygon")
                            },

                            {
                                keyMask: OpenLayers.Handler.MOD_SHIFT
                            }
                            ),

The funny thing about the above code is, the 'done' event only gets fired when the control/handler is created, and the keyMask doesn't work at all -- I have to loop through this object and manually set the keyMask each time, but that's not the real problem at hand. 上面代码的有趣之处在于,“完成”事件仅在创建控件/处理程序时才会触发,而keyMask根本不起作用-我必须遍历此对象并每次手动设置keyMask ,但这并不是眼前的真正问题。

I've tried every way I can think of to register a dblclick event, but no matter what, I can't get it to zoom in when I double click. 我已经尽力尝试注册dblclick事件,但是无论如何,双击时都无法放大它。 It works fine on all the other geometries (bbox, point/radius, and polygon). 在所有其他几何体(bbox,点/半径和多边形)上都可以正常工作。

Can anybody give me some advice? 有人可以给我一些建议吗?

I never solved this issue, but ended up doing away with using MOD_XXX altogether. 我从未解决此问题,但最终完全放弃使用MOD_XXX。 Each different draw control had too much built-in functionality for what happens when you hold shift, ctrl, alt, etc. I ended up using custom Buttons and a toolbar, that way the user can explicitly select the drawing control themselves. 每个不同的绘制控件都具有太多的内置功能,可用于在您按住shift,Ctrl,Alt等时发生的事情。我最终使用了自定义按钮和工具栏,从而用户可以自己明确地选择绘制控件。

this.toolbar = new OpenLayers.Control.Panel({
                displayClass: 'olControlEditingToolbar'
            });
            map.addControl(this.toolbar);

var navButton = new OpenLayers.Control.Button({
                displayClass: "olControlNavigation", 
                title: "Navigation",
                trigger: lang.hitch(this, function(data){
                    this.toggleDrawControl("navigation");

                    navButton.activate();
                    pointButton.deactivate();
                    bboxButton.deactivate();
                    pointRadiusButton.deactivate();
                    polygonButton.deactivate();
                })
            }); 

...

this.toolbar.addControls([navButton, pointButton, bboxButton, pointRadiusButton, polygonButton]);

and my function to toggle draw controls (can be called externally, so that's why I re-call the activate and deactivate functions: 以及切换绘图控件的功能(可以在外部调用,因此这就是我重新调用激活和停用功能的原因:

 toggleDrawControl: function(geometryType){
            this.currentGeometryType = geometryType;
            for(key in this.drawControls) {
                var control = this.drawControls[key];
                if(geometryType == key) {
                    control.activate();
                    this.drawingButtons[key].activate();
                } else {
                    control.deactivate();
                    this.drawingButtons[key].deactivate();
                }
            }
        }

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

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