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?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
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.