map-boundary-editor 0.1.0 → 0.2.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 +120 -23
- package/dist/map-boundary-editor.js +248 -229
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# map-boundary-editor
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/map-boundary-editor)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/map-boundary-editor)
|
|
6
|
+
|
|
3
7
|
**map-boundary-editor** is a generic, embeddable, map-based boundary editor
|
|
4
8
|
implemented as a Web Component.
|
|
5
9
|
|
|
@@ -29,15 +33,14 @@ tightly coupled to a specific map provider.
|
|
|
29
33
|
|
|
30
34
|
---
|
|
31
35
|
|
|
32
|
-
## Features
|
|
36
|
+
## Features
|
|
33
37
|
|
|
34
|
-
- Draw, edit, and delete
|
|
38
|
+
- Draw, edit, and delete polygon boundaries
|
|
39
|
+
- Supports **multiple boundaries** (GeoJSON `FeatureCollection`)
|
|
35
40
|
- Leaflet-based (no API key required)
|
|
36
41
|
- Outputs standard GeoJSON (RFC 7946)
|
|
37
|
-
- Framework-agnostic
|
|
38
|
-
-
|
|
39
|
-
|
|
40
|
-
> Note: v0.1 supports a single boundary only.
|
|
42
|
+
- Framework-agnostic Web Component
|
|
43
|
+
- **Lifecycle-safe public API** (no timing hacks required)
|
|
41
44
|
|
|
42
45
|
---
|
|
43
46
|
|
|
@@ -51,21 +54,21 @@ npm install map-boundary-editor
|
|
|
51
54
|
|
|
52
55
|
---
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
## Basic Usage (Recommended)
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
<script src="map-boundary-editor.min.js"></script>
|
|
58
|
-
```
|
|
59
|
+
Use module scripts only to ensure correct loading order.
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
```html
|
|
62
|
+
<map-boundary-editor id="editor" style="width: 800px; height: 500px;">
|
|
63
|
+
</map-boundary-editor>
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
<script type="module">
|
|
66
|
+
import "map-boundary-editor";
|
|
63
67
|
|
|
64
|
-
|
|
65
|
-
<map-boundary-editor style="width: 800px; height: 500px;"></map-boundary-editor>
|
|
68
|
+
const editor = document.getElementById("editor");
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
// Public APIs are lifecycle-safe
|
|
71
|
+
editor.setView(-6.2, 106.8, 11);
|
|
69
72
|
|
|
70
73
|
editor.addEventListener("change", (e) => {
|
|
71
74
|
console.log("GeoJSON:", e.detail.geojson);
|
|
@@ -73,9 +76,21 @@ npm install map-boundary-editor
|
|
|
73
76
|
</script>
|
|
74
77
|
```
|
|
75
78
|
|
|
79
|
+
> All public APIs (`setView`, `setGeoJSON`, `clear`) are safe to call immediately after the element is created. No `setTimeout` or `customElements.whenDefined` is required.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### Setting Initial View
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
editor.setView(lat, lng, zoom);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
If a boundary is later loaded using setGeoJSON, the map will automatically fit to the boundary.
|
|
90
|
+
|
|
76
91
|
---
|
|
77
92
|
|
|
78
|
-
|
|
93
|
+
### Loading an Existing Boundary
|
|
79
94
|
|
|
80
95
|
```js
|
|
81
96
|
editor.setGeoJSON({
|
|
@@ -97,19 +112,102 @@ editor.setGeoJSON({
|
|
|
97
112
|
|
|
98
113
|
---
|
|
99
114
|
|
|
115
|
+
### Optional: Use User Geolocation
|
|
116
|
+
|
|
117
|
+
`map-boundary-editor` supports an optional geolocation-based initial view to help users quickly focus on their current area.
|
|
118
|
+
|
|
119
|
+
This feature is **opt-in** and **disabled by default**.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### Enable Geolocation (Opt-in)
|
|
124
|
+
|
|
125
|
+
```html
|
|
126
|
+
<map-boundary-editor use-geolocation></map-boundary-editor>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
When enabled:
|
|
130
|
+
|
|
131
|
+
- The editor will attempt to center the map on the user’s current location
|
|
132
|
+
- The browser will request permission explicitly
|
|
133
|
+
- If permission is denied or unavailable, the map silently falls back to the default view
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### Behavior & Priority Rules
|
|
138
|
+
|
|
139
|
+
The initial map view follows this priority order:
|
|
140
|
+
|
|
141
|
+
1. `setGeoJSON()`
|
|
142
|
+
|
|
143
|
+
If boundaries are loaded, the map will automatically fit to them.
|
|
144
|
+
|
|
145
|
+
2. `use-geolocation` **attribute**
|
|
146
|
+
|
|
147
|
+
If enabled and permission is granted, the map centers on the user’s location.
|
|
148
|
+
|
|
149
|
+
3. **Default view**
|
|
150
|
+
|
|
151
|
+
Falls back to a neutral world view (`[0, 0]`, zoom `2`).
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### Interaction with setView()
|
|
156
|
+
|
|
157
|
+
If `setView()` is called by the host application, it will override the geolocation-based view.
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
editor.setView(-6.2, 106.8, 11);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
This allows full programmatic control when needed.
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
### Geolocation Toggle Behavior
|
|
168
|
+
|
|
169
|
+
The `use-geolocation` attribute is reactive and can be toggled at runtime.
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
editor.setAttribute("use-geolocation", "");
|
|
173
|
+
editor.removeAttribute("use-geolocation");
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
- Adding the attribute triggers a geolocation request
|
|
177
|
+
- Removing the attribute does not reset the map view automatically
|
|
178
|
+
- Only one geolocation request can be active at a time
|
|
179
|
+
- Browser permission handling is respected (no repeated prompts)
|
|
180
|
+
|
|
181
|
+
Geolocation is treated as a UX helper, not persistent state.
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
### Privacy Notes
|
|
186
|
+
|
|
187
|
+
- Geolocation is never requested automatically
|
|
188
|
+
- Location data is not stored
|
|
189
|
+
- Location data is not transmitted
|
|
190
|
+
- The feature only affects the initial map view
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
100
194
|
## Public API (v0.1)
|
|
101
195
|
|
|
102
|
-
`getGeoJSON():
|
|
196
|
+
`getGeoJSON(): FeatureCollection`
|
|
197
|
+
|
|
198
|
+
Returns the current boundaries as GeoJSON.
|
|
199
|
+
|
|
200
|
+
`setGeoJSON(geojson: FeatureCollection): void`
|
|
103
201
|
|
|
104
|
-
|
|
202
|
+
Loads boundaries from GeoJSON and renders them on the map.
|
|
105
203
|
|
|
106
|
-
`
|
|
204
|
+
`setView(lat: number, lng: number, zoom?: number): void`
|
|
107
205
|
|
|
108
|
-
|
|
206
|
+
Moves the map to the specified location.
|
|
109
207
|
|
|
110
208
|
`clear(): void`
|
|
111
209
|
|
|
112
|
-
Removes
|
|
210
|
+
Removes all boundaries.
|
|
113
211
|
|
|
114
212
|
---
|
|
115
213
|
|
|
@@ -144,7 +242,6 @@ The output is compatible with:
|
|
|
144
242
|
|
|
145
243
|
## Roadmap
|
|
146
244
|
|
|
147
|
-
- v0.2: multiple boundaries (FeatureCollection)
|
|
148
245
|
- v0.3: read-only mode
|
|
149
246
|
- v0.4: additional map engine adapters (MapLibre, Google Maps)
|
|
150
247
|
- v1.0: stable API
|