map-boundary-editor 0.1.0 → 0.3.0

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/README.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # map-boundary-editor
2
2
 
3
- **map-boundary-editor** is a generic, embeddable, map-based boundary editor
4
- implemented as a Web Component.
3
+ [![npm](https://img.shields.io/npm/v/map-boundary-editor)](https://www.npmjs.com/package/map-boundary-editor)
4
+ [![license](https://img.shields.io/npm/l/map-boundary-editor)](LICENSE)
5
+ [![downloads](https://img.shields.io/npm/dm/map-boundary-editor)](https://www.npmjs.com/package/map-boundary-editor)
5
6
 
6
- It allows users to visually draw and edit a geographic boundary
7
- and outputs a standard **GeoJSON** representation that can be reused
8
- across different map engines and backend systems.
7
+ **map-boundary-editor** is a lightweight, embeddable map-based boundary editor
8
+ designed for defining and validating geographic service boundaries.
9
+
10
+ It is optimized for use cases where a **user-defined area (polygon)** must be
11
+ evaluated against a **fixed administrative or reference boundary** — such as
12
+ service eligibility, coverage restriction, or zoning rules.
9
13
 
10
14
  ---
11
15
 
@@ -18,6 +22,9 @@ Many applications need users to define geographic areas:
18
22
  - eligibility rules
19
23
  - geofencing configuration
20
24
 
25
+ A common requirement in these use cases is a clear separation between
26
+ **editable user input** and **non-editable reference boundaries**.
27
+
21
28
  Most teams end up rebuilding the same map drawing logic again and again,
22
29
  tightly coupled to a specific map provider.
23
30
 
@@ -29,15 +36,31 @@ tightly coupled to a specific map provider.
29
36
 
30
37
  ---
31
38
 
32
- ## Features (v0.1)
39
+ ## Key Concepts
40
+
41
+ ### Editable Polygon
42
+
43
+ A polygon created or modified by the user to represent an area of interest
44
+ (e.g. delivery zone, service coverage).
45
+
46
+ ### Reference Boundary
33
47
 
34
- - Draw, edit, and delete a polygon boundary
35
- - Leaflet-based (no API key required)
36
- - Outputs standard GeoJSON (RFC 7946)
37
- - Framework-agnostic (Web Component)
38
- - Easy to embed in any web application
48
+ A fixed, non-editable boundary used as a reference for validation or restriction.
49
+ Typical examples include cities, provinces, or regulatory zones.
39
50
 
40
- > Note: v0.1 supports a single boundary only.
51
+ ### Readonly Mode
52
+
53
+ A mode where editing controls are disabled, allowing the map to be used purely
54
+ for visualization, review, or approval workflows.
55
+
56
+ ---
57
+
58
+ ## Features
59
+
60
+ - Draw, edit, and delete **editable polygon** boundaries
61
+ - Support for fixed, non-editable **reference boundaries**
62
+ - Read-only mode for review or visualization use cases
63
+ - Supports multiple editable boundaries (GeoJSON `FeatureCollection`)
41
64
 
42
65
  ---
43
66
 
@@ -51,73 +74,165 @@ npm install map-boundary-editor
51
74
 
52
75
  ---
53
76
 
54
- ### Via script tag
55
-
56
- ```html
57
- <script src="map-boundary-editor.min.js"></script>
58
- ```
59
-
60
- ---
77
+ ## Basic Usage (Recommended)
61
78
 
62
- ## Basic Usage
79
+ The most common usage pattern is defining an editable area **within** a fixed reference boundary.
63
80
 
64
81
  ```html
65
- <map-boundary-editor style="width: 800px; height: 500px;"></map-boundary-editor>
66
-
67
- <script>
68
- const editor = document.querySelector("map-boundary-editor");
82
+ <map-boundary-editor
83
+ id="editor"
84
+ style="width: 800px; height: 500px;"
85
+ ></map-boundary-editor>
86
+
87
+ <script type="module">
88
+ import "map-boundary-editor";
89
+
90
+ const editor = document.getElementById("editor");
91
+
92
+ // Set a fixed reference boundary (e.g. administrative area)
93
+ editor.setBoundary({
94
+ type: "FeatureCollection",
95
+ features: [
96
+ {
97
+ type: "Feature",
98
+ geometry: {
99
+ type: "Polygon",
100
+ coordinates: [
101
+ [
102
+ [106.69, -6.1],
103
+ [107.03, -6.1],
104
+ [107.03, -6.38],
105
+ [106.69, -6.38],
106
+ [106.69, -6.1],
107
+ ],
108
+ ],
109
+ },
110
+ properties: {},
111
+ },
112
+ ],
113
+ });
69
114
 
115
+ // Listen for user-defined polygon changes
70
116
  editor.addEventListener("change", (e) => {
71
- console.log("GeoJSON:", e.detail.geojson);
117
+ console.log("Editable GeoJSON:", e.detail.geojson);
72
118
  });
73
119
  </script>
74
120
  ```
75
121
 
122
+ > All public APIs (`setView`, `setGeoJSON`, `clear`, etc.) are safe to call
123
+ > immediately after the element is created.
124
+ > No `setTimeout` or `customElements.whenDefined` is required.
125
+
76
126
  ---
77
127
 
78
- ## Loading an Existing Boundary
128
+ ### Loading an Existing Editable Boundary
79
129
 
80
130
  ```js
81
131
  editor.setGeoJSON({
82
- type: "Feature",
83
- geometry: {
84
- type: "Polygon",
85
- coordinates: [
86
- [
87
- [106.8166, -6.2],
88
- [106.82, -6.21],
89
- [106.83, -6.205],
90
- [106.8166, -6.2],
91
- ],
92
- ],
93
- },
94
- properties: {},
132
+ type: "FeatureCollection",
133
+ features: [
134
+ {
135
+ type: "Feature",
136
+ geometry: {
137
+ type: "Polygon",
138
+ coordinates: [
139
+ [
140
+ [106.8166, -6.2],
141
+ [106.82, -6.21],
142
+ [106.83, -6.205],
143
+ [106.8166, -6.2],
144
+ ],
145
+ ],
146
+ },
147
+ properties: {},
148
+ },
149
+ ],
95
150
  });
96
151
  ```
97
152
 
153
+ Even when loading a single boundary, the data must be wrapped in a `FeatureCollection` for consistency.
154
+
155
+ ---
156
+
157
+ ### View Control
158
+
159
+ ```js
160
+ editor.setView(lat, lng, zoom);
161
+ ```
162
+
163
+ If editable boundaries are later loaded using `setGeoJSON`, the map will automatically fit to the boundary.
164
+
98
165
  ---
99
166
 
100
- ## Public API (v0.1)
167
+ ### Optional: Geolocation Helper
168
+
169
+ An optional geolocation helper is available to center the map on the user's current location.
101
170
 
102
- `getGeoJSON(): GeoJSON`
171
+ This feature only affects the initial view and does not modify boundaries or output GeoJSON.
103
172
 
104
- Returns the current boundary as GeoJSON.
173
+ ```html
174
+ <map-boundary-editor use-geolocation></map-boundary-editor>
175
+ ```
176
+
177
+ ---
105
178
 
106
- `setGeoJSON(geojson: GeoJSON): void`
179
+ ## Public API (v0.3)
107
180
 
108
- Loads a boundary from GeoJSON and renders it on the map.
181
+ ### Editable Polygon
182
+
183
+ `setGeoJSON(geojson: FeatureCollection): void`
184
+
185
+ Loads editable polygon boundaries from GeoJSON.
186
+
187
+ `getGeoJSON(): FeatureCollection`
188
+
189
+ Returns the current editable polygon boundaries.
109
190
 
110
191
  `clear(): void`
111
192
 
112
- Removes the current boundary.
193
+ Removes all editable polygon boundaries.
194
+
195
+ ---
196
+
197
+ ### Reference Boundary
198
+
199
+ `setBoundary(geojson: FeatureCollection): void`
200
+
201
+ Sets a fixed, non-editable reference boundary.
202
+
203
+ `getBoundary(): FeatureCollection | null`
204
+
205
+ Returns the current reference boundary.
206
+
207
+ `clearBoundary(): void`
208
+
209
+ Removes the reference boundary from the map.
210
+
211
+ ---
212
+
213
+ ### Mode Control
214
+
215
+ `setReadonly(value: boolean): void`
216
+
217
+ Enables or disables editing controls.
218
+
219
+ `isReadonly(): boolean`
220
+
221
+ Returns the current readonly state.
113
222
 
114
223
  ---
115
224
 
225
+ ### View Control
226
+
227
+ `setView(lat: number, lng: number, zoom?: number): void`
228
+
229
+ Moves the map to the specified location.
230
+
116
231
  ## Events
117
232
 
118
- `change`
233
+ ### change
119
234
 
120
- Fired whenever the boundary is created, edited, or deleted.
235
+ Fired whenever the editable polygon is created, edited, or deleted.
121
236
 
122
237
  ```js
123
238
  editor.addEventListener("change", (e) => {
@@ -131,8 +246,7 @@ editor.addEventListener("change", (e) => {
131
246
 
132
247
  The editor uses GeoJSON as its data contract.
133
248
 
134
- GeoJSON is treated as the single source of truth and is intentionally decoupled
135
- from any specific map engine.
249
+ GeoJSON is treated as the single source of truth and is intentionally decoupled from any specific map engine.
136
250
 
137
251
  The output is compatible with:
138
252
 
@@ -142,11 +256,32 @@ The output is compatible with:
142
256
 
143
257
  ---
144
258
 
259
+ ## Demo
260
+
261
+ A demo is included in the repository to showcase:
262
+
263
+ - Editable polygons vs administrative reference boundaries
264
+ - Visual hierarchy between reference and user-defined areas
265
+ - Readonly vs editable interaction modes
266
+
267
+ The demo also serves as a reference implementation for integrating the component
268
+ into real-world applications.
269
+
270
+ ---
271
+
145
272
  ## Roadmap
146
273
 
147
- - v0.2: multiple boundaries (FeatureCollection)
148
- - v0.3: read-only mode
274
+ - v0.3: reference boundary support, read-only mode, improved demo UX
149
275
  - v0.4: additional map engine adapters (MapLibre, Google Maps)
150
276
  - v1.0: stable API
151
277
 
152
278
  ---
279
+
280
+ ## Non-Goals
281
+
282
+ This project is intentionally not:
283
+
284
+ - A full GIS editor
285
+ - A GeoJSON validation library
286
+ - A replacement for tools like geojson.io
287
+ - A general-purpose map rendering framework