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 want to create a balloon for a KML file that dynamically moves.

The example that I am working on is sundials.html.

Let's say that the KML is moving. How we would get the balloon to move as well?

TIA.

share|improve this question

1 Answer 1

I'm not really sure what you mean by "let's say that the KML is moving", but if you want to change the location of a popup after it has been created, here's how you do it:

// Set the new lonlat location.
popup.lonlat = new OpenLayers.LonLat(popup.lonlat.lon - 1, popup.lonlat.lat - 1);
// Tell OpenLayers to update the popup's location on the map.
popup.updateSize()

If you have a vector, such as a sundial, and it's lonlat changes, and you want the popup to move to the new center, you can do this:

// Set the popup's location equal to the vector's center
popup.lonlat = feature.geometry.getBounds().getCenterLonLat();
// Tell OpenLayers to update the popup's location on the map
popup.updateSize();

You can paste the first example into firebug on the sundials example and it should work straight away.

The OpenLayers API doesn't mention that the updateSize function updates the center, so it's possible that this behavior will disappear at some point.

share|improve this answer

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.