Waymark JS
[!CAUTION]
Waymark JS v3 is currently in alpha.
Adding meaning to GeoJSON.
Waymark JS is a JavaScript library for rendering GeoJSON data on a OpenStreetMap vector basemap.
«« View the Demo »»
Built on the shoulders of giants:
Installation
NPM
To install via NPM, run:
npm install @ogis/waymark-js
Then import the library and CSS in your JavaScript:
import { createInstance } from "@ogis/waymark-js";
import "@ogis/waymark-js/dist/waymark-js.css";
CDN
ES Module
To use via CDN, include the following in your HTML:
<link
rel="stylesheet"
href="https://unpkg.com/@ogis/waymark-js/dist/waymark-js.css"
/>
<script type="module">
import { createInstance } from "https://unpkg.com/@ogis/waymark-js/dist/waymark-js.js";
</script>
Usage
HTML
Add a container element for the Instance:
<div id="waymark-instance" style="height: 480px"></div>
[!NOTE]
Instance element must have a height in order to be visible.
If there isn't a DOM element with the given id, Waymark JS will create one for you and append it to the body (with 100% width and height).
JavaScript
Create a Waymark Instance with your configuration, showing some GeoJSON data:
import { createInstance } from "@ogis/waymark-js";
import "@ogis/waymark-js/dist/waymark-js.css";
const instance = createInstance({
id: "waymark-instance",
mapOptions: {
zoom: 12,
},
geoJSON: {
type: "FeatureCollection",
features: [
{
id: "pub-marker",
type: "Feature",
properties: {
waymark: {
title: "The Scarlet Ibis",
description:
"Great pub, great food! Especially after a Long Ride 🚴🍔🍟🍺🍺💤",
paint: {
"circle-radius": 20,
"circle-color": "white",
"circle-stroke-color": "brown",
"circle-stroke-width": 6,
},
icon: {
html: `<div style="font-size:32px">🍺</div>`,
},
},
},
geometry: {
type: "Point",
coordinates: [-128.0094, 50.6539],
},
},
],
},
onLoad: (thisInstance) => {
const pubMarker = thisInstance.geoJSONStore.getItem("pub-marker");
const map = thisInstance.mapLibreStore.mapLibreMap;
map.setCenter(pubMarker.geometry.coordinates);
map.setZoom(12);
},
});
Development
[!IMPORTANT]
To build Waymark JS from source, you will need Node + NPM.
npm install
npm run dev
npm run build