@ogis/waymark-js 2.0.0-alpha.9 β†’ 3.0.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ogis/waymark-js",
3
- "version": "2.0.0-alpha.9",
3
+ "version": "3.0.0-alpha",
4
4
  "type": "module",
5
5
  "license": "GPL-2.0-only",
6
6
  "repository": {
@@ -23,24 +23,31 @@
23
23
  ".": {
24
24
  "import": "./dist/waymark-js.js",
25
25
  "require": "./dist/waymark-js.umd.cjs"
26
- }
26
+ },
27
+ "./dist/waymark-js.css": "./dist/waymark-js.css"
27
28
  },
28
29
  "scripts": {
29
30
  "build": "vite build",
30
- "dev": "vite --host"
31
+ "dev": "concurrently \"vite --host\" \"npm run test:watch\"",
32
+ "test": "vitest run",
33
+ "test:watch": "vitest watch"
34
+ },
35
+ "vitest": {
36
+ "setupFiles": "./tests/setupTests.js"
31
37
  },
32
38
  "dependencies": {
39
+ "@turf/bbox": "^7.3.2",
33
40
  "@turf/length": "^7.2.0",
34
- "font-awesome": "^4.7.0",
35
- "ionicons-npm": "^2.0.1",
41
+ "lodash-es": "^4.17.22",
36
42
  "maplibre-gl": "^5.7.1",
37
- "pinia": "^2.1.7",
38
- "vue": "^3.4.21"
43
+ "ulid": "^3.0.2"
39
44
  },
40
45
  "devDependencies": {
41
- "@vitejs/plugin-vue": "^5.0.4",
46
+ "concurrently": "^9.2.1",
47
+ "jsdom": "^24.1.0",
42
48
  "less": "^4.2.0",
43
49
  "prettier": "^3.2.5",
44
- "vite": "^6.3.5"
50
+ "vite": "^6.3.5",
51
+ "vitest": "^4.0.17"
45
52
  }
46
53
  }
package/readme.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Waymark JS
2
2
 
3
3
  > [!CAUTION]
