What's the smartest way to manage balloons with the Google Earth plugin?
My company develops a web application (in Java using GWT) that employs the Google Earth plugin to display specific sites and other data on the globe. We're currently managing balloons on a per-use basis, meaning each function that needs to display a balloon is managing the destruction(if needed) and creation of the balloon itself. This leads to issues where the GE plugin will sometimes crash if we try to open a balloon while another is still open. Though we've worked this out in almost every case, I'm thinking it would be smart开发者_开发技巧(er) to manage the balloons centrally, instead of in each place that uses them.
Hurdles:
many sites to show, the locations of which must be very precise;
multiple layers are in use, each of which may show balloons;
Has anyone created a "BalloonManager"-type thing that handles this sort of thing? How might you do this?
It sounds like you should be using encapsulation, look at moving the balloon creation into a single separate method.
Also, with regard to "issues where the GE plugin will sometimes crash if we try to open a balloon while another is still open" - make sure you simply call ge.setBalloon(null)
before opening any balloons, or better still, simply reuse any current balloon rather than creating a new one if it is available.
The following code should help to explain - it is using the api methods you would need so it should be of some use.
public void function OpenFeatureBalloon(GEPlugin plugin, IKMLFeature feature)
{
// Get any open balloon
IGEFeatureBalloon balloon = plugin.getBalloon();
if (balloon == null)
{
// not there, so create one
balloon = plugin.createHtmlStringBalloon("");
}
// set the balloon to the features geographic location
balloon.setFeature(feature);
// open the balloon in the plugin
ge.setBalloon(balloon);
}
If you did not want to pass a feature to the method, it would be fairly trivial to ammed the method to accept something like a latitude and longitude as doubles for example.
精彩评论