1

I've created a map using google maps v3 api for GWT. I'm trying to present a kml over this map, but this is not possible because it is stored locally. So, I'm trying to use geoxml3 in order to parse my local kml.

I need the javascript code to be able to "see" the map I created using GWT. How can I do this?

I create the map using

map = GoogleMap.create(Document.get().getElementById("map_canvas"), myOptions); (map_canvas is a div in my html page)

I want to call a Javascript function in order to parse the KML file and present it on my map. I know how to call a JS function but I don't know what to write in its body.,,

2 Answers 2

2

This is the way I plotted local kml files in gwt/gxt google maps api v3 Find and download geoxml3.js and ProjectedOverlay.js on the internet. in your html put:<

script type="text/javascript" src='YourServicePath/geoxml3.js'>

Add some procedures to call the kml operations to your client entry java file:

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();
}-*/;

Because ProjectedOverlay.js needs Google maps connected we'll inject it after we connect to Google maps.

mapWidget = new MapWidget(opts);

ScriptInjector.fromUrl(
    GWT.getHostPageBaseURL() + "YourServicePath/ProjectedOverlay.js").setCallback(new Callback() {

@Override
public void onFailure(Object reason) {
    System.out.println("Script load failed");
}

@Override
public void onSuccess(Object result) {

}
}).setWindow(ScriptInjector.TOP_WINDOW).inject();

To show the KML:
public JavaScriptObject parserGeoXml3;

if (mapWidget != null) {
    JavaScriptObject jsoParser = createKmlParser(mapWidget.getJso());
         parserGeoXml3 = jsoParser;
    try {
        showKml(jsoParser, kmlStr);
        } catch (JavaScriptException jse) {

        }
}
To hide:
try {
    hideKml(parserGeoXml3);
} catch (JavaScriptException jse) {

}
Sign up to request clarification or add additional context in comments.

1 Comment

Looks like a very nice example but not sure why it is not working for me..project builds fine but KML won't show up..
0

Here is coding basics of JSNI from GWT documentation. This definitely help you how to write body of the function.

4 Comments

well I've seen this (developers.google.com/web-toolkit/doc/latest/…) but I still can't get it. I'll try passing my KML to Javascript as a String and then parse it with geoxml
Yes, this is the one I'm using. I managed to present my kml, calling a js function from my gwt project. however, i can't see the map, only the shape of my kml.
I managed to use JSNI as mentioned here (developers.google.com/web-toolkit/doc/latest/…). Thnx a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.