简体   繁体   中英

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.

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.

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.

The modifiers property of the GetFeature control is null when I request the control like this:

.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}.

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.

Is this an oversight by me? The OL documentation does not state that the modifiers should be declared manually. However, no default values are given in the documentation page.

Dennis

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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