cybersthang / gmaps-utility-library-dev

Automatically exported from code.google.com/p/gmaps-utility-library-dev
0 stars 0 forks source link

markermanager.getMarker shouldn't return a new marker if one doesn't exist #150

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When using the MarkerManager to check if a marker is already added to the
manager, using getMarker returns a Marker, but there's no logical way to
tell if the marker you get back is the one you added, or a new marker.

It should be left up to the programmer as to what the desired action is if
a marker isn't in the markermanager.

As a hint to anyone else that has this issue: I ended up using
marker.getTitle() to check if it's the one I wanted, but it requires that
the title is set!

Original issue reported on code.google.com by macro...@gmail.com on 1 Sep 2009 at 5:46

GoogleCodeExporter commented 8 years ago
Interesting. Do you have a suggested patch for the library?

Original comment by pamela.fox on 1 Sep 2009 at 5:49

GoogleCodeExporter commented 8 years ago
Indeed I do, see attached file. A simple 1 line change.

I decided that returning null reflects the nature of not finding the marker, 
versus
using false or undefined.

Then to see if a marker exists:

var MM = new MarkerManager(map);
var marker = MM.getMarker(point.lat(), point.lng(), map.getZoom());
if (marker == null) {
    marker = new GMarker(point);
    MM.addMarker(marker, 0);
}

etc.

Original comment by macro...@gmail.com on 3 Sep 2009 at 2:43

Attachments:

GoogleCodeExporter commented 8 years ago
Oh, I missed changing the doc comment on the method, will need to be altered.

Original comment by macro...@gmail.com on 3 Sep 2009 at 3:40

GoogleCodeExporter commented 8 years ago
I've personally patched my MarkerManager to act in a similar manner. For the
applications I'm working on it's important as there's no other way to keep 
track of
what points may or may not already be stored. You could keep a list of what 
points
you're storing externally but that seems to defeat the purpose of MarkerManager 
in
the first place.

At the current point it creates a marker but it doesn't evn add it to the
MarkerManager - hence there's no way to tell if it existed before or was 
created just
to pass to you. That's not the behaviour I originally expected from getMarker, 
as
most similar get*'s either return the object or their equivalent of null.

My personal opinion is this would be a great patch to put in, with the only 
light
issue being legacy users who may expect getMarker to behave in a specific way.

Original comment by smerity on 19 Feb 2010 at 12:50

GoogleCodeExporter commented 8 years ago
What about adding a function that would simply let you know if the marker was 
part 
of the markermanagers collection?  mgr.markerExists(marker) returns boolean.
Either that, or add an optional boolean parameter passed in.  If true then 
return 
null if the marker is not found.  
I'm very new to all of this, 10 years of vb, asp.net programming though.  
Loving it 
so far.

Original comment by ericclar...@gmail.com on 25 Feb 2010 at 9:21