Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have KML layer with multiple tracks and I would like to highlight them individually on mouse hover. I tried to implement this like in the example found in OpenLayers examples, but couldn't get it work.

In the example there is following code that adds polygon as feature. In my case, how do I add KML-tracks as feature so that I can highlight them with SelectFeature?

var feature = new OpenLayers.Feature.Vector(
    OpenLayers.Geometry.fromWKT(
        "POLYGON((28.828125 0.3515625, 132.1875 -13.0078125, -1.40625 -59.4140625, 28.828125 0.3515625))"
    )
);
vectors.addFeatures([feature]);

You can find simplified version of my index.html and KML file here: https://gist.github.com/1379118

share|improve this question
add comment

1 Answer

Your code has no SelectFeature handlers.

Look at the source code of the sample you linked to, there are 2 controls, one that acts on a "highlight" (or a "hover") and the other on a select/click. You need to create handlers like that and add your vector layer to it.

...from the sample file

var highlightCtrl = new OpenLayers.Control.SelectFeature...
...
var selectCtrl = ...
share|improve this answer
    
That sample was supposed to only show the starting point where to add highlighting feature. I updated the sample with SelectFeatures included. It doesn't yet work because I should also addFeatures, but don't know how to exactly do it. –  Petteri Vaarala Nov 20 '11 at 21:16
    
Vector layer has the function to addFeature. dev.openlayers.org/docs/files/OpenLayers/Layer/… –  Vadim Nov 30 '11 at 18:30
    
See this example on how the features are created and added to the map. Ignore the rotating part if it's not applicable. openlayers.org/dev/examples/rotate-features.html –  Vadim Nov 30 '11 at 18:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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