@versatiles/svelte 0.2.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 +16 -4
- package/dist/components/AutoComplete.svelte +4 -5
- package/dist/components/BBoxMap/BBoxMap.d.ts +1 -12
- package/dist/components/BBoxMap/BBoxMap.js +1 -200
- package/dist/components/BBoxMap/BBoxMap.svelte +19 -92
- package/dist/components/BBoxMap/BBoxMap.svelte.d.ts +2 -5
- package/dist/components/BasicMap/BasicMap.svelte +1 -1
- package/dist/components/LocatorMap/LocatorMap.svelte +34 -0
- package/dist/components/LocatorMap/LocatorMap.svelte.d.ts +19 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/utils/draw/abstract.d.ts +5 -0
- package/dist/utils/draw/abstract.js +2 -0
- package/dist/utils/draw/bbox.d.ts +35 -0
- package/dist/utils/draw/bbox.js +198 -0
- package/dist/utils/draw/marker.d.ts +24 -0
- package/dist/utils/draw/marker.js +97 -0
- package/dist/utils/draw/style.d.ts +19 -0
- package/dist/utils/draw/style.js +40 -0
- package/dist/utils/location.d.ts +2 -1
- package/dist/utils/location.js +19 -10
- package/dist/utils/sprite_library.d.ts +19 -0
- package/dist/utils/sprite_library.js +30 -0
- package/package.json +12 -10
- package/dist/components/BBoxMap/README.md +0 -70
- package/dist/components/BBoxMap/data/countries.jsonl +0 -258
- package/dist/components/BBoxMap/data/eu.jsonl +0 -1876
- package/dist/components/BBoxMap/data/us.jsonl +0 -52
- package/dist/components/BBoxMap/data/world.jsonl +0 -7
- package/dist/components/BBoxMap/helpers/geojson2bboxes.d.ts +0 -2
- package/dist/components/BBoxMap/helpers/geojson2bboxes.js +0 -183
- package/dist/components/BBoxMap/helpers/merge_bboxes.d.ts +0 -2
- package/dist/components/BBoxMap/helpers/merge_bboxes.js +0 -84
- package/dist/components/BBoxMap/helpers/population.raw.br +0 -0
- /package/dist/utils/{style.d.ts → map_style.d.ts} +0 -0
- /package/dist/utils/{style.js → map_style.js} +0 -0
package/README.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
+
[](https://www.npmjs.com/package/@versatiles/svelte)
|
2
|
+
[](https://www.npmjs.com/package/@versatiles/svelte)
|
3
|
+
[](https://codecov.io/gh/versatiles-org/node-versatiles-svelte)
|
4
|
+
[](https://github.com/versatiles-org/node-versatiles-svelte/actions/workflows/ci.yml)
|
5
|
+
|
1
6
|
# Svelte Components for VersaTiles
|
2
7
|
|
8
|
+
Play with them: https://versatiles.org/node-versatiles-svelte/
|
9
|
+
|
3
10
|
## Install
|
4
11
|
|
5
12
|
```bash
|
@@ -16,12 +23,17 @@ npm i @versatiles/svelte
|
|
16
23
|
</tr>
|
17
24
|
<tr>
|
18
25
|
<th>BasicMap</th>
|
19
|
-
<td><img src="
|
20
|
-
<td><img src="
|
26
|
+
<td><img src="./screenshots/basic-map-light.png"></td>
|
27
|
+
<td><img src="./screenshots/basic-map-dark.png"></td>
|
21
28
|
</tr>
|
22
29
|
<tr>
|
23
30
|
<th>BBoxMap</th>
|
24
|
-
<td><img src="
|
25
|
-
<td><img src="
|
31
|
+
<td><img src="./screenshots/bbox-map-light.png"></td>
|
32
|
+
<td><img src="./screenshots/bbox-map-dark.png"></td>
|
33
|
+
</tr>
|
34
|
+
<tr>
|
35
|
+
<th>LocatorMap</th>
|
36
|
+
<td><img src="./screenshots/locator-map-light.png"></td>
|
37
|
+
<td><img src="./screenshots/locator-map-dark.png"></td>
|
26
38
|
</tr>
|
27
39
|
</table>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<!-- AutoComplete.svelte -->
|
2
2
|
<script lang="ts" generics="T">
|
3
|
-
import { isDarkMode } from '../utils/
|
3
|
+
import { isDarkMode } from '../utils/map_style.js';
|
4
4
|
/* eslint svelte/no-at-html-tags: off */
|
5
5
|
|
6
6
|
import { createEventDispatcher, onMount } from 'svelte';
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
// Component properties
|
13
13
|
export let placeholder: string = '';
|
14
|
-
export let minChar: number =
|
14
|
+
export let minChar: number = 3;
|
15
15
|
export let maxItems: number = 10;
|
16
16
|
|
17
17
|
// Reactive variables
|
@@ -32,14 +32,13 @@
|
|
32
32
|
if (r.length > 0) {
|
33
33
|
const { key, value } = r[0];
|
34
34
|
inputText = key;
|
35
|
-
|
35
|
+
dispatch('change', JSON.parse(JSON.stringify(value)));
|
36
36
|
} else {
|
37
37
|
inputText = '';
|
38
38
|
}
|
39
39
|
}
|
40
40
|
|
41
41
|
export function setInputText(text: string) {
|
42
|
-
console.log(text);
|
43
42
|
inputText = text;
|
44
43
|
results = filterResults();
|
45
44
|
close(0);
|
@@ -97,7 +96,7 @@
|
|
97
96
|
// Close the autocomplete and select an item
|
98
97
|
function close(index = -1) {
|
99
98
|
isOpen = false;
|
100
|
-
if (index
|
99
|
+
if (index >= 0 && results[index]) {
|
101
100
|
const { key, value } = results[index];
|
102
101
|
inputText = key;
|
103
102
|
dispatch('change', JSON.parse(JSON.stringify(value)));
|
@@ -1,15 +1,4 @@
|
|
1
|
-
import type { GeoJSON } from 'geojson';
|
2
|
-
import type { LngLat, Point } from 'maplibre-gl';
|
3
|
-
export type BBox = [number, number, number, number];
|
4
|
-
export type BBoxDrag = '0_' | '1_' | '_0' | '_1' | '00' | '01' | '10' | '11' | false;
|
5
|
-
export declare function getBBoxDrag(point: Point, bboxPixel: BBox): BBoxDrag;
|
6
|
-
export declare function dragBBox(bbox: BBox, drag: BBoxDrag, lngLat: LngLat): {
|
7
|
-
bbox: BBox;
|
8
|
-
drag: BBoxDrag;
|
9
|
-
};
|
10
|
-
export declare function getCursor(drag: BBoxDrag): string | false;
|
11
|
-
export declare function getBBoxGeometry(bbox: BBox): GeoJSON;
|
12
1
|
export declare function loadBBoxes(): Promise<{
|
13
2
|
key: string;
|
14
|
-
value:
|
3
|
+
value: [number, number, number, number];
|
15
4
|
}[]>;
|
@@ -1,204 +1,5 @@
|
|
1
|
-
export function getBBoxDrag(point, bboxPixel) {
|
2
|
-
const maxDistance = 5;
|
3
|
-
const { x, y } = point;
|
4
|
-
const [x0, y0, x1, y1] = bboxPixel;
|
5
|
-
// Don't think outside the box
|
6
|
-
if (x < x0 - maxDistance)
|
7
|
-
return false;
|
8
|
-
if (x > x1 + maxDistance)
|
9
|
-
return false;
|
10
|
-
if (y < y0 - maxDistance)
|
11
|
-
return false;
|
12
|
-
if (y > y1 + maxDistance)
|
13
|
-
return false;
|
14
|
-
const drag = [
|
15
|
-
Math.abs(x0 - x) < maxDistance,
|
16
|
-
Math.abs(y0 - y) < maxDistance,
|
17
|
-
Math.abs(x1 - x) < maxDistance,
|
18
|
-
Math.abs(y1 - y) < maxDistance
|
19
|
-
];
|
20
|
-
if (drag[0] && drag[2]) {
|
21
|
-
if (Math.abs(x0 - x) < Math.abs(x1 - x)) {
|
22
|
-
drag[2] = false;
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
drag[0] = false;
|
26
|
-
}
|
27
|
-
}
|
28
|
-
if (drag[1] && drag[3]) {
|
29
|
-
if (Math.abs(y0 - y) < Math.abs(y1 - y)) {
|
30
|
-
drag[3] = false;
|
31
|
-
}
|
32
|
-
else {
|
33
|
-
drag[1] = false;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
if (drag[0]) {
|
37
|
-
if (drag[1])
|
38
|
-
return '01';
|
39
|
-
if (drag[3])
|
40
|
-
return '00';
|
41
|
-
return '0_';
|
42
|
-
}
|
43
|
-
else if (drag[1]) {
|
44
|
-
if (drag[2])
|
45
|
-
return '11';
|
46
|
-
return '_1';
|
47
|
-
}
|
48
|
-
else if (drag[2]) {
|
49
|
-
if (drag[3])
|
50
|
-
return '10';
|
51
|
-
return '1_';
|
52
|
-
}
|
53
|
-
else if (drag[3]) {
|
54
|
-
return '_0';
|
55
|
-
}
|
56
|
-
else
|
57
|
-
return false;
|
58
|
-
}
|
59
|
-
export function dragBBox(bbox, drag, lngLat) {
|
60
|
-
const x = Math.round(lngLat.lng * 1e3) / 1e3;
|
61
|
-
const y = Math.round(lngLat.lat * 1e3) / 1e3;
|
62
|
-
switch (drag) {
|
63
|
-
case '_0':
|
64
|
-
bbox[1] = y;
|
65
|
-
break;
|
66
|
-
case '_1':
|
67
|
-
bbox[3] = y;
|
68
|
-
break;
|
69
|
-
case '0_':
|
70
|
-
bbox[0] = x;
|
71
|
-
break;
|
72
|
-
case '00':
|
73
|
-
bbox[0] = x;
|
74
|
-
bbox[1] = y;
|
75
|
-
break;
|
76
|
-
case '01':
|
77
|
-
bbox[0] = x;
|
78
|
-
bbox[3] = y;
|
79
|
-
break;
|
80
|
-
case '1_':
|
81
|
-
bbox[2] = x;
|
82
|
-
break;
|
83
|
-
case '10':
|
84
|
-
bbox[2] = x;
|
85
|
-
bbox[1] = y;
|
86
|
-
break;
|
87
|
-
case '11':
|
88
|
-
bbox[2] = x;
|
89
|
-
bbox[3] = y;
|
90
|
-
break;
|
91
|
-
}
|
92
|
-
if (bbox[2] < bbox[0]) {
|
93
|
-
// flip horizontal
|
94
|
-
const t = bbox[0];
|
95
|
-
bbox[0] = bbox[2];
|
96
|
-
bbox[2] = t;
|
97
|
-
switch (drag) {
|
98
|
-
case '0_':
|
99
|
-
drag = '1_';
|
100
|
-
break;
|
101
|
-
case '00':
|
102
|
-
drag = '10';
|
103
|
-
break;
|
104
|
-
case '01':
|
105
|
-
drag = '11';
|
106
|
-
break;
|
107
|
-
case '1_':
|
108
|
-
drag = '0_';
|
109
|
-
break;
|
110
|
-
case '10':
|
111
|
-
drag = '00';
|
112
|
-
break;
|
113
|
-
case '11':
|
114
|
-
drag = '01';
|
115
|
-
break;
|
116
|
-
}
|
117
|
-
}
|
118
|
-
if (bbox[3] < bbox[1]) {
|
119
|
-
// flip vertical
|
120
|
-
const t = bbox[1];
|
121
|
-
bbox[1] = bbox[3];
|
122
|
-
bbox[3] = t;
|
123
|
-
switch (drag) {
|
124
|
-
case '_0':
|
125
|
-
drag = '_1';
|
126
|
-
break;
|
127
|
-
case '_1':
|
128
|
-
drag = '_0';
|
129
|
-
break;
|
130
|
-
case '00':
|
131
|
-
drag = '01';
|
132
|
-
break;
|
133
|
-
case '01':
|
134
|
-
drag = '00';
|
135
|
-
break;
|
136
|
-
case '10':
|
137
|
-
drag = '11';
|
138
|
-
break;
|
139
|
-
case '11':
|
140
|
-
drag = '10';
|
141
|
-
break;
|
142
|
-
}
|
143
|
-
}
|
144
|
-
return { drag, bbox };
|
145
|
-
}
|
146
|
-
export function getCursor(drag) {
|
147
|
-
switch (drag) {
|
148
|
-
case '_0':
|
149
|
-
return 'ns-resize';
|
150
|
-
case '_1':
|
151
|
-
return 'ns-resize';
|
152
|
-
case '0_':
|
153
|
-
return 'ew-resize';
|
154
|
-
case '00':
|
155
|
-
return 'nesw-resize';
|
156
|
-
case '01':
|
157
|
-
return 'nwse-resize';
|
158
|
-
case '1_':
|
159
|
-
return 'ew-resize';
|
160
|
-
case '10':
|
161
|
-
return 'nwse-resize';
|
162
|
-
case '11':
|
163
|
-
return 'nesw-resize';
|
164
|
-
}
|
165
|
-
return false;
|
166
|
-
}
|
167
|
-
export function getBBoxGeometry(bbox) {
|
168
|
-
return {
|
169
|
-
type: 'FeatureCollection',
|
170
|
-
features: [polygon(getRing([-180, -86, 180, 86]), getRing(bbox)), linestring(getRing(bbox))]
|
171
|
-
};
|
172
|
-
function polygon(...coordinates) {
|
173
|
-
return {
|
174
|
-
type: 'Feature',
|
175
|
-
geometry: { type: 'Polygon', coordinates },
|
176
|
-
properties: {}
|
177
|
-
};
|
178
|
-
}
|
179
|
-
function linestring(coordinates) {
|
180
|
-
return {
|
181
|
-
type: 'Feature',
|
182
|
-
geometry: { type: 'LineString', coordinates },
|
183
|
-
properties: {}
|
184
|
-
};
|
185
|
-
}
|
186
|
-
function getRing(bbox) {
|
187
|
-
const x0 = Math.min(bbox[0], bbox[2]);
|
188
|
-
const x1 = Math.max(bbox[0], bbox[2]);
|
189
|
-
const y0 = Math.min(bbox[1], bbox[3]);
|
190
|
-
const y1 = Math.max(bbox[1], bbox[3]);
|
191
|
-
return [
|
192
|
-
[x0, y0],
|
193
|
-
[x1, y0],
|
194
|
-
[x1, y1],
|
195
|
-
[x0, y1],
|
196
|
-
[x0, y0]
|
197
|
-
];
|
198
|
-
}
|
199
|
-
}
|
200
1
|
export async function loadBBoxes() {
|
201
|
-
const data = await import('
|
2
|
+
const data = await import('../../components/BBoxMap/bboxes.json');
|
202
3
|
const bboxes = data.default.map((e) => {
|
203
4
|
const key = e[0];
|
204
5
|
const value = e.slice(1, 5);
|
@@ -1,116 +1,39 @@
|
|
1
1
|
<!-- BBoxMap.svelte -->
|
2
2
|
<script lang="ts">
|
3
|
-
import type { CameraOptions,
|
4
|
-
import type { BBox, BBoxDrag } from './BBoxMap.js';
|
5
|
-
import { onMount } from 'svelte';
|
3
|
+
import type { CameraOptions, Map as MaplibreMapType } from 'maplibre-gl';
|
6
4
|
import 'maplibre-gl/dist/maplibre-gl.css';
|
7
|
-
import { dragBBox, getBBoxDrag, loadBBoxes, getBBoxGeometry, getCursor } from './BBoxMap.js';
|
8
5
|
import AutoComplete from '../AutoComplete.svelte';
|
9
|
-
import {
|
6
|
+
import { getCountryName } from '../../utils/location.js';
|
10
7
|
import BasicMap from '../BasicMap/BasicMap.svelte';
|
11
|
-
import { isDarkMode } from '../../utils/
|
8
|
+
import { isDarkMode } from '../../utils/map_style.js';
|
9
|
+
import type { BBox } from 'geojson';
|
10
|
+
import { loadBBoxes } from './BBoxMap.js';
|
11
|
+
import { BBoxDrawer } from '../../utils/draw/bbox.js';
|
12
12
|
|
13
13
|
let bboxes: { key: string; value: BBox }[] | undefined = undefined;
|
14
14
|
let mapContainer: HTMLDivElement;
|
15
15
|
let autoComplete: AutoComplete<BBox> | undefined = undefined;
|
16
|
-
const worldBBox: BBox = [-180, -85, 180, 85];
|
17
16
|
const startTime = Date.now();
|
18
|
-
|
17
|
+
let bbox: BBoxDrawer;
|
19
18
|
let map: MaplibreMapType; // Declare map instance at the top level
|
20
19
|
|
21
|
-
onMount(async () => {
|
22
|
-
bboxes = await loadBBoxes();
|
23
|
-
start();
|
24
|
-
});
|
25
|
-
|
26
20
|
function handleMapReady(event: CustomEvent) {
|
27
21
|
map = event.detail.map;
|
28
22
|
map.setPadding({ top: 31 + 5, right: 5, bottom: 5, left: 5 });
|
29
23
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
map.on('load', () => {
|
34
|
-
map.addSource('bbox', { type: 'geojson', data: getBBoxGeometry(selectedBBox) });
|
35
|
-
map.addLayer({
|
36
|
-
id: 'bbox-line',
|
37
|
-
type: 'line',
|
38
|
-
source: 'bbox',
|
39
|
-
filter: ['==', '$type', 'LineString'],
|
40
|
-
layout: { 'line-cap': 'round', 'line-join': 'round' },
|
41
|
-
paint: { 'line-color': bboxColor, 'line-width': 0.5 }
|
42
|
-
});
|
43
|
-
map.addLayer({
|
44
|
-
id: 'bbox-fill',
|
45
|
-
type: 'fill',
|
46
|
-
source: 'bbox',
|
47
|
-
filter: ['==', '$type', 'Polygon'],
|
48
|
-
paint: { 'fill-color': bboxColor, 'fill-opacity': 0.2 }
|
24
|
+
map.on('load', async () => {
|
25
|
+
bbox = new BBoxDrawer(map, {
|
26
|
+
color: isDarkMode(mapContainer) ? '#FFFFFF' : '#000000'
|
49
27
|
});
|
28
|
+
bboxes = await loadBBoxes();
|
50
29
|
});
|
51
|
-
|
52
|
-
function getDrag(point: Point): BBoxDrag {
|
53
|
-
const { x: x0, y: y1 } = map.project([selectedBBox[0], selectedBBox[1]]);
|
54
|
-
const { x: x1, y: y0 } = map.project([selectedBBox[2], selectedBBox[3]]);
|
55
|
-
return getBBoxDrag(point, [x0, y0, x1, y1]);
|
56
|
-
}
|
57
|
-
|
58
|
-
let lastDrag: BBoxDrag = false;
|
59
|
-
let dragging = false;
|
60
|
-
map.on('mousemove', (e) => {
|
61
|
-
if (dragging) {
|
62
|
-
if (e.originalEvent.buttons % 2) {
|
63
|
-
const { drag, bbox } = dragBBox(selectedBBox, lastDrag, e.lngLat);
|
64
|
-
lastDrag = drag;
|
65
|
-
selectedBBox = bbox;
|
66
|
-
redrawBBox();
|
67
|
-
e.preventDefault();
|
68
|
-
} else {
|
69
|
-
dragging = false;
|
70
|
-
}
|
71
|
-
} else {
|
72
|
-
const drag = getDrag(e.point);
|
73
|
-
if (drag !== lastDrag) {
|
74
|
-
lastDrag = drag;
|
75
|
-
canvas.style.cursor = getCursor(drag) || 'grab';
|
76
|
-
}
|
77
|
-
}
|
78
|
-
});
|
79
|
-
|
80
|
-
map.on('mousedown', (e) => {
|
81
|
-
if (e.originalEvent.buttons % 2) {
|
82
|
-
const drag = getDrag(e.point);
|
83
|
-
lastDrag = drag;
|
84
|
-
if (drag) {
|
85
|
-
dragging = true;
|
86
|
-
e.preventDefault();
|
87
|
-
}
|
88
|
-
}
|
89
|
-
});
|
90
|
-
|
91
|
-
map.on('mouseup', () => (dragging = false));
|
92
|
-
|
93
|
-
start();
|
94
|
-
}
|
95
|
-
|
96
|
-
function start() {
|
97
|
-
if (!bboxes) return;
|
98
|
-
if (!map) return;
|
99
|
-
if (!autoComplete) return;
|
100
|
-
autoComplete.setInputText(getCountry()); // Initial search text
|
101
|
-
}
|
102
|
-
|
103
|
-
function redrawBBox() {
|
104
|
-
const bboxSource = map.getSource('bbox') as GeoJSONSource;
|
105
|
-
bboxSource.setData(getBBoxGeometry(selectedBBox));
|
106
30
|
}
|
107
31
|
|
108
|
-
function flyTo(
|
109
|
-
|
110
|
-
|
111
|
-
if (map.getSource('bbox')) redrawBBox();
|
32
|
+
function flyTo(newBBox: BBox) {
|
33
|
+
if (bbox) {
|
34
|
+
bbox.setGeometry(newBBox);
|
112
35
|
|
113
|
-
const transform = map.cameraForBounds(
|
36
|
+
const transform = map.cameraForBounds(bbox.getBounds()) as CameraOptions;
|
114
37
|
if (transform == null) return;
|
115
38
|
transform.zoom = transform.zoom ?? 0 - 0.5;
|
116
39
|
transform.bearing = 0;
|
@@ -123,6 +46,10 @@
|
|
123
46
|
}
|
124
47
|
}
|
125
48
|
}
|
49
|
+
|
50
|
+
$: if (autoComplete) {
|
51
|
+
autoComplete?.setInputText(getCountryName() ?? '');
|
52
|
+
}
|
126
53
|
</script>
|
127
54
|
|
128
55
|
<div class="container">
|
@@ -1,10 +1,9 @@
|
|
1
|
-
import type { BBox } from './BBoxMap.js';
|
2
1
|
import 'maplibre-gl/dist/maplibre-gl.css';
|
3
2
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
4
3
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
5
4
|
$$bindings?: Bindings;
|
6
5
|
} & Exports;
|
7
|
-
(internal: unknown, props:
|
6
|
+
(internal: unknown, props: {
|
8
7
|
$$events?: Events;
|
9
8
|
$$slots?: Slots;
|
10
9
|
}): Exports & {
|
@@ -13,9 +12,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
13
12
|
};
|
14
13
|
z_$$bindings?: Bindings;
|
15
14
|
}
|
16
|
-
declare const BBoxMap: $$__sveltets_2_IsomorphicComponent<{
|
17
|
-
selectedBBox?: BBox;
|
18
|
-
}, {
|
15
|
+
declare const BBoxMap: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
19
16
|
[evt: string]: CustomEvent<any>;
|
20
17
|
}, {}, {}, string>;
|
21
18
|
type BBoxMap = InstanceType<typeof BBoxMap>;
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import type { Map as MaplibreMapType, MapOptions } from 'maplibre-gl';
|
4
4
|
import { onMount, createEventDispatcher } from 'svelte';
|
5
5
|
import 'maplibre-gl/dist/maplibre-gl.css';
|
6
|
-
import { getMapStyle, isDarkMode } from '../../utils/
|
6
|
+
import { getMapStyle, isDarkMode } from '../../utils/map_style.js';
|
7
7
|
import type { StyleBuilderOptions } from '@versatiles/style';
|
8
8
|
|
9
9
|
// Props
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<!-- LocatorMap.svelte -->
|
2
|
+
<script lang="ts">
|
3
|
+
import type { Map as MaplibreMapType } from 'maplibre-gl';
|
4
|
+
import 'maplibre-gl/dist/maplibre-gl.css';
|
5
|
+
import BasicMap from '../BasicMap/BasicMap.svelte';
|
6
|
+
//import SpriteLibrary from '../../utils/sprite_library.js';
|
7
|
+
import { MarkerDrawer } from '../../utils/draw/marker.js';
|
8
|
+
|
9
|
+
let mapContainer: HTMLDivElement;
|
10
|
+
let map: MaplibreMapType;
|
11
|
+
//let spriteLibrary = new SpriteLibrary();
|
12
|
+
let markers = [];
|
13
|
+
|
14
|
+
function handleMapReady(event: CustomEvent) {
|
15
|
+
map = event.detail.map;
|
16
|
+
map.on('load', async () => {
|
17
|
+
//const list = await spriteLibrary.getSpriteList();
|
18
|
+
markers.push(new MarkerDrawer(map, { point: [25, 22] }));
|
19
|
+
});
|
20
|
+
}
|
21
|
+
</script>
|
22
|
+
|
23
|
+
<div class="container">
|
24
|
+
<BasicMap {map} bind:container={mapContainer} on:mapReady={handleMapReady}></BasicMap>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<style>
|
28
|
+
.container {
|
29
|
+
width: 100%;
|
30
|
+
height: 100%;
|
31
|
+
position: relative;
|
32
|
+
min-height: 6em;
|
33
|
+
}
|
34
|
+
</style>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import 'maplibre-gl/dist/maplibre-gl.css';
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
4
|
+
$$bindings?: Bindings;
|
5
|
+
} & Exports;
|
6
|
+
(internal: unknown, props: {
|
7
|
+
$$events?: Events;
|
8
|
+
$$slots?: Slots;
|
9
|
+
}): Exports & {
|
10
|
+
$set?: any;
|
11
|
+
$on?: any;
|
12
|
+
};
|
13
|
+
z_$$bindings?: Bindings;
|
14
|
+
}
|
15
|
+
declare const LocatorMap: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
16
|
+
[evt: string]: CustomEvent<any>;
|
17
|
+
}, {}, {}, string>;
|
18
|
+
type LocatorMap = InstanceType<typeof LocatorMap>;
|
19
|
+
export default LocatorMap;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
import type geojson from 'geojson';
|
2
|
+
import type { FillStyle, LineStyle } from './style.js';
|
3
|
+
import { AbstractDrawer } from './abstract.js';
|
4
|
+
type DragPoint = 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw' | false;
|
5
|
+
export declare const DragPointMap: Map<DragPoint, {
|
6
|
+
cursor: string;
|
7
|
+
flipH: DragPoint;
|
8
|
+
flipV: DragPoint;
|
9
|
+
}>;
|
10
|
+
export type BBox = [number, number, number, number];
|
11
|
+
export declare class BBoxDrawer extends AbstractDrawer<geojson.BBox> {
|
12
|
+
private source?;
|
13
|
+
private dragPoint;
|
14
|
+
private isDragging;
|
15
|
+
private map;
|
16
|
+
private canvas;
|
17
|
+
private fillStyle;
|
18
|
+
private lineStyle;
|
19
|
+
private inverted;
|
20
|
+
private bbox;
|
21
|
+
constructor(map: maplibregl.Map, options?: {
|
22
|
+
bbox?: BBox;
|
23
|
+
inverted?: boolean;
|
24
|
+
} & LineStyle & FillStyle);
|
25
|
+
private updateDragPoint;
|
26
|
+
private getAsFeatureCollection;
|
27
|
+
setGeometry(bbox: geojson.BBox): void;
|
28
|
+
getBounds(): maplibregl.LngLatBounds;
|
29
|
+
private redraw;
|
30
|
+
private getAsPixel;
|
31
|
+
private checkDragPointAt;
|
32
|
+
private getCursor;
|
33
|
+
private doDrag;
|
34
|
+
}
|
35
|
+
export {};
|