Skip to main content

MarkerCollection

The MarkerCollection object enables you to apply bulk actions to a collection of markers. The markers can be organized by tags so that you can apply the bulk actions to a subset of the markers.

Example usage

const markerCollection = G.markerCollection();
markerCollection.add(marker1, 'tag1');
markerCollection.add(marker2, ['tag2']);
markerCollection.add(marker3, ['tag1', 'tag2']);
markerCollection.add(marker4, 'tag2');
markerCollection.add(marker5, 'tag3');
markerCollection.add(marker6, 'tag4');
markerCollection.add(marker7, ['tag1', 'tag3', 'tag4']);
markerCollection.add(marker8);
markerCollection.add(marker9);

As you can see, you can assign one tag, multiple tags, or no tags.

You can pass a single tag as a string, a single tag as an array, or an array of tags. Tags must be a string value.

If you assign no tag then an internal default tag is applied. This is intended to allow you to use a marker collection with no tags if desired. Typically you would not mix markers with tags and those with no tags in the same collection. There is no way to target only those markers with the internal default tag.

Creating the MarkerCollection object

G.markerCollection(): MarkerCollection

The MarkerCollection object does not take any parameters.

const markerCollection = G.markerCollection();

Methods

add

add(marker: Marker, tag?: string|string[]): void

Add a marker to the collection with zero or more tags.

ParameterTypeRequiredDescription
markerMarkersvg fileThe marker object to add.
tagsstring|string[]One or more string tags. This allows you to pass multiple tags as strings to the method.

No tags:

markerCollection.add(marker);

One tag:

markerCollection.add(marker, 'tag1');
markerCollection.add(marker, ['tag1']);

Multiple tags:

markerCollection.add(marker, ['tag1', 'tag2', 'anotherTag', 'andAnotherTag']);

clear

clear(): void

Remove all markers and tags from the collection.

markerCollection.clear();

clone

clone(): MarkerCollection

const copy = markerCollection.clone();

hasData

hasData(): boolean

Return whether the collection has at least one marker.

if (markerCollection.hasData()) {
// There is at least one marker in the collection
}

hide

hide(tag: string|string[]): void

Hide the markers that are assigned to the passed tag(s).

ParameterTypeRequiredDescription
tagsstring|string[]svg fileOne or more string tags. This allows you to pass multiple tags as strings to the method.

If multiple tags are passed then any marker that is assigned to one of the passed tags is hidden. Multiple tags does not mean that a marker has to be assigned to all of the passed tags.

If no tags are passed then nothing happens.

Hide markers that are assigned to the passed tag:

markerCollection.hide('tag1');
markerCollection.hide(['tag1']);

Hide markers that are assigned to the passed tags:

markerCollection.hide(['tag1', 'tag2', 'anotherTag']);

hideAll

hideAll(): void

Hide all the markers in the collection.

markerCollection.hideAll();

isEmpty

isEmpty(): boolean

Return whether the collection has no markers.

if (markerCollection.isEmpty()) {
// There are no markers in the collection
}

remove

remove(marker: Marker, tag?: string|string[]): void

Remove a marker from the collection. Optionally only remove it from the passed tags.

ParameterTypeRequiredDescription
markerMarkerThe marker object to remove.
tagsstring|string[]One or more string tags. This allows you to pass multiple tags as strings to the method.

Remove the marker from all tags:

markerCollection.remove(marker);

Remove the marker from one tag:

markerCollection.remove(marker, 'tag1');
markerCollection.remove(marker, ['tag1']);

Remove the marker from multiple tag:

markerCollection.remove(marker, ['tag1', 'tag2', 'anotherTag', 'andAnotherTag']);

show

show(tag: string|string[], map: Map): void

Show the markers that are assigned to the passed tag(s).

ParameterTypeRequiredDescription
tagsstring|string[]svg fileOne or more string tags. This allows you to pass multiple tags as strings to the method.
mapMapsvg fileThe map object

If multiple tags are passed then any marker that is assigned to one of the passed tags is shown. Multiple tags does not mean that a marker has to be assigned to all of the passed tags.

If no tags are passed then nothing happens.

Show markers that are assigned to the passed tag:

markerCollection.show('tag1', map);
markerCollection.show(['tag1'], map);

Show markers that are assigned to the passed tags:

markerCollection.show(['tag1', 'tag2', 'anotherTag'], map);

showAll

showAll(map: Map): void

Show all the markers in the collection.

ParameterTypeRequiredDescription
mapMapsvg fileThe map object
markerCollection.showAll(map);