How to disable marker clustering below a certain number of points in the viewport? - google-maps

Is there an elegant way to disable clustering of points by marker clusterer if there are lesser than, say 30 points in the viewport?
When there are fewer points I would like to plot all of them.

According to the documentation, minimumClusterSize does that:
minimumClusterSize number The minimum number of markers needed in a cluster before the markers are hidden and a cluster marker appears. The default value is 2.

Related

Markers and Clusters are flashed/redraw when zoom is changing [googlemaps/js-markerclusterer]

I reviewed this example http://jsfiddle.net/geocodezip/f5baj1uq/:
it uses https://cdnjs.cloudflare.com/ajax/libs/markerclustererplus/2.1.4/markerclusterer.js
I love it because I zoom markers and clusters and them are not redrawn.
MarkerCluster-Ok.webm
But checking the last version https://googlemaps.github.io/js-markerclusterer/public/defaults/ I see that all markers and clusters are drawn for example in each zoom changing giving a bad user experience because unnecessary markers and clusters are drawing again.
MarkerCluster-Ko.webm
Is there an option in the last version to avoid flash/redraw effect in markers and clusters?
Thanks for your response.

algorith or formula to get a set of lat lon values based on viewport and zoomlevel

I need to display around 50,000 markers on the map. But i was able to plot only 10000 points. I thought of implementing this way correct me if i'm wrong...
Instead of fetching whole data at once just fetch points that are in the viewport and depending on the zoomlevel.
ex:google maps: at one zoomlevel only states are shows if we zoom in further cities are shown
I'm stuck with the zoomlevel.. how to relate zoomlevel and viewport.Is there any algorithm or formulae that helps in getting the lat long values or it needs to be hardcoded in the database like for particular lat-lon this is the zoomlevel range so while fetching range is checked.
i'm using openlayers bbox feature to get the bounds
Thanx in advance
google.maps.Map.getBounds() will return the lat/long bounds of the viewport.
50,000 markers is a lot compared to what Google Maps can handle; you would have to be way zoomed in to have few enough markers to be under the limits. You might do better by creating custom tiles with dots instead of markers. You can see an example at
http://maps.webfoot.com/demos/election2008/
Scroll down to the third overlay to see dots; select zip codes to see LOTS of dots.

Can I temporarily disable rendering of markers in Google Maps V3?

I have a map where at some point I draw around 14000 markers. If the bounds of the map is set to the entire area where the markers are drawn, it takes a long time to draw the markers (about 8 seconds). But if I zoom into an area where few/no markers will be drawn, then drawing the 14000 markers goes really fast, like 2-3 seconds.
I assume this is because the most time consuming process is to actually draw the marker icons to the tiles, and since the markers are added one at a time, the map is rendered a ton of times in a very short time span.
Therefore I wonder if it's possible to disable the map updating/rendering while I add my icons, then re-enable it when all the icons are added.
Any solutions with the similar effect is welcome
The rendering time goes down because api v3 doesn't add the 14 000 when you're zoomed in more tightly. It only adds the markers that are in the current bounds PLUS markers that are in the tile layer buffer around the edges (probably one or two tiles).
I'm kind of confused as to what you mean, but perhaps you want to add the markers only after the map has already been loaded:
google.maps.event.addListenerOnce(map,'tilesloaded',addMarkersFunction);
All that being said, 14 000 markers is A LOT of markers. Clustering markers when you have this many is not even what I would consider optional any more.
Yes, you could create a lot of markers, not associate them with the map. Then afterwards, call the setMap() function on each of them.
You could also only do this that fall within the current bounds.
And have you considered marker clustering to reduce the number of markers?
Would be useful to see your code.
Try using the MarkerManager library in the Google Maps API v3 Utility Library. It was designed for such problems. While there isn't much in the way of documentation, there are several useful examples and plenty of comments in the source code.

Atlas style map index for static google map

I'm using a static google map, but really this problem could apply to any maps project. I want to divide a map into multiple quadrants (of say 50x50 pixels) and label the columns as A, B, C.... and the rows as 1, 2, 3...
Next I plan to do something like,
1) Find the markers which are the farthest north, east, south, and west
2) Use that info to to define the bounding boxes of each row and column box
3) Classify each marker by its row and column (Example Marker 1 = [A,2])
A few requirements,
I don't know the zoom level because I let Google set the zoom level appropriately for me and I would rather not use an algorithm that is dependent on a zoom level. I do however know the locations of all of the markers that are shown on the map.
Here is an example of a map that I would like to classify the markers for,
static map example link.
I found these which look like a good start,
Resource 1, Resource 2
But I think I'm still in need of some help getting started. Can anyone help write out some pseudo code or post a few more resources? I'm kind of in a rut at the moment.
Thanks! Much appreciated of any help!
Ok two days into this I finally got it. Thought I would share my thoughts with people who stumble upon this later.
Following the PHP code on this site and for translating lat,lng pairs to pixel coordinates, I was able to classify the individual pixel row by the x value and the column by the pixels y value.
To calculate the zoom level, I determine the maxLat, maxLng, minLat, and minLng values defined by the collection of markers. Then I calculated the bounds of the map at a given zoom level. Finally I used a brute force method of checking if the new bounds of the map determined by the zoom level would include the bounds defined by the max,min lat,lng values of the collection of markers. Starting at zoom level 21 (max zoom on google maps) I decrement the zoom level until I find a zoom level that includes all the markers.
It seems, that the zoom level that is calculated in this method matches Google's preset zoom level selected automatically if you do not provide a zoom level for a static map.
In PHP there is a nice library to do all of this here.

How to check if there are any markers within a Google Maps viewport?

What is the most effcient approach to check if there are any markers within a viewport?
A perfect solution wouldn't require checking all the markers one-by-one if it's contained by the viewport.
The best solution that I came up with is to
on the application launch, create an array with reference to markers - sorted by 1 coordinate, i.e. latitude
get viewport's bounds with GMap2.getBounds() (as paullb suggested)
take lower latitude of viewport boundaries and look for it in the array (fastest to achieve with binary search)
check if every following marker fits within the viewport (up to marker's latitude <= viewport's upper latitude).
Use GMap2.getBounds() to find the bounding box. The use GLatLngBounds.containsLatLng() to check each marker to see if it is visible.
Alternatively you could try and use the same approach with the Marker Cluster if the value of each cluster is stored in an easily accessible way. (haven't looked myself)