In не может разобрать kml для моего GE, что не так с моим кодом?
Я застрял в этом в течение 2 недель и попытался сделать много других способов,
Любая помощь будет приветствоваться,
Рафаэль Иисус
google_earth.jsp
var ge;
google.load("earth", "1");
function init() {
google.earth.createInstance('map3d', initCB, failureCB);
window.scroll(0, 10000);
}
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
// add a navigation control
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
// add some layers
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
// directs the exact location of the placemark
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
lookAt.setLatitude(-15.26108113514467);
lookAt.setLongitude(-57.77290131815782);
lookAt.setRange(8007066.726300671);
ge.getView().setAbstractView(lookAt);
ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, false);
var kmlString = showPics();
// I put a alert in here and show in a window the value "undefined"
var kmlObject = ge.parseKml( kmlString );
ge.getFeatures().appendChild(kmlObject);
}
// dwr function that brings the kml with his values
// for now it is in hard coded, just for tests!!
function showPics() {
PainelEarthAjax.geraFotosObra({
callback : function(kmlString) {
// I put a alert function in here, and it has openned a window
// with the entire kmlString brought from the java method geraFotosObra().
return kmlString;
}
});
}
function failureCB(errorCode) {
}
google.setOnLoadCallback(init);
geraFotosObra.java
public String geraFotosObra () throws Exception {
try {
return new KMLGenerator().getKMLFromObra();
} catch (Exception e) {
log.error(e.getLocalizedMessage(), e);
return null;
}
}
KMLGenerator.java
public static String getKMLFromObra () {
StringBuffer sb = new StringBuffer();
sb.append("<?xml version='1.0' encoding='UTF-8'?>");
sb.append("<kml xmlns='http://www.opengis.net/kml/2.2' ");
sb.append("<Document>");
sb.append("<name>ConstruMobil</name>");
sb.append("<Style id='defaultStyles'>");
sb.append("<IconStyle>");
sb.append("<Icon>");
sb.append("<href>" + "http://maps.google.com/mapfiles/kml/pal4/icon38.png" + "</href>");
sb.append("</Icon>");
sb.append("</IconStyle>");
sb.append("</Style>");
sb.append("</Style>");
sb.append("<Placemark>");
sb.append("<name>" + "Some name" + "</name>");
sb.append("<styleUrl>" + "#defaultStyles"+ "</styleUrl>");
sb.append("<altitudeMode>" + "relativeToGround" + "</altitudeMode>");
sb.append("<Location>");
sb.append("<longitude>" + -122.3599987260313 + "</longitude>");
sb.append("<latitude>" + 47.62949781133496 + "</latitude>");
sb.append("<altitude>"+ 15.49615401024533 + "</altitude>");
sb.append("</Location>");
sb.append("<Link>");
sb.append("<href>" + "http://localhost:8080/myCompany/lib/img/dubai.jpg" + "</href>");
sb.append("</Link>");
sb.append("</Model>");
sb.append("</Placemark>");
sb.append("</Document>");
sb.append("</kml>");
return sb.toString();
}