Google GWT and Maps, marker does not close

72 views
Skip to first unread message

pfdevil

unread,
Dec 17, 2009, 8:57:06 AM12/17/09
to Google Web Toolkit

Hello

I have an issue with an marker that does not want to close when
clicked. Basically adding a marker is fine, but when I click on the
marker it is supposed to close but it doesn't. I copied the code from
this tutorial.

http://gwt.google.com/samples/HelloMaps-1.0.1/HelloMaps.html#Click%20...

Here is my code:

public class SimpleMaps implements EntryPoint{
private InfoWindow info = null;
private Marker newMarker = null;
InfoWindowContent infoWindowContent = null;

/**
* This is the entry point method.
*/
public void onModuleLoad() {
LatLng cawkrCity = LatLng.newInstance(39.509, -98.434);
VerticalPanel verticalPanel = new VerticalPanel();

verticalPanel.addStyleName("verticalPanel");

MapWidget map = new MapWidget(cawkrCity, 4);

HTML htmlWidget = new HTML("<b> Write a message </b>");

verticalPanel.add(htmlWidget);

info = map.getInfoWindow();

infoWindowContent = new InfoWindowContent(verticalPanel);

map.setUIToDefault();

map.addStyleName("mapContainer");

map.setSize("500px", "300px");

# THIS IS THE CLICKHANDLER FOR THE MARKER

map.addMapClickHandler(new MapClickHandler() {
public void onClick(MapClickEvent e) {
MapWidget sender = e.getSender();
Overlay overlay = e.getOverlay();
LatLng point = e.getLatLng();

newMarker = new Marker(point);

if (overlay != null && overlay instanceof Marker) {
sender.removeOverlay(overlay);

} else {
sender.addOverlay(newMarker);
info.open(newMarker, infoWindowContent);

}
}
});

RootPanel.get("mapContainer").add(map);

}

I also receive an error when testing this application:

14:37:18.834 [ERROR] [simplemaps] Uncaught exception escaped
com.google.gwt.core.client.JavaScriptException: (TypeError): a is null
fileName: http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/maps2.api/main.js
lineNumber: 1246
stack: (null)@http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/
maps2.api/main.js:1246
ik(null)@http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/maps2.api/
main.js:1237
(null)@http://localhost:8888:85
@:0
([object GWTJavaObject],2555922,[object GWTJavaObject],null)@http://
localhost:8888/simplemaps/hosted.html?simplemaps:56
([object Object],(void 0),[object Object])@http://localhost:8888:160
([object Array])@http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/
maps2.api/main.js:297
([object Object],1)@http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/
maps2.api/main.js:274
t([object Array],(function (d) {if (lh) {d.bt(c);} else {try {d.bt
(c);} catch (f) {}}}))@http://maps.gstatic.com/intl/en_ALL/mapfiles/
193c/maps2.api/main.js:81
A([object Object],"click",[object Object],(void 0),[object Object])
@http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/maps2.api/main.js:
274
([object Object])@http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/
maps2.api/main.js:770
([object Object])@http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/
maps2.api/main.js:6
([object Array])@http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/
maps2.api/main.js:297
([object Object],0)@http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/
maps2.api/main.js:274
t([object Array],(function (d) {if (lh) {d.bt(c);} else {try {d.bt
(c);} catch (f) {}}}))@http://maps.gstatic.com/intl/en_ALL/mapfiles/
193c/maps2.api/main.js:81
A([object Object],"click",[object Object])@http://maps.gstatic.com/
intl/en_ALL/mapfiles/193c/maps2.api/main.js:274
Em([object MouseEvent])@http://maps.gstatic.com/intl/en_ALL/mapfiles/
193c/maps2.api/main.js:1298
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript
(BrowserChannelServer.java:195)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke
(ModuleSpaceOOPHM.java:120)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative
(ModuleSpace.java:507)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject
(ModuleSpace.java:264)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject
(JavaScriptHost.java:91)
at com.google.gwt.maps.client.impl.__MarkerImplImpl.construct
(__MarkerImplImpl.java)
at com.google.gwt.maps.client.overlay.Marker.<init>(Marker.java:
116)
at simplemap.client.SimpleMaps$2.onClick(SimpleMaps.java:66)
at com.google.gwt.maps.client.MapWidget$8.callback(MapWidget.java:
481)
at com.google.gwt.maps.client.impl.EventImpl$OverlayLatLngCallback
$1.execute(EventImpl.java:193)
at
com.google.gwt.maps.client.impl.EventImpl.invokeAndReportUncaughtExceptions
(EventImpl.java:260)
at
com.google.gwt.maps.client.impl.EventImpl.invokeAndMaybeReportUncaughtExceptions
(EventImpl.java:246)
at com.google.gwt.maps.client.impl.EventImpl.access$0
(EventImpl.java:241)
at com.google.gwt.maps.client.impl.EventImpl
$OverlayLatLngCallback.callbackWrapper(EventImpl.java:191)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.google.gwt.dev.shell.MethodAdaptor.invoke
(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke
(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke
(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessages
(BrowserChannel.java:1668)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection
(BrowserChannelServer.java:401)
at com.google.gwt.dev.shell.BrowserChannelServer.run
(BrowserChannelServer.java:222)
at java.lang.Thread.run(Thread.java:636)

This could maybe be related. I'm sorry for posting all this code.
Since it usually unnecessary. But i'm not sure what to do, or where
this error/exception lies.

Thank you

Francois

unread,
Dec 17, 2009, 9:26:10 AM12/17/09
to Google Web Toolkit
I found the problem. But I don't really understand why?

map.addMapClickHandler(new MapClickHandler() {
public void onClick(MapClickEvent e) {
MapWidget sender = e.getSender();
Overlay overlay = e.getOverlay();
LatLng point = e.getLatLng();

===> HERE IS THE PROBLEM <===
newMarker = new Marker(point);

if (overlay != null && overlay instanceof Marker) {
sender.removeOverlay(overlay);

} else {
sender.addOverlay(newMarker);
info.open(newMarker, infoWindowContent);

}
}
});

By removing newMarker = new Marker(point); and inserting it here:

map.addMapClickHandler(new MapClickHandler() {
public void onClick(MapClickEvent e) {
MapWidget sender = e.getSender();
Overlay overlay = e.getOverlay();
LatLng point = e.getLatLng();

if (overlay != null && overlay instanceof Marker) {
sender.removeOverlay(overlay);

} else {
===> HERE IS THE PROBLEM SOLVED <===
newMarker = new Marker(point);
sender.addOverlay(newMarker);
info.open(newMarker, infoWindowContent);

}
}
});

The exception isn't thrown and clicking on the marker works. Why does
javascript throw an exception?

Reply all
Reply to author
Forward
0 new messages