1

I'm having troubles with a highlight layer which I created on a map dynamically to put the selected feature on the top of all layers, so I can see it despite of a polygon layer which has been set visible on the SelectFeature method. It is working well so long I don't try to unselect it. The functions are like:

 var HighlightLayer = new OpenLayers.Layer.Vector('HighlightLayer', {
        visibility: false
        }
    );

function selectedFeaturesSchulenEinzug(event) {
        HighlightLayer.addFeatures([event.feature]);

        // a try with addFeatures but without event.object works well
        //HighlightLayer.addFeatures([OrigVectorLayer.features[0]]);

        HighlightLayer.setVisibility(true);

        //switch on the polygon layer
        PolygLayer.setVisibility(true);
}

  function unselectFeatureEinzug() {

        // switch off the polygon layer
       PolygLayer.setVisibility(false);

       // remove the features and switch off the highlight layer
      HighlightLayer.removeAllFeatures();
      HighlightLayer.setVisibility(false);
  }

It looks like the event.feature object makes the trouble when I click out the layer. Maybe it tries to put a new event.feature into the HighlightLayer and simultaneously removeAllFeatures. However, when I clear the unselect function and it contains nothing, I have the same problem: it tries to do something and after a while the message prompts that the script doesn't answer. When I try to make the same with a not dynamic feature (like in the script above in the comment), I don't have any troubles and the unselect method can be executed.

Does anybody has experience with a trouble like that?

1 Answer 1

0

I've found the source of the trouble and it is quite specific to my map application, but maybe others face the problem sometimes, too.

So: addFeature function with an event handler takes the event.feature "out" of the original layer. As I switched off my original layer with setVisibility(false), the layer missed a feature by switching on again resp. there were contradictory declinations for the styling of the feature.

So I build the HighlightLayer new by taking the geometry and attributions of the event.feature. Now everything is fine...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.