theCrimsonEK
06-12-2008, 04:27 PM
I am loading an instance of Google Earth in my browser and am running
into an issue. I am trying to set the pop up balloon so when you click
on the placemark, it pops up with the custom balloon.
right now, the custom balloon loads when the API is initialized before
it zooms into the location. i need to anchor the new balloon to the
placemark. from what i have in my code, the logic behind it seems to
be correct, but its not working.
Any ideas?
Here is my code: I have a changeBalloon() function that creates the
balloon and assigns it to the original object.
<script>
google.load("earth", "1");
google.load("maps", "2.99"); // For JS geocoder
var ge = null;
var geocoder;
var address = "<%= strAddressQuery %>";
var lat
var bubble = "bubble content";
function init() {
if (GBrowserIsCompatible()) {
geocoder = new GClientGeocoder();
google.earth.createInstance("map3d", initCallback,
failureCallback);
}
}
function initCallback(object) {
ge = object;
ge.getWindow().setVisibility(true);
// if the address is populated, the lat and long need found
if (address != "") {
geocoder.getLatLng(
address,
function(point) {
if (point && ge != null) {
var la = ge.createLookAt('');
la.set(point.y, point.x, 100,
ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 400);
ge.getView().setAbstractView(la);
}
}
);
} else {
// look up by lat, long
var la = ge.createLookAt('');
la.set(<%= dGeoLatitude %>, <%= dGeoLongitude %>, 100,
ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 400);
ge.getView().setAbstractView(la);
}
// create instance of pointer
createPlacemark();
}
function failureCallback(object) {
// error loading plugin
}
function changeBalloon() {
// create instance of bubble
var feature = null;
if (window.placemark) {
feature = window.placemark;
}
var b = ge.createHtmlStringBalloon('');
b.setMaxWidth(300);
b.setFeature(feature);
b.setContentString(bubble);
ge.setBalloon(null);
ge.setBalloon(b);
}
function createPlacemark() {
// create the pointer
var placemark = ge.createPlacemark('');
placemark.setName("<%= strName %>");
ge.getFeatures().appendChild(placemark);
// Create style map for placemark
var normal = ge.createIcon('');
normal.setHref('http://maps.google.com/mapfiles/kml/paddle/red-
circle.png');
var iconNormal = ge.createStyle('');
iconNormal.getIconStyle().setIcon(normal);
var highlight = ge.createIcon('');
highlight.setHref('http://maps.google.com/mapfiles/kml/paddle/red-
circle.png');
var iconHighlight = ge.createStyle('');
iconHighlight.getIconStyle().setIcon(highlight);
var styleMap = ge.createStyleMap('');
styleMap.setNormalStyle(iconNormal);
styleMap.setHighlightStyle(iconHighlight);
placemark.setStyleSelector(styleMap);
// Create point
var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_ GROUND);
var point = ge.createPoint('');
point.setLatitude(<%= dGeoLatitude %>);
point.setLongitude(<%= dGeoLongitude %>);
placemark.setGeometry(point);
changeBalloon(); // loads before startup
}
</script>
into an issue. I am trying to set the pop up balloon so when you click
on the placemark, it pops up with the custom balloon.
right now, the custom balloon loads when the API is initialized before
it zooms into the location. i need to anchor the new balloon to the
placemark. from what i have in my code, the logic behind it seems to
be correct, but its not working.
Any ideas?
Here is my code: I have a changeBalloon() function that creates the
balloon and assigns it to the original object.
<script>
google.load("earth", "1");
google.load("maps", "2.99"); // For JS geocoder
var ge = null;
var geocoder;
var address = "<%= strAddressQuery %>";
var lat
var bubble = "bubble content";
function init() {
if (GBrowserIsCompatible()) {
geocoder = new GClientGeocoder();
google.earth.createInstance("map3d", initCallback,
failureCallback);
}
}
function initCallback(object) {
ge = object;
ge.getWindow().setVisibility(true);
// if the address is populated, the lat and long need found
if (address != "") {
geocoder.getLatLng(
address,
function(point) {
if (point && ge != null) {
var la = ge.createLookAt('');
la.set(point.y, point.x, 100,
ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 400);
ge.getView().setAbstractView(la);
}
}
);
} else {
// look up by lat, long
var la = ge.createLookAt('');
la.set(<%= dGeoLatitude %>, <%= dGeoLongitude %>, 100,
ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 400);
ge.getView().setAbstractView(la);
}
// create instance of pointer
createPlacemark();
}
function failureCallback(object) {
// error loading plugin
}
function changeBalloon() {
// create instance of bubble
var feature = null;
if (window.placemark) {
feature = window.placemark;
}
var b = ge.createHtmlStringBalloon('');
b.setMaxWidth(300);
b.setFeature(feature);
b.setContentString(bubble);
ge.setBalloon(null);
ge.setBalloon(b);
}
function createPlacemark() {
// create the pointer
var placemark = ge.createPlacemark('');
placemark.setName("<%= strName %>");
ge.getFeatures().appendChild(placemark);
// Create style map for placemark
var normal = ge.createIcon('');
normal.setHref('http://maps.google.com/mapfiles/kml/paddle/red-
circle.png');
var iconNormal = ge.createStyle('');
iconNormal.getIconStyle().setIcon(normal);
var highlight = ge.createIcon('');
highlight.setHref('http://maps.google.com/mapfiles/kml/paddle/red-
circle.png');
var iconHighlight = ge.createStyle('');
iconHighlight.getIconStyle().setIcon(highlight);
var styleMap = ge.createStyleMap('');
styleMap.setNormalStyle(iconNormal);
styleMap.setHighlightStyle(iconHighlight);
placemark.setStyleSelector(styleMap);
// Create point
var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_ GROUND);
var point = ge.createPoint('');
point.setLatitude(<%= dGeoLatitude %>);
point.setLongitude(<%= dGeoLongitude %>);
placemark.setGeometry(point);
changeBalloon(); // loads before startup
}
</script>