4
- > Waymark JS v2 is currently in alpha. Many features are not yet implemented. Please see the [To-Do list](/readme.md#to-do) for details.
4
+ > Waymark JS v3 is currently in alpha.
5
5
 
6
- _Create, Edit and Share Meaningful Maps_
6
+ Adding _meaning_ to GeoJSON.
7
7
 
8
- Waymark JS is a JavaScript library for creating and sharing geographical information. It is designed to be easy to use and intuitive, and is suitable for a wide range of applications due to its flexibility and customisation [options](/docs/v2/2.instances.md#map-options). Waymark JS stores data in GeoJSON format.
8
+ Waymark JS is a JavaScript library for rendering GeoJSON data on a [OpenStreetMap](https://www.openstreetmap.org/) vector basemap.
9
9
 
10
10
  Built on the shoulders of giants:
11
11
 
@@ -26,7 +26,7 @@ npm install @ogis/waymark-js
26
26
  Then import the library and CSS in your JavaScript:
27
27
 
28
28
  ```javascript
29
- import { Instance } from "@ogis/waymark-js";
29
+ import { createInstance } from "@ogis/waymark-js";
30
30
  import "@ogis/waymark-js/dist/waymark-js.css";
31
31
  ```
32
32
 
@@ -43,10 +43,11 @@ To use via CDN, include the following in your HTML:
43
43
  />
44
44
 
45
45
  <script type="module">
46
- import { Instance } from "https://unpkg.com/@ogis/waymark-js/dist/waymark-js.js";
46
+ import { createInstance } from "https://unpkg.com/@ogis/waymark-js/dist/waymark-js.js";
47
47
  </script>
48
48
  ```
49
49
 
50
+ <!--
50
51
  #### UMD
51
52
 
52
53
  When you can't rely on native ES modules, you can load the bundled UMD build via a classic `<script>` tag. The bundle exposes a `WaymarkJS` global with the same `Instance` class that the package exports.
@@ -69,7 +70,9 @@ When you can't rely on native ES modules, you can load the bundled UMD build via
69
70
  <div id="waymark-instance" style="height: 480px"></div>
70
71
  <script>
71
72
  window.addEventListener("DOMContentLoaded", () => {
72
- const instance = new WaymarkJS.Instance();
73
+ const instance = new WaymarkJS.createInstance({
74
+ id: "waymark-instance",
75
+ });
73
76
  });
74
77
  </script>
75
78
  </body>
@@ -77,6 +80,7 @@ When you can't rely on native ES modules, you can load the bundled UMD build via
77
80
  ```
78
81
 
79
82
  If you're self-hosting the assets, replace the CDN URLs with your local `waymark-js.css` and `waymark-js.umd.cjs` paths.
83
+ -->
80
84
 
81
85
  ## Usage
82
86
 
@@ -89,86 +93,98 @@ Add a container element for the Instance:
89
93
  ```
90
94
 
91
95
  > [!NOTE]
92
- > The element that contains the Instance must have a **height** set, either inline or via CSS.
96
+ > Instance element must have a **height** in order to be visible.
97
+ > 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).
93
98
 
94
99
  ### JavaScript
95
100
 
96
- Create a Waymark Instance with your configuration, then load some GeoJSON data:
101
+ Create a Waymark Instance with your configuration, showing some GeoJSON data:
97
102
 
98
103
  ```javascript
99
- import { Instance } from "@ogis/waymark-js";
104
+ import { createInstance } from "@ogis/waymark-js";
100
105
  import "@ogis/waymark-js/dist/waymark-js.css";
101
106
 
102
- // Create a Waymark Instance with this configuration
103
- const instance = new Instance({
104
- // See [Map Options](docs/v2/2.instances.md#map-options) for details
105
- map_options: {
106
- // This is the default, so can be omitted
107
- div_id: "waymark-instance",
108
-
109
- // Passed directly to MapLibre GL JS
110
- // See [MapLibre Map Options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/)
111
- maplibre_options: {
112
- zoom: 12,
113
- },
114
-
115
- // See [Marker Types](docs/v2/2.instances.md#marker-types) for details
116
- marker_types: [
107
+ const instance = createInstance({
108
+ // Will console.log() all Waymark JS Events
109
+ // debug: true,
110
+
111
+ // Unique ID repesenting the DOM element to load the Instance into
112
+ // Is added to the DOM if it doesn't exist
113
+ id: "waymark-instance",
114
+
115
+ // MapLibre GL JS Options
116
+ // See [MapLibre Map Options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/)
117
+ mapOptions: {
118
+ zoom: 12,
119
+ },
120
+
121
+ // Can pass GeoJSON here
122
+ geoJSON: {
123
+ type: "FeatureCollection",
124
+ features: [
117
125
  {
118
- marker_title: "Pub",
119
- marker_shape: "marker",
120
- marker_size: "large",
121
- icon_type: "icon",
122
- marker_icon: "ion-beer",
123
- marker_colour: "#fbfbfb",
124
- icon_colour: "#754423",
126
+ // Set an ID here so you can access the Overlay
127
+ id: "pub-marker",
128
+ type: "Feature",
129
+ properties: {
130
+ // Waymark Properties
131
+ waymark: {
132
+ // The Title & Descrption will display when the Marker is clicked
133
+ title: "The Scarlet Ibis",
134
+ description:
135
+ "Great pub, great food! Especially after a Long Ride πŸš΄πŸ”πŸŸπŸΊπŸΊπŸ’€",
136
+
137
+ // MapLibre GL JS Layer Paint Properties
138
+ paint: {
139
+ "circle-radius": 20,
140
+ "circle-color": "white",
141
+ "circle-stroke-color": "brown",
142
+ "circle-stroke-width": 6,
143
+ },
144
+
145
+ // Marker Icons
146
+ icon: {
147
+ // <img /> and <i /> tags work well here
148
+ html: `<div style="font-size:32px">🍺</div>`,
149
+
150
+ // Inline SVG supported
151
+ // svg: `<svg />`
152
+
153
+ // Image URLs supported
154
+ // url: "https://...pint.png
155
+ },
156
+ },
157
+ },
158
+ geometry: {
159
+ type: "Point",
160
+ coordinates: [-128.0094, 50.6539],
161
+ },
125
162
  },
126
163
  ],
127
164
  },
128
- });
129
165
 
130
- // Load this GeoJSON, which contains a single "pub" Marker
131
- instance.loadGeoJSON({
132
- type: "FeatureCollection",
133
- features: [
134
- {
135
- type: "Feature",
136
- properties: {
137
- type: "pub",
138
- title: "The Scarlet Ibis",
139
- description:
140
- "Great pub, great food! Especially after a Long Ride πŸš΄πŸ”πŸŸπŸΊπŸΊπŸ’€",
141
- image_large_url: "https://www.waymark.dev/assets/geo/pub.jpeg",
142
- },
143
- geometry: {
144
- type: "Point",
145
- coordinates: [-128.0094, 50.6539],
146
- },
147
- },
148
- ],
166
+ // This function is called when the Instance has finished loading
167
+ // and is passed the Instance as an argument
168
+ onLoad: (thisInstance) => {
169
+ //Get the Waymark JS Overlay for the "pub-marker" Feature
170
+ const pubMarker = thisInstance.geoJSONStore.getItem("pub-marker");
171
+
172
+ // Get the MapLibre GL JS Map
173
+ const map = thisInstance.mapLibreStore.mapLibreMap;
174
+
175
+ // Set the map view to fit the Marker (instantly)
176
+ map.setCenter(pubMarker.geometry.coordinates);
177
+ map.setZoom(12);
178
+ },
149
179
  });
150
180
  ```
151
181
 
182
+ <!--
152
183
  ## Documentation
153
184
 
154
- 1. [Start Here](docs/v2/1.index.md)
155
- 2. [Instances](docs/v2/2.instances.md)
156
-
157
- ## To-Do
158
-
159
- Alpha
160
-
161
- - [ ] Demo PAGE
162
-
163
- Later
164
-
165
- - [ ] Map Options:
166
- - [ ] `map_init_basemap`
167
- - [ ] `show_scale`
168
- - [ ] `debug_mode`
169
- - [ ] Viewer Options
170
- - [ ] Editor Options
171
- - [ ] GPX/KML Import/Export
185
+ 1. [Start Here](docs/v3/1.index.md)
186
+ 2. [Instances](docs/v3/2.instances.md)
187
+ -->
172
188
 
173
189
  ## Development
174
190
 
@@ -179,7 +195,7 @@ Later
179
195
  # Install dependencies
180
196
  npm install
181
197
 
182
- # Run the development server
198
+ # Run the dev server (& tests)
183
199
  npm run dev
184
200
 
185
201
  # Build for production