Source: https://developers.woosmap.com/products/mobile/flutter/advanced-markers/

> For clean Markdown of any page, append `.md` to the page URL.

> Routing index (which page answers which question): https://developers.woosmap.com/llms.txt

> Full page list: https://developers.woosmap.com/llms-full.txt

# Woosmap for Flutter - Advanced Markers and InfoWindow



Version 2.9 of the plugin adds `AdvancedMarker`, a binding for the Maps JS `AdvancedMarkerElement`, and `InfoWindow`.

`AdvancedMarker` is a separate class from [`Marker`](/products/mobile/flutter/markers/) because the two wrap unrelated JavaScript types. It takes `AdvancedMarkerOptions`, emits a smaller set of events, and has no `icon`, `label`, `opacity`, `rotation` or `alignment` of its own — its visual is a DOM node, which you supply either as a styled pin or as HTML. What it adds over the classic marker is that HTML visual, precise anchoring through `anchorLeft` and `anchorTop`, and altitude — it is the only marker that reads `LatLng.altitude`.

## Checking that advanced markers are available

Advanced markers need the `marker` library, which the plugin loads for you. Check the capability before relying on them, because a map that lacks it will not build the element.

```dart
final MapCapabilities capabilities = await _controller!.getMapCapabilities();
if (!capabilities.isAdvancedMarkersAvailable) {
  return;
}
```

## Adding an advanced marker

Create an `AdvancedMarker` with its options and call `add()`. Without a pin or content it draws the SDK's default pin.

```dart
final AdvancedMarker marker = AdvancedMarker.create(
  AdvancedMarkerOptions(
    position: LatLng(lat: 51.52, lng: -0.13),
    title: 'Bloomsbury',
  ),
  _controller!,
  click: (dynamic value) {
    debugPrint('advanced marker clicked');
  },
);
marker.add();
```

An advanced marker emits `click`, `mouseover`, `mouseout`, `dragstart`, `drag` and `dragend`. Every callback is invoked with `null` rather than an event object: the SDK calls its listeners with no arguments, so there is nothing for the bridge to forward.

Read what you need from the marker itself. Declare it `late final` and assign it on the next line — writing `final marker = AdvancedMarker.create(... marker ...)` does not compile, because `marker` would be read inside its own initializer.

```dart
late final AdvancedMarker marker;
marker = AdvancedMarker.create(
  AdvancedMarkerOptions(
    position: LatLng(lat: 51.52, lng: -0.13),
    draggable: true,
  ),
  _controller!,
  dragend: (_) async {
    final LatLng? position = await marker.getPosition();
    debugPrint('dropped at ${position?.lat}, ${position?.lng}');
  },
);
marker.add();
```

`getPosition()` returns `null` when the map has no position to report — for a marker that has been removed, say. Note also that dragging rewrites the position from the pointer, which carries no altitude, so a dragged marker drops back to ground level.

`click` only fires while `clickable` is true, which is the plugin's default.

## Styling the pin with `PinOptions`

`PinOptions` is the advanced marker's equivalent of an icon. Every field is a plain value, so no markup crosses the bridge.

```dart
final AdvancedMarker marker = AdvancedMarker.create(
  AdvancedMarkerOptions(position: LatLng(lat: 51.52, lng: -0.13)),
  _controller!,
  pin: PinOptions(
    background: '#f50057',
    borderColor: '#B31412',
    glyphColor: '#FFFFFF',
    glyphText: '1',
    scale: 1.2,
  ),
);
marker.add();
```

`glyphText` and `glyphSrc` cover a text or image glyph. The upstream `glyph` option, which also accepts an arbitrary DOM element, is not exposed — use `content` below when you need a fully custom visual.

## Using your own HTML as the marker

`content` replaces the pin with markup of your own.

```dart
final AdvancedMarker marker = AdvancedMarker.create(
  AdvancedMarkerOptions(position: LatLng(lat: 51.52, lng: -0.13)),
  _controller!,
  content: '<img src="https://images.woosmap.com/marker-red.png" '
      'width="24" height="34" alt="store">'
      '<b>Store</b>',
);
marker.add();

// Replace it later, and read back what the map kept.
await marker.setContent('<b>Closed today</b>');
final String markup = await marker.getContent();
```

