aWhere Manual
DevelopWidgets

Map

Embed a web map in your page and send it options and geometries to draw on top.

The Map widget shows the web map of an Item and draws the geometries that your page sends on top of it. The rest of the contract (credential, ready, error) is in Widgets.

URL and parameters

The URL is <site>/widgets/map.

ParameterMeaningRequired
item_idThe id of the web map Item.Yes

Long values are not in the URL. Your page sends them as the payload of post-widget-parameters, described next.

Messages

actionDirectionPayload
readywidget to your pageNone. Sent as soon as the widget loads, before the web map has loaded.
post-widget-parametersyour page to the widget{ options, features }. Both fields are optional.
errorwidget to your page{ statusCode } when the web map cannot be read, or { statusCode: undefined, message } when the map cannot be created, for example when the browser has no WebGL.

options turns parts of the screen on or off. A value you leave out takes the web map's own value, then the default.

Field of options.componentsDefaultPart it controls
zoomtrueThe zoom buttons and the button back to the full extent.
measurementtrueThe measuring tool.
scaletrueThe scale bar.
coordinatestrueThe coordinates under the pointer.
featureInfoWindowtrueThe Record card when a Feature is clicked.
details{ expanded: false }The card with the name and the layers (expanded opens it from the start).

features is an array of GeoJSON geometries (Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon) or of Features that hold one of them. The widget draws them over the web map with labels for coordinates, length and area, then fits the map to them.

Each post-widget-parameters message replaces both options and features of the one before. A field you leave out goes back to its default.

Example

Continuing the example in Widgets, send the geometries after ready.

if (e.data.action === 'ready') {
  frame.contentWindow.postMessage(
    {
      messageToken,
      action: 'post-widget-parameters',
      payload: {
        options: { components: { measurement: false } },
        features: [{ type: 'Point', coordinates: [100.5018, 13.7563] }],
      },
    },
    site
  )
}

Notes

  • An error with a statusCode comes from reading the Item: 401 means the credential does not work, 403 means no permission, 404 means no such id.
  • An error with a message and no statusCode means the map could not be created. Check that the browser has WebGL on.
  • A position in features is [longitude, latitude], as GeoJSON says.
  • To let the user draw or edit a geometry, use a Form that has a geometry editor field.

On this page