Google Maps API Projects
Home · Demo Maps · Projects · Discussion Forums · Downloads · Developer Available · Google Search · Site SearchSeptember 07 2010 09:07
Navigation
Home
Demo Maps
Projects
Discussion Forums
Downloads
Useful Links
Developer Available
Contact Me
Privacy Policy
Search
Google Search
Site Search
Paypal Donate

Donations encourage developers such as myself to provide support for and develop new versions of our code.

View Thread
Google Maps API Projects | ClusterMarker | General discussion
Author replace a marker by a new one
jftremblay1982
Member

Posts: 2
Joined: 06.07.10
Posted on 06-07-2010 17:48
Hi Martin, I recently discovered your gmap api. I am using these clusters to load about 35000 markers in a progressive way. My data is inside KML files. Each time I move the map, a trigger is started to check what data is inbound(map bounds). And I load only what the user see. When the file has finished loading, its name is saved so the same file cannot be loaded twice.

That is how my map works. Now, my question is the following...

Is it possible to remove a marker from the map when using your ClusterMarker api? I mean, is there any kind of referencing possibilities so we can replace a specific marker on the map by calling him with a number, or it is just that you have to remove everything to add to marker and make a refresh after???

__________________________________
Jeff Tremblay
Analyst Programmer
Author RE: replace a marker by a new one
martin
Super Administrator

Posts: 224
Location: Norfolk, UK.
Joined: 24.07.08
Posted on 07-07-2010 10:44
Hi Jeff.

That all sounds more than possible but i can't suggest what code to modify without seeing your map.

Within ClusterMarker, the markers are held in an array named mapMarkers.
You could remove one or more markers from that array and then call the refresh() method to update the map.

But you would have to remove the marker from the array rather than simply deleting it and leaving an empty or null element in the array - that empty or null element in the array would cause an error when ClusterMarker tries to loop thru the array of markers and instead of finding a marker it finds an empty or null element.

Also ClusterMarker caches some values for each marker in another (2 dimensional) array named _iconBounds.
You also have to remove the cached icon bounds for the marker you remove else there's no guarantee the cached icon bounds would match the icon they apply to.

That sounds rather complicated but in practice it'd hopefully be straightforward!

Can you post a link to your map?

If you'd rather not post a link on the forum then PM me the link and i'll take a look at your code and see what can be done.

Martin.
http://martinpearman.co.uk
Author RE: replace a marker by a new one
jftremblay1982
Member

Posts: 2
Joined: 06.07.10
Posted on 07-07-2010 14:32
You will not be able to see the map work perfecly because of the server configuration.

You can at least see the javascript to help me resolve this...

http://devshed.destination.ca/jeanfrancoist/client_app.php
Author RE: replace a marker by a new one
martin
Super Administrator

Posts: 224
Location: Norfolk, UK.
Joined: 24.07.08
Posted on 08-07-2010 15:34
Hi again Jeff.

Is this what you need?


ClusterMarker.prototype.addMarkers=function($markers){
var i, $index=this._mapMarkers.length-1;
if(!$markers[0]){
// assume $markers is an associative array and convert to a numerically indexed array
var $numArray=[];
for(i in $markers){
$numArray.push($markers[i]);
}
$markers=$numArray;
}
for(i=$markers.length-1; i>=0; i--){
$markers[i]._isVisible=false;
$markers[i]._isActive=false;
$markers[i]._makeVisible=false;
$markers[i]._index=$index++;
}
this._mapMarkers=this._mapMarkers.concat($markers);
};





That modified addMarkers() method will give each marker a unique _index property.

Now a modified removeMarkers() method:


ClusterMarker.prototype.removeMarkers=function($markersToRemove){
var i, $mapMarkers=this._mapMarkers, $map=this._map;
if(!$markersToRemove){
// no markers have been passed to the method so remove all markers, this is the default action
for(i=$mapMarkers.length-1; i>=0; i--){
if($mapMarkers[i]._isVisible){
$map.removeOverlay($mapMarkers[i]);
}
delete $mapMarkers[i]._isVisible;
delete $mapMarkers[i]._isActive;
delete $mapMarkers[i]._makeVisible;
}
this._mapMarkers=[];
} else {
// an array of markers has been passed to the method so remove just those markers
for(i=$markersToRemove.length-1; i>=0; i--){
delete $mapMarkers[$markersToRemove[i]._index];
}
var $newArray=[], $length=$mapMarkers.length;
for(i=0; i<$length; i++){
if($mapMarkers[i]){
$mapMarkers[i]._index=i;
$newArray.push($mapMarkers[i]);
}
}
this._mapMarkers=$newArray;
}
this._iconBounds=[];
this._removeClusterMarkers();
};





This modified removeMarkers() method can be called with no argument and all markers will be removed, or (hopefully - the code is untested!) it can be called with an array of markers and only those markers in the array will be removed.

Note you'll have to call the ClusterMarker refresh() method after removing any markers to update the map.

Give it a try and let me know how you get on.

Martin.
http://martinpearman.co.uk
Jump to Forum:
Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Users Online
Guests Online: 2
No Members Online

Registered Members: 237
Newest Member: Xavi
Google Maps API Projects © Martin Pearman 2010