0

I have added geoxml3.js to my GWT project and added <script type="text/javascript" src="geoxml3.js"></script> to my host html file.

In my java source file I have:

// KML utils
    public final native JavaScriptObject createKmlParser(JavaScriptObject mapId) /*-{
        var myParser = new $wnd.geoXML3.parser({
            map : mapId
        });
        return myParser;
    }-*/;

    public final native void showKml(JavaScriptObject parser, String kml) /*-{
        parser.parseKmlString(kml);
    }-*/;

    public final native void hideKml(JavaScriptObject parser) /*-{
        parser.hideDocument();
    }-*/;

    public void setupKmlLayer(final MapWidget mapWidget) {
        final JavaScriptObject jsoParser = createKmlParser(mapWidget.getJso());
        try {
            showKml(jsoParser, "cta.kml");
        } catch (final JavaScriptException jse) {

        }
    }

and it is being called as:

setupKmlLayer(mapWidget);

KML file is in the same package where this java file is present.

I got the KML file from google's official page : http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml

Any tips please

EMM
  • 1,812
  • 8
  • 36
  • 58
  • I cannot really help you on kml, but it would be helpful if you could describe what actually happens. Is the native call in the page, can you debug the native function, ... more information will be helpful. – thst Apr 14 '15 at 09:31
  • Don't know how to debug native code but I am getting exception at showKml(jsoParser, "cta.kml"); above. I tried putting an alert inside the catch block. – EMM Apr 14 '15 at 10:23
  • Do you use SuperDevMode and the chrome JS debugger? There should be the class in the source maps and you should find the real native code if you don't obfuscate during development – thst Apr 14 '15 at 10:26
  • ahh..yes, I am able to debug the code..Everything looks normal. I think it is not getting my kml file. Is there a way to figure out that my program is able to pick locally put kml file? – EMM Apr 14 '15 at 10:33
  • the access should be visible in the network panel of the debugger – thst Apr 14 '15 at 11:19
  • I don't see this kml file in networks tab. – EMM Apr 15 '15 at 13:18
  • arg. I think I know, see my answer. – thst Apr 15 '15 at 13:57

1 Answers1

0

your method showKml() uses the parseKmlString() method. This will parse the given argument as KML. But you are giving it the filename to the KML file.

Thus: Nothing but parse errors can happen.

Check this doc page on how to feed it a URL:

https://code.google.com/p/geoxml/wiki/GeoXmlMethods

I think (without knowing this) you should be happy with showKml implementation like this:

public final native void showKml(JavaScriptObject parser, String kmlUrl) /*-{
    parser.urls = [kmlUrl];
    parser.parse();
}-*/;    
thst
  • 4,592
  • 1
  • 26
  • 40
  • I am using geoxml3.js, but as per your answer I changed my method parseKmlString() to parse method which is sth like var parse = function (urls) { // Process one or more KML documents if (typeof urls === 'string') { // Single KML document urls = [urls]; }.... Now I am getting "Unable to retrieve " which is a log entry in geoxml3.js .I am quite sure that it is just the matter of putting the kml at right place in the project and hopefully it would work. – EMM Apr 15 '15 at 14:31
  • I have tried putting it at several places including the package where my java source file is. Now I have moved it to src/main/resources folder and accessing it using "/resources/cta.kml" Failed to load resource: the server responded with a status of 404 (Not Found) HTTP error 404 retrieving /resources/cta.kml Unable to retrieve /resources/cta.kml(geoxml.js's log) – EMM Apr 15 '15 at 16:28
  • what url responds with the file if you call it manually (browser address field) – thst Apr 15 '15 at 17:48
  • Can you please take a look here: https://code.google.com/p/geoxml3/wiki/Usage#Use_Case_4:_Parse_KML_text_to_map If I get this to work I won't even have to keep the KML file on my machine..just the KML text....URL doesn't change, though. – EMM Apr 15 '15 at 17:52
  • I manged to put a placemark on the map by using the kml file content directly : showKml(jsoParser, "My officeThis is the location of my office.21.0000,78.0000"); – EMM Apr 15 '15 at 18:26
  • Yes, it is as I said: you are calling the parse string method. If you have a static kml file, that may be sufficient for you. Otherwise: Did you check, where in your webapp the cta.kml file actually is? If it is deployed, it must have a proper url. And that url should work on the kml parser, – thst Apr 15 '15 at 21:48