diff --git a/docs/api/mapml-viewer-api.mdx b/docs/api/mapml-viewer-api.mdx index 2faa756ae..7d2d7c926 100644 --- a/docs/api/mapml-viewer-api.mdx +++ b/docs/api/mapml-viewer-api.mdx @@ -222,6 +222,7 @@ let zoom = map.zoom; | [defineCustomProjection(options)](#definecustomprojectionoptions) | Define a custom projection for use by the page. | | [zoomTo(lat, lon, zoom)](#zoomtolat-lon-zoom) | Fly or pan the map to a (new) location and zoom level.| | [geojson2mapml(json, options)](#zoomtolat-lon-zoom) | Add a GeoJSON Layer to the map. | +| [matchMedia(mediaQueryString)](#matchmediamediaquerystring) | Returns a [MediaQueryList](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList)-like object. ### back() @@ -358,6 +359,32 @@ Check out [this application](https://maps4html.org/experiments/api/custom-map-ui --- +### matchMedia(mediaQueryString) + +While not strictly 'media' features, some dynamic map properties can be combined in queries with standard media features, for example the 'prefers-color-scheme' feature, +to enable a map container / media-query-like interface. + +`matchMedia(mediaQueryString)` returns a [MediaQueryList-like object](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList). +The `matches` boolean-valued property of the object can be used for an immediate determination of whether the map meets the queried feature conditions. To react to changes in +the map state / media conditions, use MediaQueryList.addEventListener('change', callbackFn) to add an event listener for `change` events that are triggered by changes in the +state of the queried map properties (projection, zoom, extent); any change to the map that results in a change in state of the [MediaQueryListEvent `matches` boolean property](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/change_event)triggers the `change` event and calls the callbackFn. + +## Supported map 'media' query features + +| Feature name | Description | +|------------------|-------------| +| map-zoom | Range of integers Used to evaluate if map-zoom is of a certain value or within a range | +| map-projection | Discrete string values - known values include `OSMTILE`, `CBMTILE`, `WGS84`, `APSTILE`. Can be extended with [custom projections](#definecustomprojectionoptions). | +| map-top-left-easting | Range of integers - **Decimal values are not supported.** | +| map-top-left-northing | Range of integers - **Decimal values are not supported.** | +| map-bottom-right-easting | Range of integers - **Decimal values are not supported.** | +| map-bottom-right-northing | Range of integers - **Decimal values are not supported.** | +| prefers-map-content | Discrete string values - supported values include: `image`, `tile`, `feature`, `table`. Preferences can be established via multi-select in the [MapML browser extension](../extension/features#select-map-content-preferences) | +| prefers-color-scheme | Discrete string values - supported values are `light` and `dark` | +| prefers-lang | 2-character language code returned by `navigator.language`, based on user's browser display language setting | + +--- + ## Events | Event name | Description | @@ -617,7 +644,7 @@ let output = map.geojson2mapml(json);