@versatiles/svelte 1.0.0 → 1.0.2
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/dist/components/BBoxMap/AutoComplete.svelte +116 -89
- package/dist/components/BBoxMap/BBoxMap.svelte +52 -42
- package/dist/components/BBoxMap/BBoxMap.svelte.d.ts +5 -3
- package/dist/components/BasicMap/BasicMap.svelte +59 -34
- package/dist/components/LocatorMap/LocatorMap.svelte +67 -60
- package/dist/components/MapEditor/MapEditor.svelte +35 -80
- package/dist/components/MapEditor/components/Editor.svelte +53 -0
- package/dist/components/MapEditor/{Editor.svelte.d.ts → components/Editor.svelte.d.ts} +1 -1
- package/dist/components/MapEditor/components/EditorFill.svelte +28 -0
- package/dist/components/MapEditor/components/EditorFill.svelte.d.ts +7 -0
- package/dist/components/MapEditor/components/EditorStroke.svelte +28 -0
- package/dist/components/MapEditor/components/EditorStroke.svelte.d.ts +7 -0
- package/dist/components/MapEditor/components/EditorSymbol.svelte +43 -0
- package/dist/components/MapEditor/components/EditorSymbol.svelte.d.ts +7 -0
- package/dist/components/MapEditor/components/Sidebar.svelte +179 -0
- package/dist/components/MapEditor/components/Sidebar.svelte.d.ts +8 -0
- package/dist/components/MapEditor/components/SymbolSelector.svelte +118 -0
- package/dist/components/MapEditor/components/SymbolSelector.svelte.d.ts +8 -0
- package/dist/components/MapEditor/lib/__mocks__/cursor.d.ts +5 -0
- package/dist/components/MapEditor/lib/__mocks__/cursor.js +6 -0
- package/dist/components/MapEditor/lib/__mocks__/geometry_manager.d.ts +22 -0
- package/dist/components/MapEditor/lib/__mocks__/geometry_manager.js +21 -0
- package/dist/components/MapEditor/lib/__mocks__/map.d.ts +36 -0
- package/dist/components/MapEditor/lib/__mocks__/map.js +26 -0
- package/dist/components/MapEditor/lib/cursor.d.ts +9 -0
- package/dist/components/MapEditor/lib/cursor.js +31 -0
- package/dist/components/MapEditor/lib/element/abstract.d.ts +21 -0
- package/dist/components/MapEditor/lib/element/abstract.js +39 -0
- package/dist/components/MapEditor/lib/element/abstract_path.d.ts +11 -0
- package/dist/components/MapEditor/lib/element/abstract_path.js +79 -0
- package/dist/components/MapEditor/lib/element/line.d.ts +16 -0
- package/dist/components/MapEditor/lib/element/line.js +53 -0
- package/dist/components/MapEditor/lib/element/marker.d.ts +18 -0
- package/dist/components/MapEditor/lib/element/marker.js +62 -0
- package/dist/components/MapEditor/lib/element/polygon.d.ts +17 -0
- package/dist/components/MapEditor/lib/element/polygon.js +63 -0
- package/dist/components/MapEditor/lib/element/types.d.ts +11 -0
- package/dist/components/MapEditor/lib/geometry_manager.d.ts +20 -10
- package/dist/components/MapEditor/lib/geometry_manager.js +158 -57
- package/dist/components/MapEditor/lib/map_layer/abstract.d.ts +30 -0
- package/dist/components/MapEditor/lib/map_layer/abstract.js +90 -0
- package/dist/components/MapEditor/lib/map_layer/fill.d.ts +24 -0
- package/dist/components/MapEditor/lib/map_layer/fill.js +104 -0
- package/dist/components/MapEditor/lib/map_layer/line.d.ts +20 -0
- package/dist/components/MapEditor/lib/map_layer/line.js +90 -0
- package/dist/components/MapEditor/lib/map_layer/symbol.d.ts +19 -0
- package/dist/components/MapEditor/lib/map_layer/symbol.js +123 -0
- package/dist/components/MapEditor/lib/{types.d.ts → map_layer/types.d.ts} +7 -15
- package/dist/components/MapEditor/lib/map_layer/types.js +1 -0
- package/dist/components/MapEditor/lib/state/reader.d.ts +17 -0
- package/dist/components/MapEditor/lib/state/reader.js +161 -0
- package/dist/components/MapEditor/lib/state/types.d.ts +20 -0
- package/dist/components/MapEditor/lib/state/types.js +1 -0
- package/dist/components/MapEditor/lib/state/writer.d.ts +17 -0
- package/dist/components/MapEditor/lib/state/writer.js +178 -0
- package/dist/components/MapEditor/lib/symbols.d.ts +16 -0
- package/dist/components/MapEditor/lib/symbols.js +173 -0
- package/dist/components/MapEditor/lib/utils.d.ts +8 -1
- package/dist/components/MapEditor/lib/utils.js +33 -2
- package/dist/utils/draw/bbox.d.ts +3 -1
- package/dist/utils/draw/bbox.js +56 -51
- package/package.json +16 -16
- package/dist/components/MapEditor/Editor.svelte +0 -25
- package/dist/components/MapEditor/EditorLine.svelte +0 -27
- package/dist/components/MapEditor/EditorLine.svelte.d.ts +0 -7
- package/dist/components/MapEditor/EditorMarker.svelte +0 -42
- package/dist/components/MapEditor/EditorMarker.svelte.d.ts +0 -7
- package/dist/components/MapEditor/editor.scss +0 -16
- package/dist/components/MapEditor/lib/element_abstract.d.ts +0 -20
- package/dist/components/MapEditor/lib/element_abstract.js +0 -58
- package/dist/components/MapEditor/lib/element_line.d.ts +0 -14
- package/dist/components/MapEditor/lib/element_line.js +0 -76
- package/dist/components/MapEditor/lib/element_marker.d.ts +0 -20
- package/dist/components/MapEditor/lib/element_marker.js +0 -191
- package/dist/components/MapEditor/lib/map_layer.d.ts +0 -14
- package/dist/components/MapEditor/lib/map_layer.js +0 -61
- package/dist/utils/sprite_library.d.ts +0 -19
- package/dist/utils/sprite_library.js +0 -30
- /package/dist/components/MapEditor/lib/{types.js → element/types.js} +0 -0
@@ -1,58 +0,0 @@
|
|
1
|
-
import { MapLayer } from './map_layer.js';
|
2
|
-
export class AbstractElement {
|
3
|
-
name;
|
4
|
-
canvas;
|
5
|
-
manager;
|
6
|
-
map;
|
7
|
-
layer;
|
8
|
-
source;
|
9
|
-
isActive = true;
|
10
|
-
slug = '_' + Math.random().toString(36).slice(2);
|
11
|
-
constructor(manager, name, type) {
|
12
|
-
this.manager = manager;
|
13
|
-
this.map = manager.map;
|
14
|
-
this.canvas = this.map.getCanvasContainer();
|
15
|
-
this.name = name;
|
16
|
-
this.map.addSource('source' + this.slug, {
|
17
|
-
type: 'geojson',
|
18
|
-
data: { type: 'FeatureCollection', features: [] }
|
19
|
-
});
|
20
|
-
this.source = this.map.getSource('source' + this.slug);
|
21
|
-
this.layer = new MapLayer(this.map, type + this.slug, 'source' + this.slug, type);
|
22
|
-
this.map.on('mouseenter', this.layer.id, () => {
|
23
|
-
if (this.isActive)
|
24
|
-
this.canvas.style.cursor = 'pointer';
|
25
|
-
});
|
26
|
-
this.map.on('mouseleave', this.layer.id, () => {
|
27
|
-
if (this.isActive)
|
28
|
-
this.canvas.style.cursor = 'default';
|
29
|
-
});
|
30
|
-
this.map.on('click', this.layer.id, (e) => {
|
31
|
-
if (this.isActive) {
|
32
|
-
this.manager.setActiveElement(this);
|
33
|
-
e.preventDefault();
|
34
|
-
}
|
35
|
-
});
|
36
|
-
}
|
37
|
-
randomPositions(name, length) {
|
38
|
-
let seed = name
|
39
|
-
.split('')
|
40
|
-
.reduce((acc, char) => (acc * 0x101 + char.charCodeAt(0)) % 0x100000000, 0);
|
41
|
-
const points = [];
|
42
|
-
for (let i = 0; i < length; i++) {
|
43
|
-
const xr = random() * 0.5 + 0.25;
|
44
|
-
const yr = random() * 0.5 + 0.25;
|
45
|
-
const bounds = this.map.getBounds();
|
46
|
-
points.push([
|
47
|
-
(1 - xr) * bounds.getWest() + xr * bounds.getEast(),
|
48
|
-
(1 - yr) * bounds.getSouth() + yr * bounds.getNorth()
|
49
|
-
]);
|
50
|
-
}
|
51
|
-
return points;
|
52
|
-
function random() {
|
53
|
-
for (let i = 0; i < 10; i++)
|
54
|
-
seed = ((Math.cos(seed * 3.14 + 0.0159) + 1.1) * 9631) % 1;
|
55
|
-
return seed;
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { AbstractElement } from './element_abstract.js';
|
2
|
-
import type { GeometryManager } from './geometry_manager.js';
|
3
|
-
import type { ElementLine, LayerLine, SelectionNode } from './types.js';
|
4
|
-
export declare const dashArrays: Map<string, number[] | undefined>;
|
5
|
-
export declare class LineElement extends AbstractElement<LayerLine> {
|
6
|
-
readonly color: import("svelte/store").Writable<string>;
|
7
|
-
readonly dashed: import("svelte/store").Writable<string>;
|
8
|
-
readonly width: import("svelte/store").Writable<number>;
|
9
|
-
private line;
|
10
|
-
constructor(manager: GeometryManager, name: string, line?: ElementLine);
|
11
|
-
getFeature(): GeoJSON.Feature<GeoJSON.LineString>;
|
12
|
-
getSelectionNodes(): SelectionNode[];
|
13
|
-
getSelectionNodeUpdater(properties?: Record<string, unknown>): ((lng: number, lat: number) => void) | undefined;
|
14
|
-
}
|
@@ -1,76 +0,0 @@
|
|
1
|
-
import { Color } from '@versatiles/style';
|
2
|
-
import { AbstractElement } from './element_abstract.js';
|
3
|
-
import { get, writable } from 'svelte/store';
|
4
|
-
import { getMiddlePoint } from './utils.js';
|
5
|
-
export const dashArrays = new Map([
|
6
|
-
['solid', undefined],
|
7
|
-
['dashed', [2, 4]],
|
8
|
-
['dotted', [0, 2]]
|
9
|
-
]);
|
10
|
-
export class LineElement extends AbstractElement {
|
11
|
-
color = writable('#ff0000');
|
12
|
-
dashed = writable('solid');
|
13
|
-
width = writable(2);
|
14
|
-
line = [
|
15
|
-
[0, 0],
|
16
|
-
[0, 0]
|
17
|
-
];
|
18
|
-
constructor(manager, name, line) {
|
19
|
-
super(manager, name, 'line');
|
20
|
-
this.line = line ?? this.randomPositions(name, 2);
|
21
|
-
const getDashArray = () => dashArrays.get(get(this.dashed));
|
22
|
-
this.layer.setLayout({
|
23
|
-
'line-cap': 'round',
|
24
|
-
'line-join': 'round'
|
25
|
-
});
|
26
|
-
this.layer.setPaint({
|
27
|
-
'line-color': Color.parse(get(this.color)).asString(),
|
28
|
-
'line-dasharray': getDashArray(),
|
29
|
-
'line-width': get(this.width)
|
30
|
-
});
|
31
|
-
this.color.subscribe((value) => this.layer.updatePaint('line-color', Color.parse(value)));
|
32
|
-
this.width.subscribe((value) => this.layer.updatePaint('line-width', value));
|
33
|
-
this.dashed.subscribe(() => this.layer.updatePaint('line-dasharray', getDashArray()));
|
34
|
-
this.source.setData(this.getFeature());
|
35
|
-
}
|
36
|
-
getFeature() {
|
37
|
-
return {
|
38
|
-
type: 'Feature',
|
39
|
-
properties: {},
|
40
|
-
geometry: { type: 'LineString', coordinates: this.line }
|
41
|
-
};
|
42
|
-
}
|
43
|
-
getSelectionNodes() {
|
44
|
-
const points = [];
|
45
|
-
for (let i = 0; i < this.line.length; i++) {
|
46
|
-
points.push({ index: i, coordinates: this.line[i] });
|
47
|
-
if (i === this.line.length - 1)
|
48
|
-
continue;
|
49
|
-
points.push({
|
50
|
-
index: i + 0.5,
|
51
|
-
transparent: true,
|
52
|
-
coordinates: getMiddlePoint(this.line[i], this.line[i + 1])
|
53
|
-
});
|
54
|
-
}
|
55
|
-
return points;
|
56
|
-
}
|
57
|
-
getSelectionNodeUpdater(properties) {
|
58
|
-
if (properties == undefined)
|
59
|
-
return;
|
60
|
-
const index = properties.index;
|
61
|
-
let point;
|
62
|
-
if (index % 1 === 0) {
|
63
|
-
point = this.line[index];
|
64
|
-
}
|
65
|
-
else {
|
66
|
-
const i = Math.ceil(index);
|
67
|
-
this.line.splice(i, 0, [0, 0]);
|
68
|
-
point = this.line[i];
|
69
|
-
}
|
70
|
-
return (lng, lat) => {
|
71
|
-
point[0] = lng;
|
72
|
-
point[1] = lat;
|
73
|
-
this.source.setData(this.getFeature());
|
74
|
-
};
|
75
|
-
}
|
76
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { AbstractElement } from './element_abstract.js';
|
2
|
-
import type { GeometryManager } from './geometry_manager.js';
|
3
|
-
import type { ElementPoint, LayerSymbol, SelectionNode } from './types.js';
|
4
|
-
export declare const symbols: Map<string, {
|
5
|
-
image: string;
|
6
|
-
offset?: [number, number];
|
7
|
-
}>;
|
8
|
-
export declare class MarkerElement extends AbstractElement<LayerSymbol> {
|
9
|
-
readonly color: import("svelte/store").Writable<string>;
|
10
|
-
readonly halo: import("svelte/store").Writable<number>;
|
11
|
-
readonly rotate: import("svelte/store").Writable<number>;
|
12
|
-
readonly size: import("svelte/store").Writable<number>;
|
13
|
-
readonly symbol: import("svelte/store").Writable<string>;
|
14
|
-
readonly label: import("svelte/store").Writable<string>;
|
15
|
-
private point;
|
16
|
-
constructor(manager: GeometryManager, name: string, point?: ElementPoint);
|
17
|
-
getFeature(): GeoJSON.Feature<GeoJSON.Point>;
|
18
|
-
getSelectionNodes(): SelectionNode[];
|
19
|
-
getSelectionNodeUpdater(): ((lng: number, lat: number) => void) | undefined;
|
20
|
-
}
|
@@ -1,191 +0,0 @@
|
|
1
|
-
import { Color } from '@versatiles/style';
|
2
|
-
import { AbstractElement } from './element_abstract.js';
|
3
|
-
import { get, writable } from 'svelte/store';
|
4
|
-
export const symbols = new Map([
|
5
|
-
['airplane', { image: 'basics:icon-airfield' }],
|
6
|
-
['airport', { image: 'basics:icon-airport' }],
|
7
|
-
['alcohol shop', { image: 'basics:icon-alcohol_shop' }],
|
8
|
-
['art gallery', { image: 'basics:icon-art_gallery' }],
|
9
|
-
['artwork', { image: 'basics:icon-artwork' }],
|
10
|
-
['atm', { image: 'basics:icon-atm' }],
|
11
|
-
['bakery', { image: 'basics:icon-bakery' }],
|
12
|
-
['bank', { image: 'basics:icon-bank' }],
|
13
|
-
['beauty', { image: 'basics:icon-beauty' }],
|
14
|
-
['beer', { image: 'basics:icon-beer' }],
|
15
|
-
['beergarden', { image: 'basics:icon-beergarden' }],
|
16
|
-
['bench', { image: 'basics:icon-bench' }],
|
17
|
-
['beverages', { image: 'basics:icon-beverages' }],
|
18
|
-
['bicycle share', { image: 'basics:icon-bicycle_share' }],
|
19
|
-
['books', { image: 'basics:icon-books' }],
|
20
|
-
['bus', { image: 'basics:icon-bus' }],
|
21
|
-
['butcher', { image: 'basics:icon-butcher' }],
|
22
|
-
['cafe', { image: 'basics:icon-cafe', offset: [2, 0] }],
|
23
|
-
['car rental', { image: 'basics:icon-car_rental' }],
|
24
|
-
['car wash', { image: 'basics:icon-car_wash' }],
|
25
|
-
['castle', { image: 'basics:icon-castle' }],
|
26
|
-
['cemetery', { image: 'basics:icon-cemetery' }],
|
27
|
-
['chalet', { image: 'basics:icon-chalet' }],
|
28
|
-
['chemist', { image: 'basics:icon-chemist' }],
|
29
|
-
['cinema', { image: 'basics:icon-cinema' }],
|
30
|
-
['clothes', { image: 'basics:icon-clothes' }],
|
31
|
-
['college', { image: 'basics:icon-college' }],
|
32
|
-
['community', { image: 'basics:icon-community' }],
|
33
|
-
['defibrillator', { image: 'basics:icon-defibrillator' }],
|
34
|
-
['doctor', { image: 'basics:icon-doctor' }],
|
35
|
-
['dog park', { image: 'basics:icon-dog_park' }],
|
36
|
-
['doityourself', { image: 'basics:icon-doityourself' }],
|
37
|
-
['drinking water', { image: 'basics:icon-drinking_water' }],
|
38
|
-
['drycleaning', { image: 'basics:icon-drycleaning' }],
|
39
|
-
['emergency phone', { image: 'basics:icon-emergency_phone' }],
|
40
|
-
['fast food', { image: 'basics:icon-fast_food' }],
|
41
|
-
['fire station', { image: 'basics:icon-fire_station' }],
|
42
|
-
['flag', { image: 'basics:icon-embassy', offset: [7.5, -10] }],
|
43
|
-
['florist', { image: 'basics:icon-florist' }],
|
44
|
-
['fountain', { image: 'basics:icon-fountain' }],
|
45
|
-
['furniture', { image: 'basics:icon-furniture' }],
|
46
|
-
['garden centre', { image: 'basics:icon-garden_centre' }],
|
47
|
-
['gift', { image: 'basics:icon-gift' }],
|
48
|
-
['glasses', { image: 'basics:icon-optician' }],
|
49
|
-
['golf', { image: 'basics:icon-golf' }],
|
50
|
-
['greengrocer', { image: 'basics:icon-greengrocer' }],
|
51
|
-
['hardware', { image: 'basics:icon-hardware' }],
|
52
|
-
['hospital', { image: 'basics:icon-hospital' }],
|
53
|
-
['huntingstand', { image: 'basics:icon-huntingstand' }],
|
54
|
-
['hydrant', { image: 'basics:icon-hydrant' }],
|
55
|
-
['icerink', { image: 'basics:icon-icerink' }],
|
56
|
-
['information', { image: 'basics:transport-information' }],
|
57
|
-
['jewelry store', { image: 'basics:icon-jewelry_store' }],
|
58
|
-
['kiosk', { image: 'basics:icon-kiosk' }],
|
59
|
-
['laundry', { image: 'basics:icon-laundry' }],
|
60
|
-
['letter', { image: 'basics:icon-post' }],
|
61
|
-
['library', { image: 'basics:icon-library' }],
|
62
|
-
['lighthouse', { image: 'basics:icon-lighthouse' }],
|
63
|
-
['marketplace', { image: 'basics:icon-marketplace' }],
|
64
|
-
['money', { image: 'basics:icon-bar' }],
|
65
|
-
['monument', { image: 'basics:icon-monument' }],
|
66
|
-
['newsagent', { image: 'basics:icon-newsagent' }],
|
67
|
-
['nightclub', { image: 'basics:icon-nightclub' }],
|
68
|
-
['nursinghome', { image: 'basics:icon-nursinghome' }],
|
69
|
-
['observation tower', { image: 'basics:icon-observation_tower' }],
|
70
|
-
['outdoor', { image: 'basics:icon-outdoor' }],
|
71
|
-
['pharmacy', { image: 'basics:icon-pharmacy' }],
|
72
|
-
['picnic site', { image: 'basics:icon-picnic_site' }],
|
73
|
-
['place of worship', { image: 'basics:icon-place_of_worship' }],
|
74
|
-
['playground', { image: 'basics:icon-playground' }],
|
75
|
-
['police', { image: 'basics:icon-police', offset: [-1, -3] }],
|
76
|
-
['postbox', { image: 'basics:icon-postbox' }],
|
77
|
-
['prison', { image: 'basics:icon-prison' }],
|
78
|
-
['rail light', { image: 'basics:icon-rail_light' }],
|
79
|
-
['rail metro', { image: 'basics:icon-rail_metro' }],
|
80
|
-
['rail', { image: 'basics:icon-rail' }],
|
81
|
-
['recycling', { image: 'basics:icon-recycling' }],
|
82
|
-
['restaurant', { image: 'basics:icon-restaurant' }],
|
83
|
-
['run', { image: 'basics:icon-pitch' }],
|
84
|
-
['school', { image: 'basics:icon-school' }],
|
85
|
-
['scissor', { image: 'basics:icon-hairdresser' }],
|
86
|
-
['shield', { image: 'basics:icon-historic', offset: [0, -10] }],
|
87
|
-
['shoes', { image: 'basics:icon-shoes', offset: [-5, 0] }],
|
88
|
-
['shop', { image: 'basics:icon-shop' }],
|
89
|
-
['shop', { image: 'basics:icon-shop' }],
|
90
|
-
['shrine', { image: 'basics:icon-shrine' }],
|
91
|
-
['sports', { image: 'basics:icon-sports' }],
|
92
|
-
['stadium', { image: 'basics:icon-stadium' }],
|
93
|
-
['stationery', { image: 'basics:icon-stationery' }],
|
94
|
-
['surveillance', { image: 'basics:icon-surveillance' }],
|
95
|
-
['swimming', { image: 'basics:icon-swimming' }],
|
96
|
-
['telephone', { image: 'basics:icon-telephone' }],
|
97
|
-
['theatre', { image: 'basics:icon-theatre' }],
|
98
|
-
['toilet', { image: 'basics:icon-toilet' }],
|
99
|
-
['tooth', { image: 'basics:icon-dentist' }],
|
100
|
-
['town hall', { image: 'basics:icon-town_hall' }],
|
101
|
-
['toys', { image: 'basics:icon-toys' }],
|
102
|
-
['tram', { image: 'basics:transport-tram' }],
|
103
|
-
['travel agent', { image: 'basics:icon-travel_agent' }],
|
104
|
-
['vendingmachine', { image: 'basics:icon-vendingmachine' }],
|
105
|
-
['veterinary', { image: 'basics:icon-veterinary' }],
|
106
|
-
['video', { image: 'basics:icon-video' }],
|
107
|
-
['viewpoint', { image: 'basics:icon-viewpoint', offset: [0, -6] }],
|
108
|
-
['waste basket', { image: 'basics:icon-waste_basket' }],
|
109
|
-
['watermill', { image: 'basics:icon-watermill' }],
|
110
|
-
['waterpark', { image: 'basics:icon-waterpark' }],
|
111
|
-
['windmill', { image: 'basics:icon-windmill' }],
|
112
|
-
['zoo', { image: 'basics:icon-zoo' }]
|
113
|
-
]);
|
114
|
-
export class MarkerElement extends AbstractElement {
|
115
|
-
color = writable('#ff0000');
|
116
|
-
halo = writable(1);
|
117
|
-
rotate = writable(0);
|
118
|
-
size = writable(1);
|
119
|
-
symbol = writable('flag');
|
120
|
-
label = writable('');
|
121
|
-
point = [0, 0];
|
122
|
-
constructor(manager, name, point) {
|
123
|
-
super(manager, name, 'symbol');
|
124
|
-
this.point = point ?? this.randomPositions(name, 1)[0];
|
125
|
-
const getSymbol = () => {
|
126
|
-
const entry = symbols.get(get(this.symbol)) ?? symbols.get('flag');
|
127
|
-
return { image: entry.image, offset: entry.offset ?? [0, 0] };
|
128
|
-
};
|
129
|
-
this.layer.setLayout({
|
130
|
-
'icon-image': getSymbol().image,
|
131
|
-
'icon-offset': getSymbol().offset,
|
132
|
-
'icon-overlap': 'always',
|
133
|
-
'icon-rotate': get(this.rotate),
|
134
|
-
'icon-size': get(this.size),
|
135
|
-
'text-field': get(this.label),
|
136
|
-
'text-font': ['noto_sans_regular'],
|
137
|
-
'text-justify': 'left',
|
138
|
-
'text-anchor': 'right',
|
139
|
-
'text-offset': [-0.4, -0.6]
|
140
|
-
});
|
141
|
-
this.layer.setPaint({
|
142
|
-
'icon-color': Color.parse(get(this.color)).asString(),
|
143
|
-
'icon-halo-blur': 0,
|
144
|
-
'icon-halo-color': '#FFFFFF',
|
145
|
-
'icon-halo-width': get(this.halo) * get(this.size),
|
146
|
-
'icon-opacity': 1,
|
147
|
-
'text-halo-blur': 0,
|
148
|
-
'text-halo-color': '#FFFFFF',
|
149
|
-
'text-halo-width': get(this.halo) * get(this.size)
|
150
|
-
});
|
151
|
-
this.color.subscribe((value) => this.layer.updatePaint('icon-color', Color.parse(value)));
|
152
|
-
this.halo.subscribe((value) => {
|
153
|
-
this.layer.updatePaint('icon-halo-width', value * get(this.size));
|
154
|
-
this.layer.updatePaint('text-halo-width', value * get(this.size));
|
155
|
-
});
|
156
|
-
this.label.subscribe((value) => this.layer.updateLayout('text-field', value));
|
157
|
-
this.rotate.subscribe((value) => this.layer.updateLayout('icon-rotate', value));
|
158
|
-
this.size.subscribe((value) => {
|
159
|
-
this.layer.updateLayout('icon-size', value);
|
160
|
-
this.layer.updatePaint('icon-halo-width', value * get(this.halo));
|
161
|
-
this.layer.updateLayout('text-size', value * 16);
|
162
|
-
this.layer.updatePaint('text-halo-width', value * get(this.halo));
|
163
|
-
});
|
164
|
-
this.symbol.subscribe(() => {
|
165
|
-
const symbol = getSymbol();
|
166
|
-
this.layer.updateLayout('icon-image', symbol.image);
|
167
|
-
this.layer.updateLayout('icon-offset', symbol.offset);
|
168
|
-
});
|
169
|
-
this.source.setData(this.getFeature());
|
170
|
-
}
|
171
|
-
getFeature() {
|
172
|
-
return {
|
173
|
-
type: 'Feature',
|
174
|
-
properties: {},
|
175
|
-
geometry: {
|
176
|
-
type: 'Point',
|
177
|
-
coordinates: this.point
|
178
|
-
}
|
179
|
-
};
|
180
|
-
}
|
181
|
-
getSelectionNodes() {
|
182
|
-
return [{ index: 0, coordinates: this.point }];
|
183
|
-
}
|
184
|
-
getSelectionNodeUpdater() {
|
185
|
-
return (lng, lat) => {
|
186
|
-
this.point[0] = lng;
|
187
|
-
this.point[1] = lat;
|
188
|
-
this.source.setData(this.getFeature());
|
189
|
-
};
|
190
|
-
}
|
191
|
-
}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import type { LayerFill, LayerLine, LayerSymbol } from './types.js';
|
2
|
-
type LayerSpec = LayerFill | LayerLine | LayerSymbol;
|
3
|
-
export declare class MapLayer<T extends LayerSpec> {
|
4
|
-
readonly map: maplibregl.Map;
|
5
|
-
readonly id: string;
|
6
|
-
readonly layoutProperties: T["layout"];
|
7
|
-
readonly paintProperties: T["paint"];
|
8
|
-
constructor(map: maplibregl.Map, id: string, source: string, type: 'symbol' | 'line' | 'fill');
|
9
|
-
setPaint(paint: T['paint']): void;
|
10
|
-
updatePaint<K extends keyof T['paint'], V extends T['paint'][K]>(key: K, value: V): void;
|
11
|
-
setLayout(layout: T['layout']): void;
|
12
|
-
updateLayout<K extends keyof T['layout'], V extends T['layout'][K]>(key: K, value: V): void;
|
13
|
-
}
|
14
|
-
export {};
|
@@ -1,61 +0,0 @@
|
|
1
|
-
import { Color } from '@versatiles/style';
|
2
|
-
export class MapLayer {
|
3
|
-
map;
|
4
|
-
id;
|
5
|
-
layoutProperties = {};
|
6
|
-
paintProperties = {};
|
7
|
-
constructor(map, id, source, type) {
|
8
|
-
this.map = map;
|
9
|
-
this.id = id;
|
10
|
-
let filter;
|
11
|
-
switch (type) {
|
12
|
-
case 'symbol':
|
13
|
-
filter = 'Point';
|
14
|
-
break;
|
15
|
-
case 'line':
|
16
|
-
filter = 'LineString';
|
17
|
-
break;
|
18
|
-
case 'fill':
|
19
|
-
filter = 'Polygon';
|
20
|
-
break;
|
21
|
-
default:
|
22
|
-
throw new Error('Invalid layer type');
|
23
|
-
}
|
24
|
-
this.map.addLayer({
|
25
|
-
id,
|
26
|
-
source,
|
27
|
-
type,
|
28
|
-
layout: this.layoutProperties,
|
29
|
-
paint: this.paintProperties,
|
30
|
-
filter: ['==', '$type', filter]
|
31
|
-
}, 'selection_nodes');
|
32
|
-
}
|
33
|
-
setPaint(paint) {
|
34
|
-
if (paint === undefined)
|
35
|
-
return;
|
36
|
-
const keys = new Set(Object.keys(paint).concat(Object.keys(this.paintProperties)));
|
37
|
-
for (const key of keys.values())
|
38
|
-
this.updatePaint(key, paint[key]);
|
39
|
-
}
|
40
|
-
updatePaint(key, value) {
|
41
|
-
if (value instanceof Color)
|
42
|
-
value = value.asString();
|
43
|
-
if (this.paintProperties[key] == value)
|
44
|
-
return;
|
45
|
-
this.map.setPaintProperty(this.id, key, value);
|
46
|
-
this.paintProperties[key] = value;
|
47
|
-
}
|
48
|
-
setLayout(layout) {
|
49
|
-
if (layout === undefined)
|
50
|
-
return;
|
51
|
-
const keys = new Set(Object.keys(layout).concat(Object.keys(this.layoutProperties)));
|
52
|
-
for (const key of keys.values())
|
53
|
-
this.updateLayout(key, layout[key]);
|
54
|
-
}
|
55
|
-
updateLayout(key, value) {
|
56
|
-
if (this.layoutProperties[key] == value)
|
57
|
-
return;
|
58
|
-
this.map.setLayoutProperty(this.id, key, value);
|
59
|
-
this.layoutProperties[key] = value;
|
60
|
-
}
|
61
|
-
}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
interface SpriteEntry {
|
2
|
-
width: number;
|
3
|
-
height: number;
|
4
|
-
x: number;
|
5
|
-
y: number;
|
6
|
-
pixelRatio: number;
|
7
|
-
sdf: boolean;
|
8
|
-
id: string;
|
9
|
-
name: string;
|
10
|
-
group: string;
|
11
|
-
}
|
12
|
-
export declare class SpriteLibrary {
|
13
|
-
private spriteList;
|
14
|
-
private pixelRatio;
|
15
|
-
constructor(pixelRatio?: number);
|
16
|
-
getSpriteList(): Promise<SpriteEntry[]>;
|
17
|
-
private loadSpriteList;
|
18
|
-
}
|
19
|
-
export default SpriteLibrary;
|
@@ -1,30 +0,0 @@
|
|
1
|
-
export class SpriteLibrary {
|
2
|
-
spriteList = [];
|
3
|
-
pixelRatio;
|
4
|
-
constructor(pixelRatio = 2) {
|
5
|
-
this.pixelRatio = pixelRatio;
|
6
|
-
}
|
7
|
-
async getSpriteList() {
|
8
|
-
await this.loadSpriteList();
|
9
|
-
return this.spriteList;
|
10
|
-
}
|
11
|
-
async loadSpriteList() {
|
12
|
-
if (this.spriteList.length)
|
13
|
-
return;
|
14
|
-
const spriteGroupList = (await fetch('https://tiles.versatiles.org/assets/sprites/index.json').then((r) => r.json()));
|
15
|
-
await Promise.all(spriteGroupList.map(async (group) => {
|
16
|
-
const spriteGroup = (await fetch(`https://tiles.versatiles.org/assets/sprites/${group}/sprites@${this.pixelRatio}x.json`).then((r) => r.json()));
|
17
|
-
Object.entries(spriteGroup).forEach(([name, entry]) => {
|
18
|
-
this.spriteList.push({
|
19
|
-
...entry,
|
20
|
-
pixelRatio: entry.pixelRatio ?? 1,
|
21
|
-
sdf: entry.sdf ?? false,
|
22
|
-
id: `${group}/${name}`,
|
23
|
-
group,
|
24
|
-
name
|
25
|
-
});
|
26
|
-
});
|
27
|
-
}));
|
28
|
-
}
|
29
|
-
}
|
30
|
-
export default SpriteLibrary;
|
File without changes
|