Reputation: 954
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.,,
Upvotes: 1
Views: 413
Reputation: 31
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) {
}
Upvotes: 2
Reputation: 748
Here is coding basics of JSNI from GWT documentation. This definitely help you how to write body of the function.
Upvotes: 0