简体   繁体   English

OpenLayers:GetFeature WFS请求在鼠标输入之前不会触发featureselected事件

[英]OpenLayers: GetFeature WFS request doesn't trigger the featureselected event prior to mouse input

I have setup a GetFeature control with a WFS protocol which works fine with a mouse click after the control has been added and activated. 我已经使用WFS协议设置了GetFeature控件,在添加并激活该控件后,单击鼠标即可正常工作。

selectControl.events.register("featureselected", this, function (e) { 
vectorLayer.addFeatures([e.feature]); 
}); 
selectControl.events.register("featureunselected", this, function (e) { 
    vectorLayer.removeFeatures([e.feature]); 
}); 
map.addControl(selectControl); 
selectControl.activate(); 

I want to automatically request the control from a newly created point location like so: 我想从新创建的点位置自动请求控件,如下所示:

map.controls[5].request(new OpenLayers.Bounds([lonLat.lon, lonLat.lat, lonLat.lon, lonLat.lat]), { single: true });

This works but only after I have triggered the request at least once with mouse input. 这有效,但是仅在我至少使用鼠标输入触发一次请求之后。 Prior to the manual request the automatic request will not trigger the featureselected event. 在手动请求之前,自动请求将不会触发featureselected事件。

Once I have triggered the event with a mouse click I can use the control request method with bounds input. 一旦用鼠标单击触发了事件,就可以将控制请求方法与边界输入一起使用。

Any input is more than welcome since I already put way to much time into this. 因为我已经花了很多时间在此方面,所以任何输入都值得欢迎。

Thanks, Dennis 谢谢,丹尼斯

I found the issue myself. 我自己发现了问题。 I am not sure whether this is a bug in the OpenLayers script. 我不确定这是否是OpenLayers脚本中的错误。

The modifiers property of the GetFeature control is null when I request the control like this: 当我这样请求控件时,GetFeature控件的Modifys属性为null:

.request(new OpenLayers.Bounds([lonLat.lon, lonLat.lat, lonLat.lon, lonLat.lat]), { single: true });

and not by clicking into the map object. 而不是单击地图对象。

Once I called the control by clicking in the map the modifiers property is set to {multiple:null,toggle:null}. 一旦我通过单击地图来调用控件,修饰符属性将设置为{multiple:null,toggle:null}。

If I declare the modifiers property on the control like this: 如果我像这样在控件上声明修饰符属性:

.modifiers = {multiple:null,toggle:null}

I can run the .request without clicking in the map. 我可以在不单击地图的情况下运行.request。

Is this an oversight by me? 这是我的疏忽吗? The OL documentation does not state that the modifiers should be declared manually. OL文档没有声明应手动声明修饰符。 However, no default values are given in the documentation page. 但是,文档页面中未提供默认值。

Dennis 丹尼斯

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

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