Dear all,
We use Geoserver with PostGIS and OpenLayers to display a river network as
WMS Layer. The user should be able to click on the river and get its name as
Popup. It is no problem so far. But if one is clicking between several
rivers then selection becomes very confusing. In some cases rivers that are
located much farer from mouse click then others are selected. Then Popup
comes with the name of the river that in some cases even not in the current
view. I guess by default LineString selection is based on Bounding Box. It
means that if I click between several LineStrings then one (or many lines)
with BBox covering click point will be selected. Is it possible to solve
this problem on OpenLayers side or a have to change the default behaviour of
Geoserver?
I tried to use geometry.atPoint() function but it also based on BBox. The
only function I found so far that works directly with LineString and not the
BBox is geometry.distanceTo(). I ca use it to check how far the LineString
from mouse click. But it needs some additional conversion of coordinates.
Another disadvantage is that the whole geometry should be transferred from
the server.
Is there more elegant solution? Below is my code.
Thanks a lot in advance
var streams = new OpenLayers.Layer.WMS(…);
streamControl = new OpenLayers.Control.GetFeature({
protocol: OpenLayers.Protocol.WFS.fromWMSLayer(streams),
box: false,
toggleKey: "ctrlKey",
});
streamControl.events.register('featureselected', this, function(e) {
if (e.feature.geometry.distanceTo(new
OpenLayers.Geometry.Point(lonlatMouseClick.lon,lonlatMouseClick.lat)){
var popupStream = new OpenLayers.Popup("chicken",
lonlatMouseClick,
new OpenLayers.Size(200,200),
e.feature.attributes.stream_name,
true);
map.addPopup(popupStream);
popupStream.show();
}
});
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users