[OpenLayers-Users] GetFeature Control - WFS MapServer toggle to unselect

myOpenLayersUName joanne.mcgraw at SYMPATICO.CA
Tue May 24 15:06:32 EDT 2011


I am trying to understand how the toggle works for the GetFeature Control
because it doesn't seem to be working for me and I'm not clear what I have
to do to make it do so.

The following is the code I used to create the control in a test page:

    var layer = this.map.layers[0];
    var featureInfo = new OpenLayers.Control.GetFeature({
        protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layer, {
            featurePrefix: 'ms'
            ,geometryName: 'msGeometry'
            ,featureType: layer.params.LAYERS
        }),
        box: true,
        multipleKey: "shiftKey",
        toggleKey: "ctrlKey"
    });

    var select = new OpenLayers.Layer.Vector("Selection", {styleMap:
        new OpenLayers.Style(OpenLayers.Feature.Vector.style["select"])
    });
    this.map.addLayers([select]);

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



If I "click" on a polygon feature, the WFS GetFeature request is posted and
the response used to create a new Feature.Vector that is added to the
"select" layer above and it looks selected. Everything's fine there.

Now, with the "Ctrl" button pressed (and, as I understand it, in "toggle"
mode), I mouse "click" on the same feature with a view to de-selecting it.
Unfortunately, that's not what happens. It looks like it selects it
again...and again and again for as many times as I click on it with the Ctrl
button depressed. The transparency of the polygon just keeps getting less
and less.

In the GetFeature control's select method, there's an if expression
"(this.features[feature.fid || feature.id])" that looks to see if the
feature returned by the GetFeature request already exists in the list of
features in the "select" vector layer. For me, it never does because the
second getFeature request has created a new feature with a new feature id
and so it will never already exist in the list.

I assumed that somewhere I'm supposed to indicate what attribute value
should be used to create that feature id so that if a given polygon is
clicked on while it's already selected, it will not create a new feature but
recognize that it's already part of the selected set. I can't find any
documentation to that effect though, so I'm guessing I'm off track. 

Can anyone point me in the right direction? How does that if expression ever
get evaluated to true?


--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/GetFeature-Control-WFS-MapServer-toggle-to-unselect-tp6399998p6399998.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list