I have two groups of data points, each clustered with its own MarkerClusterer instance. I thought that, if clusters/markers from the two sets happened to overlap, the one on top would belong to the clusterer I instantiated last; and it seems to work that way, mostly. But occasionally, the wrong pin comes out on top. Is that because the clusterers render asynchronously? Is there a way I can control this?
The answer is that marker pins are placed in a different MapPane than the cluster pins, and the MapPanes are controlled by z-index order of their own. About the MapPanes.
Of further interest: to make the markers' z-index work,
You have to both specify a zIndex and add
optimized: false
to every marker constructor
And to make marker pins and cluster pins respect the same z-index:
Because clustered markers sit in the overlayMouseTarget pane, you
would need to create your own markers in the same pane.
Related
I need to show a set of markers on a Google map.
I know markers can be added directly on a Google map but given that I have 3 sets of markers, one for shops, one for parks and another one for hotels, how can I show them on 3 different layers and so that later on using javascript, I be able to hide one set of markers by doing sort of:
myLayer2.setMap(null);
I have checked Panoramio layer but it needs the images first to be uploaded to panoramio, but in my case for some particular security reason I cannot upload them to panoramio. I will have images locally and set those at runtime based upon some criteria.
Is there some way to do layer based work without using panoramio approach?
The Maps-API doesn't support this kind of custom layers(as you maybe know them from other map-API's like e.g. leaflet).
But it's not hard to achieve a similar feature.
You may use a google.maps.MVCObject. for every "layer" create a property for this MVCObject and set the value of this property to null or the google.maps.Map-instance(
depending on the desired initial state of the "layer")
var myLayers=new google.maps.MVCObject();
myLayers.setValues({parks:null,shops:null,hotels:map});
//hotels initially are visible
When you want to add a Overlay...e.g. a Marker, to a "layer", bind the map-property of that Overlay to the related property of the MVCObject:
parkMarker=new google.maps.Marker({/*options*/});
parkMarker.bindTo('map',myLayers,'parks');
To toggle the display of all features within that "layer" you only need to set the property of the MVCObject:
//show the parks
myLayers.set('parks',map);
//hide the hotels
myLayers.set('hotels',null);
Demo: http://jsfiddle.net/doktormolle/UA85N/
I've created a map that uses the MarkerClusterer library. It seems to work but there are a couple of issues.
First, it seems that the number of markers represented by the cluster is sometimes a bit off - ie, sometimes a cluster will say it has 24 markers, but when you click on it, 40 markers show in the window.
Second, once you zoom out a few levels, the numbers get crazy - we've only got 4k+ markers and I get clusters with 12k+ numbers on them.
I've got no idea how how to move forward. Would love some help. Thanks!
You have an event listener that calls showMarkers when the map is idle. That function adds all the markers to the clusterer every time the idle event fires (so you end up with multiple copies of each marker). You probably want addListenerOnce instead of addListener.
Another option would be to clear out the markers in the clusterer before adding them all back in again, but since you seem to only need to add a fixed set of markers to the clusterer one time, that would probably not be the best option.
I have a web page with a google map (api v3) that has dozens of markers. I'm using markerclusterer to cluster the markers. And I have a separate panel div listing title info for each of the marker that appear on the map.
I've set up a hover event so that when the user hovers over one of the titles in the panel the corresponding marker on the map starts to bounce. This works fine if the marker hasn't been incorporated into an existing cluster. However, if the marker been incorporated into a cluster then it does not work because there is no marker to animate.
Is it possible to remove the marker from the cluster without removing it completely from the map, then animate the marker, then add the marker back to the cluster? (I took a look at the source code , but I couldn't figure out how to remove the marker from the cluster while still leaving it on the map.) Of course, if there is an easier way to tackle this problem I would love to hear about it.
After another day and another review of the source I figured out how to solve the problem, and it turns out that the answer is easy.
All you need to do is call marker.setMap(google.maps.Map object). Then, if you want to get fancy, you can call setSums on the ClusterIcon object to reduce the number of markers listed in the cluster overlay by one.
I figured out how to solve the problem.
#chuck w solution helped me.
call marker.setMap(map)
Then, if you want to get fancy, you can call
markerCluster.repaint();
to collapse to cluster
I have a problem with markers hidden behind other markers.
The problem occurs when the addresses are too close to each other. e.g. street 20, street 22.
Changing zIndex will not help, because that is just "stacking".
How can I "float" the markers so that they are all visible on the map?
I recommend you look into marker clustering.
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/examples/advanced_example.html
UPDATE:
Google now support marker cluserting via a native library: https://developers.google.com/maps/documentation/javascript/marker-clustering
is this any use to you - it's called 'Spiderfier':
http://blog.mackerron.com/2011/06/22/overlapping-marker-spiderfier/
https://github.com/jawj/OverlappingMarkerSpiderfier
It might help to use smaller markers. When I had this problem, I changed the size of my marker images from 20x34 px down to 20x20 px.
So,you can use mysql spatial extensions and MBRContains(RectangleAroundYourPoint,GeometryColumnOfYourTable)
-if of course your table have a geometry column which is easy(upon creation you choose i.e. point as the column type,and when performing an insertion you have to do it with GeomFromText)-
to check if another place exist within that rectangle and if it is move the newcoming place until the mbrcontains return false or something like that.
Hope it helps
I use marker clusterer and had the same problem. I add a small random number to coordinates. I do not want to change the locations of markers so much therefore in satellite mode problem still exists but in map mode we can zoom much more.
This may not be a good solution but good enough for my application.
I'm painting some GMarkers on a map with Subgurim Map control.
Sometimes the GMarkers overlap each other. That isn't a problem, but I want one specific one, which is kwown when I put it on the map, on top of all the others because that is the one the user clicked latest.
I thought I could just add it to the map as the latest one and it would be on top, but it isn't: the z-order of it looks like to be set at random.
Can I make sure that this GMarker is 'painted on top'?
In Google Maps itself, you can set the z-index of the markers by specifying a {zIndexProcess} parameter when you create them.
The default z-index value is calculated from the latitude. Markers to the south appear on top. The default z-index values can be very large positive and negative values, so your zIndexProcess code needs to use extremely large z-index values to be guaranteed to be on top.
See: This tutorial
I don't know whether using subgurim affects your access to {zIndexProcess}.