**The markup is sanitised before it is displayed.** The element takes a DOM node rather than a string, so the plugin parses your HTML in the map document and cleans it first, against the same allowlist [`InfoWindowOptions.content`](#adding-an-infowindow) uses. What survives is text formatting, headings, lists, tables, `a` and `img`. Every `on*` handler is stripped, `href` and `src` keep only `http`, `https` schemes, and anything else — `script`, `style`, `svg`, `iframe`, custom elements — is dropped whole.

Two consequences worth planning for:

- The allowlist has no `style` attribute, and the map document carries no stylesheet of yours, so a `class` has nothing to bind to. Size the content through the markup itself, as the `img` above does.
- `getContent()` returns the sanitised markup, not the string you passed in.

`content` and `pin` both set the element's visual and are mutually exclusive. Passing both throws an `ArgumentError` rather than letting one silently overwrite the other.

## Anchoring the marker to its point

`anchorLeft` and `anchorTop` move the marker relative to the position it marks. They are CSS lengths or percentages, because the element renders at `translate(anchorLeft, anchorTop)`.

```dart
final AdvancedMarker marker = AdvancedMarker.create(
  AdvancedMarkerOptions(
    position: LatLng(lat: 51.52, lng: -0.13),
    anchorLeft: '-50%',
    anchorTop: '-50%',
  ),
  _controller!,
);
marker.add();

// Both can be changed afterwards; the element redraws on assignment.
await marker.setAnchorLeft('calc(-50% + 10px)');
await marker.setAnchorTop(null); // back to the SDK default
```

Left unset, the SDK uses `-50%` and `-100%`, which rests the marker's bottom edge on the point like a pin on its tip. Use `-50%` for `anchorTop` to centre it on the point instead.

A value that is not a valid CSS length, percentage or `calc()` is rejected in Dart with an `ArgumentError`. That is deliberate: the element would otherwise drop its whole transform and park the marker in the map's corner with nothing logged.

## Placing a marker above the ground

`LatLng` takes an optional `altitude`, in metres. Only `AdvancedMarker` reads it, and only on a tilted map — the classic `Marker` drops it.

```dart
final AdvancedMarker marker = AdvancedMarker.create(
  AdvancedMarkerOptions(
    position: LatLng(lat: 51.52, lng: -0.13, altitude: 500),
  ),
  _controller!,
);
marker.add();

await _controller!.moveCamera(tilt: 45, heading: 90, zoom: 14);
```

Viewed from directly above, a marker at altitude sits exactly where its ground-level twin does; tilt the camera and the two separate. Dragging a marker rewrites its position from the pointer, which carries no altitude, so a dragged marker drops back to ground level.

## Collision behaviour

`collisionBehavior` is bound, with a setter and a getter.

```dart
await marker.setCollisionBehavior(
    CollisionBehavior.requiredAndHidesOptional);
final CollisionBehavior? behaviour = await marker.getCollisionBehavior();
```

Note that the current SDK stores the value and never acts on it, so markers still draw over one another whatever you set. Reading it back is the only observable effect. Use `zIndex` for stacking that works.

## Adding an InfoWindow

An `InfoWindow` is a floating panel anchored either to a marker — classic or advanced — or to a bare position.

```dart
final InfoWindow infoWindow = InfoWindow.create(
  InfoWindowOptions(
    content: '<b>Bloomsbury</b><p>Open until 18:00</p>',
    maxWidth: 260,
  ),
  _controller!,
);

await infoWindow.add();
await infoWindow.open(anchor: marker);

// Or open it at a position, with no marker to follow.
await infoWindow.open(position: LatLng(lat: 51.52, lng: -0.13));

await infoWindow.setContent('<b>Closed</b>');
await infoWindow.close();
```

`InfoWindowOptions` takes `content`, `disableAutoPan`, `maxWidth` and `pixelOffset`, and the window exposes `open({anchor, position})`, `close()`, `setContent()`, `getContent()`, `setPosition()`, `setOffset()` and `remove()`.

**Content is HTML and is sanitised in the map document before it is displayed.** The SDK assigns it straight to `innerHTML` and sanitises nothing of its own, so the plugin cleans it first, immediately before that point. The allowlist is the one described under [content](#using-your-own-html-as-the-marker) above. Treat it as rich text rather than as a page: plain text is always safe, and anything outside the allowlist simply will not appear.

Two behaviours to know:

- A non-zero `pixelOffset` is **not** applied when the anchor is an `AdvancedMarker`. Anchor to a classic `Marker`, or open at a position, when the offset matters.
- The SDK's `closeclick` and `domready` events are not bound yet.
