MarkerManager
Marker manager is an interface between the map and the user,
designed to manage adding and removing many points when the viewport changes.
Algorithm: The MM places its markers onto a grid, similar to the map tiles.
When the user moves the viewport, the MM computes which grid cells have
entered or left the viewport, and shows or hides all the markers in those
cells.
(If the users scrolls the viewport beyond the markers that are loaded,
no markers will be visible until the EVENT_moveend triggers an update.)
In practical consequences, this allows 10,000 markers to be distributed over
a large area, and as long as only 100-200 are visible in any given viewport,
the user will see good performance corresponding to the 100 visible markers,
rather than poor performance corresponding to the total 10,000 markers.
Note that some code is optimized for speed over space,
with the goal of accommodating thousands of markers.
class MarkerManager
This class is used to manage visibility of hundreds of markers on a
map, based on the map's current viewport and zoom level.
Constructor
Constructor |
Description |
MarkerManager(map, opt_opts?) |
Creates a new marker manager that controlls visibility of markers for the specified map. |
Methods
Methods |
Return Value |
Description |
addMarker(marker, minZoom, opt_maxZoom?) |
None |
Adds a single marker to a collection of markers controlled by this manager.
If the marker's location falls within the map's current viewport and the
map's zoom level is within the specified zoom level rage, the marker is
immediately added to the map. Similar to the addMarkers method,
the minZoom and the optional maxZoom parameters specify
the range of zoom levels at which the marker is shown. |
addMarkers(markers, minZoom, opt_maxZoom?) |
None |
Adds a batch of markers to this marker manager. The markers are not added to
the map, until the refresh() method is called. Once placed on a
map, the markers are shown if they fall within the map's current viewport
and the map's zoom level is greater than or equal to the specified
minZoom . If the maxZoom was given, the markers are
automatically removed if the map's zoom is greater than the one specified. |
clearMarkers() |
None |
Removes all currently displayed markers and clears grid arrays. |
getMarkerCount(zoom) |
Number |
Calculates the total number of markers potentially visible at a given
zoom level. This may include markers at lower zoom levels. |
refresh() |
None |
Forces the manager to update markers shown on the map. This method must be
called if markers were added using the addMarkers method. |
removeMarker(marker) |
None |
Removes marker from the MarkerManager by searching at every zoom level to
find grid cell that marker would be in, removing from that array if
found. Also calls removeOverlay on marker if currently visible. |
Events
Events |
Arguments |
Description |
changed |
bounds, markerCount |
This event is fired when markers managed by a manager have been added to or
removed from the map. The event handler function should be prepared to
accept two arguments. The first one is the rectangle definining the
bounds of the visible grid. The second one carries the number of markers
currently shown on the map. |
class MarkerManagerOptions
This class represents optional arguments to the MarkerManager
constructor. There is no constructor for this class. Instead, this class is instantiated as a javascript object literal.
Properties
Properties |
Type |
Description |
borderPadding |
Number |
Specifies, in pixels, the extra padding
outside the map's current viewport monitored by a manager. Markers that
fall within this padding are added to the map, even if they are not fully
visible. |
maxZoom |
Number |
Sets the maximum zoom level monitored by a
marker manager. If not given, the manager assumes the maximum map zoom
level. This value is also used when markers are added to the manager
without the optional maxZoom parameter. |
trackMarkers |
Boolean |
Indicates whether or not a marker
manager should track markers' movements. If you wish to move managed
markers using the setPoint method, this option should be set to
true . The default value is false . |