MarkerCollection

A MarkerCollection provides methods to manage Marker instances on an associated Floor. The API is accessed via the Floor.markers() method on a Floor instance.

map.on("ready", function() {
  // Create a MarkerCollection instance via `floor.markers()`, which can only be
  // called once the map has loaded. In this example, we add a marker to the
  // map's first floor.

  var markers = map.floors().first().markers();
  var myMarker = markers.add({
    id: "my-marker",
    translate: [200, 200],
    cursor: "pointer",
    draggable: false,
    size: [64, 64],
    icon: {
      url: "https://cdn.sightmap.com/app/icons/markers/pin-star.svg",
      size: [512, 512],
      // Set the anchor point to bottom center of the icon.
      anchor: [256, 512],
    },
    hitarea: null,
  });
});

MarkerCollection.add(marker)

Adds a Marker instance to a Floor. The marker object is defined below.

Marker Object

KeyRequiredTypeDefault ValueDescription
iconYesObjectundefined

The marker's icon.

See Marker.icon() for further details and usage examples.

idNoStringundefinedAn identifier for the marker instance.
Example: 1 or my-marker.
translateNoArray[0, 0]The marker's initial position in map space. Example: [20, 20].
sizeNoArrayundefined

The marker's initial size in map space: Example: [200, 150].

When no value is provided, the size will be set based on the icon size.

draggableNoBooleanfalseDetermines whether or not the marker can be dragged by the user.
Example: false.
hitareaNoObjectundefined

Defines the interactive region of the marker.

When no value is provided, the icon size will determine this region.

See Marker.hitarea() for further details and usage examples.

Returns

The created Marker instance.

MarkerCollection.removeAll()

Removes all Marker instances from the Floor.

📘

Removing a single marker

To remove a single marker, call the remove() method on a given Marker instance.

Returns

The object chain.


What’s Next