Whats the best pratice to show multiple placemarks with photos inside of the ballons?

。_饼干妹妹 提交于 2020-01-14 14:22:08

问题


I have a project as follows: Several photos are taken from a mobile, the photos are saved in a web system, which in turn displays the photos on google earth that is inside it. I've read many articles but all of them were using fetchKml, one good article that i've read was using php, but using fetchKml. I dont know if its possible using parseKml instead. Anyway, I'm not sure how to do this with the kml, so it looks tike this:

My Class KMLGenerator()

public static String getKMLFromObra (List<Obra> obraFotos) {
    StringBuffer sb = new StringBuffer();
    sb.append("<?xml version='1.0' encoding='UTF-8'?>");
    sb.append("<kml xmlns='http://www.opengis.net/kml/2.2' " + 
            "xmlns:gx='http://www.google.com/kml/ext/2.2' " + 
            "xmlns:kml='http://www.opengis.net/kml/2.2' " + 
            "xmlns:atom='http://www.w3.org/2005/Atom'> ");

    if (obraFotos != null && obraFotos.size() > 0) {
        for (Obra o : obraFotos) {
            for (Local local : o.getLocais()) {
                sb.append("<Document>");  
                sb.append("<name>" + local.getName() + "</name>");  

                sb.append("<Style id='defaultStyles'>");  
                sb.append("<IconStyle>");  
                sb.append("<scale>1.1</scale>");
                sb.append("<Icon>");  
                sb.append("<href>" + "http://localhost:8080/ConstruMobilFoto/lib/img/fotoIcon.png" + "</href>");  
                sb.append("</Icon>");  
                sb.append("</IconStyle>");  
                sb.append("</Style>");  

                sb.append("<Placemark>");  
                sb.append("<name>" + "Foto" + "</name>");  
                sb.append("<styleUrl>" + "#defaultStyles"+ "</styleUrl>");  
                sb.append("<altitudeMode>" + "relativeToGround" + "</altitudeMode>");  
                sb.append("<Point>");
                sb.append("<altitudeMode>relativeToGround</altitudeMode>");
                sb.append("<coordinates>" + local.getLongitude() + "," + local.getLatitude() + "," + 50</coordinates>");
                sb.append("</Point>");
                sb.append("<Link>");
                sb.append("<href>" + local.getFotos() + "</href>");
                sb.append("</Link>");

                sb.append("</Placemark>");  
                sb.append("</Document>");  
                sb.append("</kml>");  
                return sb.toString();
            }
        }
    }
    return null;
}

I have a dwr function in my jsp that invokes this method, got its String results and make the parse like this:

Class PainelEarth()

@SuppressWarnings("static-access")
public String geraFotosObra (int idObra) throws Exception {
    try {
        List<Obra> obraFotos = obraBusiness.getObraLatLong(new Obra(idObra));
        return new KMLGenerator().getKMLFromObra(obraFotos);
    } catch (Exception e) {
        log.error(e.getLocalizedMessage(), e);
        return null;
    }
}

and in my jsp page

function initCB(instance) {
    // other codes

    showPics(ge);
}

function showPics(ge) {
    PainelEarthAjax.geraFotosObra({
        callback : function(kmlString) {
            var kmlObject = ge.parseKml(kmlString);
            ge.getFeatures().appendChild(kmlObject);
        }
    });
    return null;
}

Any help will be welcome!!


回答1:


In your code if you look at the signature of the method geraFotosObra you can see it takes a single int parameter idObra.

public String geraFotosObra (int idObra) throws Exception { ...

Yet when you call the method in your jsp you are passing an an object literal containing a callback function.

PainelEarthAjax.geraFotosObra({
        callback : function(kmlString) { ...

As it is I don't see how the kml is generated, unless perhaps geraFotosObra is an overloaded method? Also even if it was generated, as is, I don't see how the callback function that you pass in place of an id is ever called - why for example would kmlString be the result of the call to geraFotosObra?

// How is this called, what sets kmlString!?
callback : function(kmlString) {
            var kmlObject = ge.parseKml(kmlString);
            ge.getFeatures().appendChild(kmlObject);
        }

All in all the code you posted is a wee bit confusing, so sorry if I have missed something...I think you have possibly copy and pasted some code from a fetchKml example and the asynchronous callbacks used with that method have confused you slightly.

Anyhow, based on what you have posted, you should be passing an int id to the geraFotosObra method, getting the string result and then parsing it in the plug-in.

Something like the following makes sense. Replace the showPics function with the following.

function showPics(ge) {
  var kmlString = PainelEarthAjax.geraFotosObra(1); // or something?
  var kmlObject = ge.parseKml(kmlString);
  ge.getFeatures().appendChild(kmlObject);
}


来源:https://stackoverflow.com/questions/9329945/whats-the-best-pratice-to-show-multiple-placemarks-with-photos-inside-of-the-bal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!