0

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

3

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 = ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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