How do I remove a marker from the map?

21 views
Skip to first unread message

Jesse Fulton

unread,
Jun 17, 2010, 7:00:33 PM6/17/10
to gwt-maps3-discuss
According to the JavaScript documentation, to remove a marker, you
would do:

marker.setMap(null);

However, the method com.google.gwt.maps.client.overlay.Marker.setMap()
is:

@Override
public void setMap(HasMap map) {
MarkerImpl.impl.setMap(jso, map.getJso());
}

If I pass null into this method, I get a NullPointerException. Is
there another way I am supposed to be removing markers from the map?

Jesse Fulton

unread,
Jun 17, 2010, 7:11:36 PM6/17/10
to gwt-maps3-discuss
I've tried the following which seems to work

MapWidget nullMap = new MapWidget(new MapOptions());
m.setMap(nullMap.getMap());

but this seems veerrrrry wrong and like it will cause huge performance
issues down the road since I need to create a new map and it still
stores all of the markers. I'm assuming I'll have to write a custom
native method which then calls the Javascript setMap() method?

Vinay

unread,
Jun 17, 2010, 7:13:45 PM6/17/10
to Jesse Fulton, gwt-maps3-discuss
Hi Jesse,

Thats a valid point, i'll fix it over the weekend. Till then you could
either use a dummy implementation of HasMap interface which would
return null for getJso() or fix it in you local code. First option
would definitely be forward compatible with my fixes.

Thanks for finding the bug!

Cheers!
--
Vinay

Vinay

unread,
Jun 17, 2010, 7:17:44 PM6/17/10
to Jesse Fulton, gwt-maps3-discuss
Could you this null map implementation for now :

-----------------

package <your package name>;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.maps.client.HasMap;
import com.google.gwt.maps.client.HasMapOptions;
import com.google.gwt.maps.client.base.HasLatLng;
import com.google.gwt.maps.client.base.HasLatLngBounds;
import com.google.gwt.maps.client.overlay.HasProjection;
import com.google.gwt.user.client.Element;

public class NullMap implements HasMap {

@Override
public void fitBounds(HasLatLngBounds bounds) {
throw new IllegalStateException("Illegal invocation");
}

@Override
public HasLatLngBounds getBounds() {
throw new IllegalStateException("Illegal invocation");
}

@Override
public HasLatLng getCenter() {
throw new IllegalStateException("Illegal invocation");
}

@Override
public Element getDiv() {
throw new IllegalStateException("Illegal invocation");
}

@Override
public String getMapTypeId() {
throw new IllegalStateException("Illegal invocation");
}

@Override
public int getZoom() {
throw new IllegalStateException("Illegal invocation");
}

@Override
public void panBy(int x, int y) {
throw new IllegalStateException("Illegal invocation");
}

@Override
public void panTo(HasLatLng latLng) {
throw new IllegalStateException("Illegal invocation");
}

@Override
public void panToBounds(HasLatLngBounds bounds) {
throw new IllegalStateException("Illegal invocation");
}

@Override
public void setCenter(HasLatLng latLng) {
throw new IllegalStateException("Illegal invocation");
}

@Override
public void setMapTypeId(String mapTypeId) {
throw new IllegalStateException("Illegal invocation");
}

@Override
public void setOptions(HasMapOptions options) {
throw new IllegalStateException("Illegal invocation");
}

@Override
public void setZoom(int zoom) {
throw new IllegalStateException("Illegal invocation");
}

@Override
public JavaScriptObject getJso() {
return null;
}

@Override
public HasProjection getProjection() {
throw new IllegalStateException("Illegal invocation");
}
}


-----------------------

Vinay

unread,
Jun 17, 2010, 7:20:24 PM6/17/10
to Jesse Fulton, gwt-maps3-discuss
Create a single instance of it and reuse every time you want to
setMap(null) / setMap(new NullMap());

Jesse Fulton

unread,
Jun 17, 2010, 7:25:32 PM6/17/10
to gwt-maps3-discuss
Yep, that works for now. Thanks.

On Jun 17, 4:20 pm, Vinay <vinay.sek...@gmail.com> wrote:
> Create a single instance of it and reuse every time you want to
> setMap(null) / setMap(new NullMap());
>
Reply all
Reply to author
Forward
0 new messages