[OpenLayers-Users] SelectFeature on vector layer under WMS layer

Steven den Hartog steven.den.hartog at gmail.com
Wed Dec 18 09:06:30 PST 2013


Hi Marc-André,

I've had a similar problem, and it's pretty hard to fix.
The way I fixed it was to add a click event on the WMS layer, and when the
WMS layer is clicked, get the mouse position and then manually check what
was selected.
Here pos is an object where pos.x is the x position of the mouse and pos.y
is the y position of the mouse:

var target = document.elementFromPoint(pos.x, pos.y)
 if (target && target._featureId) {
                        //It's possible to have multiple vector layers, so
we have to loop through all of them to found out what we clicked on.
                        for (var i in wfslayers) {
                            //Find the corresponding feature by id
                            var feature =
wfslayers[i].getFeatureById(target._featureId);
                            if (feature) {
                                //If feature is found, it won't be null or
undefined. Then we can select it, and break the for loop.
                                select.select(feature);
                                break;
                            }
                        }
                    }

I hope this was enough to solve your problem, if you need more information
don't hesitate to ask.

Steven den Hartog


2013/12/18 Marc-André Trottier <trottier.marcandre at gmail.com>

> I have a selectFeature define on my vector layer :
> so, 'featureselected' event never start because my WMS layer is on top.
> i looked for start manually the event but i was stopped when i saw on line
> #212 of Feature.js, the param 'evt' don't have the polygon who must be
> selected.
> How can i do this ?
>
> P.S.: all that start with IE 8, because it can not support correctly
> labelling on layer vector.
> on IE 8, label is selected when you pass over and the polygon is
> unselected.
>
> some code :
>
> reg_admin = new OpenLayers.Layer.Vector("reg_admin", {
> isBaseLayer:false,
> rendererOptions: {zIndexing: true},
>  minResolution: 1200,
> maxResolution: 5000,
> clone:"",
>  strategies: [new OpenLayers.Strategy.BBOX()],
> protocol: new OpenLayers.Protocol.WFS({
> url:  "/cgi-wms/mapserv?map=dpop&service=wfs&version=1.1.0",
>  featureType: "dpop_criminalite_generale_v_s",
> geometryName: "geom_s"
> }),
>  filter:
> new OpenLayers.Filter.Comparison({
> type: OpenLayers.Filter.Comparison.EQUAL_TO,
>  property: "year",
> value: "2012"
>                     })
> });
>
> reg_admin.events.on({
> 'featureselected': function(e) {
> bla bla bla
>  },
> 'featureunselected': function(e) {
> bla bla bla
>  }
> });
>
> var selecthover = new OpenLayers.Control.SelectFeature(
> reg_admin,
>  {
>   multiple: false,
>   hover: true
> }
>  );
>
> numeroRegion = new OpenLayers.Layer.WMS( "numberOnly",
>   '/cgi-wms/adnInternetV2?',
>  {layers: 'numberOnly',
>    format: szFormat,
>   transparent: true,
>   NOCACHE: Math.random()
>  },
>  oWMSOverlayOptions
>  );
> numeroRegion.setVisibility(true);
> numeroRegion.displayInLayerSwitcher = false;
>
> map.addControl(selecthover);
> selecthover.activate();
> map.addLayers([fondRelief, reg_admin, numeroRegion ]);
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20131218/577617a0/attachment.html>


More information about the Users mailing list