Sources and layers
<map.Source> yields <source.Layer>. When Ember
removes the component, the layer goes away.
Meridian
One declarative map, any tile server, any provider. Meridian is a port of
@vis.gl/react-maplibre to Ember .gts components on MapLibre GL
JS. It also has a provider layer for geocoding, places and routing.
pnpm add @meridian-ts/ember maplibre-gl
Ember 5.12 or later, Vite and Embroider, maplibre-gl 5.
<MeridianMap
@mapStyle="https://tiles.openfreemap.org/styles/liberty"
@initialViewState={{hash lng=-123.125 lat=49.287 zoom=11.3}}
@options={{hash cooperativeGestures=true}}
style="height: 440px"
as |map|
>
{{#each this.places as |place|}}
<map.Marker @lngLat={{place.location}} @color="#be123c" />
{{/each}}
<map.Popup
@lngLat={{this.park.location}}
@offset={{36}}
@closeButton={{false}}
@closeOnClick={{false}}
>
{{this.park.name}}
</map.Popup>
<map.NavigationControl @position="top-right" />
</MeridianMap>
The map loads here.
A declarative map
A source, layer, marker, popup or control is on the map while its component is in the template. Change an argument, and Meridian makes the smallest MapLibre call. You do not write the calls that keep the map and your state the same.
<map.Source> yields <source.Layer>. When Ember
removes the component, the layer goes away.
New data calls setData. New paint calls setPaintProperty.
Meridian does not make the layer again.
The block of <map.Marker> or <map.Popup> is its
content: your components, with your state.
The block yields map.instance, and @onLoad sends it. Use it
for imperative calls.
<MeridianMap @mapStyle={{this.style}} @viewState={{this.view}} @onMove={{this.setView}} as |map|>
<map.Source @type="geojson" @data={{this.stops}} as |source|>
<source.Layer @type="circle" @paint={{this.paint}} @onClick={{this.select}} />
</map.Source>
<map.Marker @lngLat={{this.office}} @draggable={{true}} @onDragEnd={{this.move}}>
<OfficePin />
</map.Marker>
{{#if this.selected}}
<map.Popup @lngLat={{this.selected.location}} @onClose={{this.clear}}>
{{this.selected.name}}
</map.Popup>
{{/if}}
<map.NavigationControl @position="top-right" />
<map.ScaleControl @position="bottom-left" />
</MeridianMap>
The camera is controlled (@viewState with @onMove) or
uncontrolled (@initialViewState). On the server, the component renders an
empty element.
Guide: your first map, sources and layers, view state.
Tiles
@mapStyle accepts a style URL or a style object. A source accepts vector
tiles, raster tiles, TileJSON and GeoJSON. Thus the map works with a hosted service and
with your own server.
{{!-- protocol: a Protocol of 'pmtiles' --}}
<MeridianMap
@mapStyle={{this.style}}
@protocols={{hash pmtiles=this.protocol.tile}}
as |map|
>
<map.Source
@type="vector"
@url="pmtiles://https://example.com/a.pmtiles"
as |source|
>
<source.Layer
@type="line"
@sourceLayer="roads"
@paint={{this.roadPaint}}
/>
</map.Source>
</MeridianMap>
{{!--
this.tiles: one URL template, for example
https://example.com/wms?…&bbox={bbox-epsg-3857}
--}}
<MeridianMap @mapStyle={{this.style}} as |map|>
<map.Source
@type="raster"
@tiles={{this.tiles}}
@tileSize={{256}}
@attribution="© Example"
as |source|
>
<source.Layer
@type="raster"
@paint={{hash raster-opacity=0.7}}
/>
</map.Source>
</MeridianMap>
Each name above is a link to its guide page, with a live example.
Location services
Geocoding, places, routing, elevation, time zone, static maps and IP location are small interfaces. One configuration selects a provider for each. To change a provider, change one line.
// app/meridian.ts
import { defineMeridian } from '@meridian-ts/core'
import { photon } from '@meridian-ts/photon'
import { stadia } from '@meridian-ts/stadia'
// The proxy on your server adds the key.
const hosted = stadia({ baseUrl: '/api/stadia' })
export const meridian = defineMeridian({
geocoding: photon(),
routing: hosted,
timezone: hosted,
})
import { meridian } from './meridian'
const { geocoding, routing } = meridian
const places = await geocoding.autocomplete(
'Stanley Pa',
{ limit: 5, signal: controller.signal },
)
// A result has { lat, lng }.
// An argument can also be [lng, lat].
const [route] = await routing.directions(
[places[0].location, [-123.1162, 49.2845]],
{ mode: 'bike' },
)
meridian.supports('routing.isochrone') // true
Each example is a Meridian component in the guide. It calls a public server from your browser, so an answer can be slow.
Type a name, then select a place. The map moves to it.
A route between two places, with its distance, its time and its steps.
Click the map to see the address of that point.
The area that you can reach on foot in 5, 10 and 15 minutes. Click the map to move the point.
Each adapter is one package. It calls the REST API of the provider with
fetch, without the SDK of the provider, so it also works on the server. An
adapter has only the functions that its provider has.
Nominatim. No key.
Photon. No key.
Pelias. Your server, or Geocode Earth with a key.
Valhalla. Your server. No key.
Stadia Maps. API key or proxy.
MapTiler. API key or proxy.
Mapbox. Access token or proxy.
Google Maps Platform. API key or proxy. Read the terms first.
HERE. API key or proxy.
Esri ArcGIS. API key or proxy.
Amazon Location Service. API key or proxy.
Each adapter accepts a public key, or a baseUrl for your own proxy. With
baseUrl, the adapter sends the same path and query to the proxy, and sends no
key. Meridian ships no proxy.
The Google terms limit the use of Google content with a map that is not a Google map. Read the warning in the README of the Google adapter before you use it.
Components
Place autocomplete, a geocoder control for the map, and directions. The components are headless: they ship no styles by default. An optional theme file gives a default look with CSS custom properties.
<PlaceAutocomplete
aria-label="Find a place"
placeholder="Find a place"
@provider={{meridian.geocoding}}
@options={{hash limit=5 countries=this.countries}}
@onSelect={{this.goTo}}
>
<:option as |place active|>
<PlaceRow @place={{place}} @active={{active}} />
</:option>
<:empty>No places</:empty>
</PlaceAutocomplete>
<MeridianMap @mapStyle={{this.style}} as |map|>
<map.GeocoderControl
@provider={{meridian.geocoding}}
@position="top-left"
aria-label="Find a place"
/>
<map.Directions
@provider={{meridian.routing}}
@waypoints={{this.stops}}
@mode="walk"
as |directions|
>
{{#if directions.route}}
<map.Control @position="bottom-left">
<DirectionsSteps @route={{directions.route}} />
</map.Control>
{{/if}}
</map.Directions>
</MeridianMap>
// The optional theme. Without it, the components have no styles.
import '@meridian-ts/ember/theme.css'
For your own UI, query gives the state of a request to a template:
value, isLoading and error, with a debounce and an
AbortSignal.
Optional
Clusters are in @meridian-ts/ember. Draw tools and deck.gl layers are
optional packages. Each component loads its library with a dynamic import, so it stays out
of the first bundle.
<map.Cluster> yields a layer, and also the clusters and points in
view, for your own markers.
<Draw> is terra-draw as a component: points, lines, polygons,
rectangles, circles and freehand.
<Deck> is a deck.gl overlay. Each <deck.Layer>
is one deck.gl layer class with its props.
<deck.HexCluster> puts each point into an H3 cell and colours the
cell by its count.
{{!-- Draw is from '@meridian-ts/draw'. Deck is from '@meridian-ts/deck'. --}}
<MeridianMap @mapStyle={{this.style}} as |map|>
<map.Cluster @data={{this.stops}} @radius={{60}} as |cluster|>
{{#each cluster.clusters as |item|}}
<map.Marker @lngLat={{item.location}} @onClick={{fn cluster.expand item}}>
<span class="cluster">{{item.count}}</span>
</map.Marker>
{{/each}}
{{#each cluster.points as |point|}}
<map.Marker @lngLat={{point.location}} />
{{/each}}
</map.Cluster>
<Draw @map={{map}} @mode="polygon" @onFinish={{this.saveArea}} />
<Deck @map={{map}} as |deck|>
<deck.HexCluster @data={{this.trips}} @getPosition={{this.pickup}} @extruded={{true}} />
</Deck>
</MeridianMap>
Guide: clusters, draw and edit, deck.gl layers, hexagon clusters.
A port
Meridian is a port of
@vis.gl/react-maplibre. The names
agree with the React library, and most examples port line by line. The root is
MeridianMap, because Map hides the JavaScript global in a
.gts file.
<Map
initialViewState={view}
mapStyle={styleUrl}
onClick={onClick}
>
<Source
id="stops"
type="geojson"
data={stops}
>
<Layer
id="dots"
type="circle"
paint={paint}
/>
</Source>
<Marker longitude={-123.12} latitude={49.28} />
<NavigationControl position="top-right" />
</Map>
<MeridianMap
@initialViewState={{this.view}}
@mapStyle={{this.styleUrl}}
@onClick={{this.onClick}}
as |map|
>
<map.Source
@type="geojson"
@data={{this.stops}}
as |source|
>
<source.Layer
@id="dots"
@type="circle"
@paint={{this.paint}}
/>
</map.Source>
<map.Marker @lngLat={{hash lng=-123.12 lat=49.28}} />
<map.NavigationControl @position="top-right" />
</MeridianMap>
useControl is <map.Control @create=…>.
useMap is map.instance in the block. Layer events are arguments
on the layer, so you do not set interactiveLayerIds.
Packages
All packages are in the @meridian-ts scope. Core and the adapters are plain
TypeScript with no dependency on Ember, so they also work on the server.
| Package | Contents | Peers |
|---|---|---|
@meridian-ts/ember |
The map, sources, layers, markers, popups, controls, clusters, the UI components,
query and theme.css.
|
ember-source, maplibre-gl |
@meridian-ts/core |
Coordinate types, the capability interfaces, defineMeridian and the
errors.
|
none |
@meridian-ts/draw |
<Draw>: draw and edit tools on terra-draw. |
terra-draw, terra-draw-maplibre-gl-adapter |
@meridian-ts/deck |
<Deck>, <deck.Layer> and
<deck.HexCluster>.
|
@deck.gl/core, @deck.gl/mapbox, h3-js
|
@meridian-ts/nominatim |
The adapter for Nominatim: geocoding. | none |
@meridian-ts/photon |
The adapter for Photon: geocoding with autocomplete. | none |
@meridian-ts/pelias |
The adapter for Pelias: geocoding and places. | none |
@meridian-ts/valhalla |
The adapter for Valhalla: routing and elevation. | none |
@meridian-ts/stadia |
The adapter for Stadia Maps: geocoding, places, routing, elevation, time zone and static maps. | none |
@meridian-ts/maptiler |
The adapter for MapTiler: geocoding, elevation, static maps and IP location. | none |
@meridian-ts/mapbox |
The adapter for Mapbox: geocoding, places, routing and static maps. | none |
@meridian-ts/google |
The adapter for Google Maps Platform: all seven capabilities. Read the terms first. | none |
@meridian-ts/here |
The adapter for HERE: geocoding, places, routing and static maps. | none |
@meridian-ts/esri |
The adapter for Esri ArcGIS: geocoding, places, routing and elevation. | none |
@meridian-ts/aws |
The adapter for Amazon Location Service: geocoding, places, routing and static maps. | none |
Get started
Meridian needs Ember 5.12 or later, Vite with Embroider, and
maplibre-gl 5 or later. The map loads maplibre-gl with a dynamic
import.
pnpm add @meridian-ts/ember maplibre-gl
import { MeridianMap } from '@meridian-ts/ember'
import { hash } from '@ember/helper'
<template>
<MeridianMap
@mapStyle="https://tiles.openfreemap.org/styles/liberty"
@initialViewState={{hash lng=-123.12 lat=49.28 zoom=11}}
style="height: 400px"
as |map|
>
<map.Marker @lngLat={{hash lng=-123.12 lat=49.28}} />
<map.NavigationControl @position="top-right" />
</MeridianMap>
</template>
The map element needs a height. Then add a provider:
pnpm add @meridian-ts/core @meridian-ts/photon
More
Meridian is the library for maps and locations on the
Ember Workbench. Coordinates are
structural: each object with lat and lng works, and thus a
Millwork LatLng value fits.
@meridian-ts.