@teipublisher/pb-components 1.31.0 → 1.32.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/CHANGELOG.md +12 -0
- package/css/leaflet/MarkerCluster.Default.css +60 -0
- package/css/leaflet/MarkerCluster.css +14 -0
- package/dist/demo/pb-leaflet-map.html +9 -7
- package/dist/demo/pb-leaflet-map2.html +2 -2
- package/dist/demo/pb-leaflet-map3.html +3 -5
- package/dist/es-global-bridge-6abe3a88.js +5 -0
- package/dist/pb-components-bundle.js +97 -104
- package/dist/pb-elements.json +28 -0
- package/dist/pb-leaflet-map.js +4 -8
- package/lib/leaflet-src.js +14062 -0
- package/lib/leaflet.markercluster-src.js +2718 -0
- package/package.json +2 -1
- package/pb-elements.json +28 -0
- package/src/pb-geolocation.js +6 -0
- package/src/pb-leaflet-map.js +75 -38
- package/src/pb-split-list.js +2 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teipublisher/pb-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.0",
|
|
4
4
|
"description": "Collection of webcomponents underlying TEI Publisher",
|
|
5
5
|
"repository": "https://github.com/eeditiones/tei-publisher-components.git",
|
|
6
6
|
"main": "index.html",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"i18next-xhr-backend": "^3.2.2",
|
|
77
77
|
"js-cookie": "^2.2.1",
|
|
78
78
|
"leaflet": "^1.7.1",
|
|
79
|
+
"leaflet.markercluster": "^1.5.3",
|
|
79
80
|
"lit-element": "latest",
|
|
80
81
|
"lit-html": "^1.3.0",
|
|
81
82
|
"marked": "^1.2.0",
|
package/pb-elements.json
CHANGED
|
@@ -3760,6 +3760,7 @@
|
|
|
3760
3760
|
},
|
|
3761
3761
|
{
|
|
3762
3762
|
"name": "auto",
|
|
3763
|
+
"description": "If set, add location to a map automatically upon load by\nemitting an event. If not set, locations are only added when\nthe configured event is triggered.",
|
|
3763
3764
|
"type": "boolean",
|
|
3764
3765
|
"default": "false"
|
|
3765
3766
|
},
|
|
@@ -3847,6 +3848,7 @@
|
|
|
3847
3848
|
{
|
|
3848
3849
|
"name": "auto",
|
|
3849
3850
|
"attribute": "auto",
|
|
3851
|
+
"description": "If set, add location to a map automatically upon load by\nemitting an event. If not set, locations are only added when\nthe configured event is triggered.",
|
|
3850
3852
|
"type": "boolean",
|
|
3851
3853
|
"default": "false"
|
|
3852
3854
|
},
|
|
@@ -4578,6 +4580,18 @@
|
|
|
4578
4580
|
"type": "boolean",
|
|
4579
4581
|
"default": "false"
|
|
4580
4582
|
},
|
|
4583
|
+
{
|
|
4584
|
+
"name": "cluster",
|
|
4585
|
+
"description": "If set, combine markers into clusters if they are located too close together\nto display as single markers",
|
|
4586
|
+
"type": "boolean",
|
|
4587
|
+
"default": "false"
|
|
4588
|
+
},
|
|
4589
|
+
{
|
|
4590
|
+
"name": "fit-markers",
|
|
4591
|
+
"description": "If set, the map will automatically zoom so it can fit all the markers",
|
|
4592
|
+
"type": "boolean",
|
|
4593
|
+
"default": "false"
|
|
4594
|
+
},
|
|
4581
4595
|
{
|
|
4582
4596
|
"name": "subscribe",
|
|
4583
4597
|
"description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
|
|
@@ -4667,6 +4681,20 @@
|
|
|
4667
4681
|
"type": "boolean",
|
|
4668
4682
|
"default": "false"
|
|
4669
4683
|
},
|
|
4684
|
+
{
|
|
4685
|
+
"name": "cluster",
|
|
4686
|
+
"attribute": "cluster",
|
|
4687
|
+
"description": "If set, combine markers into clusters if they are located too close together\nto display as single markers",
|
|
4688
|
+
"type": "boolean",
|
|
4689
|
+
"default": "false"
|
|
4690
|
+
},
|
|
4691
|
+
{
|
|
4692
|
+
"name": "fitMarkers",
|
|
4693
|
+
"attribute": "fit-markers",
|
|
4694
|
+
"description": "If set, the map will automatically zoom so it can fit all the markers",
|
|
4695
|
+
"type": "boolean",
|
|
4696
|
+
"default": "false"
|
|
4697
|
+
},
|
|
4670
4698
|
{
|
|
4671
4699
|
"name": "subscribe",
|
|
4672
4700
|
"attribute": "subscribe",
|
package/src/pb-geolocation.js
CHANGED
|
@@ -33,6 +33,11 @@ export class PbGeolocation extends PbHighlight {
|
|
|
33
33
|
event: {
|
|
34
34
|
type: String
|
|
35
35
|
},
|
|
36
|
+
/**
|
|
37
|
+
* If set, add location to a map automatically upon load by
|
|
38
|
+
* emitting an event. If not set, locations are only added when
|
|
39
|
+
* the configured event is triggered.
|
|
40
|
+
*/
|
|
36
41
|
auto: {
|
|
37
42
|
type: Boolean
|
|
38
43
|
}
|
|
@@ -70,6 +75,7 @@ export class PbGeolocation extends PbHighlight {
|
|
|
70
75
|
},
|
|
71
76
|
label: this.label,
|
|
72
77
|
popup: this.popup,
|
|
78
|
+
fitBounds: true,
|
|
73
79
|
element: this
|
|
74
80
|
});
|
|
75
81
|
});
|
package/src/pb-leaflet-map.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LitElement, html, css } from 'lit-element';
|
|
2
|
-
import
|
|
2
|
+
import "@lrnwebcomponents/es-global-bridge";
|
|
3
3
|
import { pbMixin } from './pb-mixin.js';
|
|
4
4
|
import { resolveURL } from './utils.js';
|
|
5
5
|
import './pb-map-layer.js';
|
|
@@ -29,6 +29,20 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
29
29
|
crs: {
|
|
30
30
|
type: String
|
|
31
31
|
},
|
|
32
|
+
/**
|
|
33
|
+
* If set, the map will automatically zoom so it can fit all the markers
|
|
34
|
+
*/
|
|
35
|
+
fitMarkers: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
attribute: 'fit-markers'
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* If set, combine markers into clusters if they are located too close together
|
|
41
|
+
* to display as single markers
|
|
42
|
+
*/
|
|
43
|
+
cluster: {
|
|
44
|
+
type: Boolean
|
|
45
|
+
},
|
|
32
46
|
/**
|
|
33
47
|
* If enabled, the map will not automatically scroll to the coordinates received via `pb-geolocation`
|
|
34
48
|
*/
|
|
@@ -73,6 +87,8 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
73
87
|
this.toggle = false;
|
|
74
88
|
this.noScroll = false;
|
|
75
89
|
this.disabled = true;
|
|
90
|
+
this.cluster = false;
|
|
91
|
+
this.fitMarkers = false;
|
|
76
92
|
}
|
|
77
93
|
|
|
78
94
|
connectedCallback() {
|
|
@@ -85,7 +101,8 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
85
101
|
* @param {{ detail: any[]; }} ev
|
|
86
102
|
*/
|
|
87
103
|
this.subscribeTo('pb-update-map', (ev) => {
|
|
88
|
-
|
|
104
|
+
this._markerLayer.clearLayers();
|
|
105
|
+
|
|
89
106
|
/**
|
|
90
107
|
* @param {{ latitude: any; longitude: any; label: any; }} loc
|
|
91
108
|
*/
|
|
@@ -101,14 +118,9 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
101
118
|
this.emitTo('pb-leaflet-marker-click', loc);
|
|
102
119
|
});
|
|
103
120
|
marker.bindTooltip(loc.label);
|
|
104
|
-
|
|
105
|
-
bounds.extend([loc.latitude, loc.longitude]);
|
|
121
|
+
this._markerLayer.addLayer(marker);
|
|
106
122
|
});
|
|
107
|
-
|
|
108
|
-
this._map.fitBounds(bounds);
|
|
109
|
-
} else {
|
|
110
|
-
this._map.setZoom(this.zoom);
|
|
111
|
-
}
|
|
123
|
+
this._fitBounds();
|
|
112
124
|
});
|
|
113
125
|
|
|
114
126
|
/**
|
|
@@ -117,20 +129,14 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
117
129
|
* @param {{ detail: { root: { querySelectorAll: (arg0: string) => any[]; }; }; }} ev
|
|
118
130
|
*/
|
|
119
131
|
this.subscribeTo('pb-update', (ev) => {
|
|
120
|
-
this.
|
|
121
|
-
if (layer instanceof L.Marker) {
|
|
122
|
-
layer.remove();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
const bounds = L.latLngBounds();
|
|
132
|
+
this._markerLayer.clearLayers();
|
|
126
133
|
const locations = ev.detail.root.querySelectorAll('pb-geolocation');
|
|
127
134
|
/**
|
|
128
135
|
* @param {{ latitude: any; longitude: any; }} loc
|
|
129
136
|
*/
|
|
130
137
|
locations.forEach((loc) => {
|
|
131
138
|
const coords = L.latLng(loc.latitude, loc.longitude);
|
|
132
|
-
|
|
133
|
-
const marker = L.marker(coords).addTo(this._map);
|
|
139
|
+
const marker = L.marker(coords).addTo(this._markerLayer);
|
|
134
140
|
if (loc.label) {
|
|
135
141
|
marker.bindTooltip(loc.label);
|
|
136
142
|
}
|
|
@@ -141,14 +147,7 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
141
147
|
this.emitTo('pb-leaflet-marker-click', loc);
|
|
142
148
|
});
|
|
143
149
|
});
|
|
144
|
-
|
|
145
|
-
if (locations.length === 0) {
|
|
146
|
-
this._map.fitWorld();
|
|
147
|
-
} else if (locations.length === 1) {
|
|
148
|
-
this._map.fitBounds(bounds, {maxZoom: this.zoom});
|
|
149
|
-
} else {
|
|
150
|
-
this._map.fitBounds(bounds);
|
|
151
|
-
}
|
|
150
|
+
this._fitBounds();
|
|
152
151
|
});
|
|
153
152
|
|
|
154
153
|
/**
|
|
@@ -171,7 +170,12 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
171
170
|
if (ev.detail.popup) {
|
|
172
171
|
marker.bindPopup(ev.detail.popup);
|
|
173
172
|
}
|
|
174
|
-
marker.addTo(this.
|
|
173
|
+
marker.addTo(this._markerLayer);
|
|
174
|
+
|
|
175
|
+
if (ev.detail.fitBounds) {
|
|
176
|
+
this._fitBounds();
|
|
177
|
+
}
|
|
178
|
+
|
|
175
179
|
console.log('<pb-leaflet-map> added marker');
|
|
176
180
|
} else {
|
|
177
181
|
console.log('<pb-leaflet-map> Marker already added to map');
|
|
@@ -179,7 +183,7 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
179
183
|
if (this.toggle) {
|
|
180
184
|
this.disabled = false;
|
|
181
185
|
}
|
|
182
|
-
this._locationChanged();
|
|
186
|
+
this._locationChanged(this.latitude, this.longitude);
|
|
183
187
|
}
|
|
184
188
|
});
|
|
185
189
|
}
|
|
@@ -188,13 +192,23 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
188
192
|
if (!this.toggle) {
|
|
189
193
|
this.disabled = false;
|
|
190
194
|
}
|
|
191
|
-
|
|
195
|
+
window.ESGlobalBridge.requestAvailability();
|
|
196
|
+
const leafletPath = resolveURL('../lib/leaflet-src.js');
|
|
197
|
+
const pluginPath = resolveURL('../lib/leaflet.markercluster-src.js');
|
|
198
|
+
window.ESGlobalBridge.instance.load("leaflet", leafletPath)
|
|
199
|
+
.then(() => window.ESGlobalBridge.instance.load("plugin", pluginPath));
|
|
200
|
+
window.addEventListener(
|
|
201
|
+
"es-bridge-plugin-loaded",
|
|
202
|
+
this._initMap.bind(this),
|
|
203
|
+
{ once: true }
|
|
204
|
+
);
|
|
192
205
|
}
|
|
193
206
|
|
|
194
207
|
render() {
|
|
195
208
|
const cssPath = resolveURL(this.cssPath);
|
|
196
209
|
return html`
|
|
197
210
|
<link rel="Stylesheet" href="${cssPath}/leaflet.css">
|
|
211
|
+
<link rel="Stylesheet" href="${cssPath}/MarkerCluster.Default.css">
|
|
198
212
|
<div id="map" style="height: 100%; width: 100%"></div>
|
|
199
213
|
`;
|
|
200
214
|
}
|
|
@@ -236,6 +250,14 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
236
250
|
crs
|
|
237
251
|
});
|
|
238
252
|
this._configureLayers();
|
|
253
|
+
|
|
254
|
+
if (this.cluster) {
|
|
255
|
+
this._markerLayer = L.markerClusterGroup();
|
|
256
|
+
} else {
|
|
257
|
+
this._markerLayer = L.layerGroup();
|
|
258
|
+
}
|
|
259
|
+
this._markerLayer.addTo(this._map);
|
|
260
|
+
|
|
239
261
|
this.signalReady();
|
|
240
262
|
|
|
241
263
|
L.control.scale().addTo(this._map);
|
|
@@ -310,16 +332,31 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
310
332
|
}
|
|
311
333
|
}
|
|
312
334
|
|
|
313
|
-
|
|
335
|
+
_fitBounds() {
|
|
336
|
+
if (!this.fitMarkers) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const bounds = L.latLngBounds();
|
|
340
|
+
let len = 0;
|
|
341
|
+
this._markerLayer.eachLayer((layer) => {
|
|
342
|
+
bounds.extend(layer.getLatLng());
|
|
343
|
+
len += 1;
|
|
344
|
+
});
|
|
345
|
+
if (len === 0) {
|
|
346
|
+
this._map.fitWorld();
|
|
347
|
+
} else if (len === 1) {
|
|
348
|
+
this._map.fitBounds(bounds, {maxZoom: this.zoom});
|
|
349
|
+
} else {
|
|
350
|
+
this._map.fitBounds(bounds);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
_locationChanged(lat, long) {
|
|
314
355
|
if (this._map) {
|
|
315
|
-
const coords = L.latLng([
|
|
316
|
-
this.
|
|
317
|
-
if (layer
|
|
318
|
-
|
|
319
|
-
layer.openTooltip();
|
|
320
|
-
} else {
|
|
321
|
-
layer.closeTooltip();
|
|
322
|
-
}
|
|
356
|
+
const coords = L.latLng([lat, long]);
|
|
357
|
+
this._markerLayer.eachLayer((layer) => {
|
|
358
|
+
if (layer.getLatLng().equals(coords)) {
|
|
359
|
+
layer.openTooltip();
|
|
323
360
|
}
|
|
324
361
|
});
|
|
325
362
|
if (!this.noScroll)
|
|
@@ -330,7 +367,7 @@ export class PbLeafletMap extends pbMixin(LitElement) {
|
|
|
330
367
|
_hasMarker(lat, long) {
|
|
331
368
|
const coords = L.latLng([lat, long]);
|
|
332
369
|
let found = false;
|
|
333
|
-
this.
|
|
370
|
+
this._markerLayer.eachLayer((layer) => {
|
|
334
371
|
if (layer instanceof L.Marker && layer.getLatLng().equals(coords)) {
|
|
335
372
|
found = true;
|
|
336
373
|
}
|
package/src/pb-split-list.js
CHANGED
|
@@ -49,9 +49,6 @@ export class PbSplitList extends pbMixin(LitElement) {
|
|
|
49
49
|
_categories: {
|
|
50
50
|
type: Array
|
|
51
51
|
},
|
|
52
|
-
_items: {
|
|
53
|
-
type: Array
|
|
54
|
-
},
|
|
55
52
|
...super.properties
|
|
56
53
|
};
|
|
57
54
|
}
|
|
@@ -59,7 +56,6 @@ export class PbSplitList extends pbMixin(LitElement) {
|
|
|
59
56
|
constructor() {
|
|
60
57
|
super();
|
|
61
58
|
this._categories = [];
|
|
62
|
-
this._items = [];
|
|
63
59
|
this._params = {};
|
|
64
60
|
this.selected = null;
|
|
65
61
|
this.subforms = null;
|
|
@@ -112,7 +108,7 @@ export class PbSplitList extends pbMixin(LitElement) {
|
|
|
112
108
|
})
|
|
113
109
|
.then((json) => {
|
|
114
110
|
this._categories = json.categories;
|
|
115
|
-
this.
|
|
111
|
+
this.innerHTML = json.items.join('');
|
|
116
112
|
this.emitTo('pb-end-update');
|
|
117
113
|
})
|
|
118
114
|
.catch((error) => {
|
|
@@ -152,11 +148,7 @@ export class PbSplitList extends pbMixin(LitElement) {
|
|
|
152
148
|
)
|
|
153
149
|
}
|
|
154
150
|
</header>
|
|
155
|
-
<div id="items" part="items">
|
|
156
|
-
${
|
|
157
|
-
this._items.map((item) => html`<div part="item">${unsafeHTML(item)}</div>`)
|
|
158
|
-
}
|
|
159
|
-
</div>
|
|
151
|
+
<div id="items" part="items"><slot></slot></div>
|
|
160
152
|
`;
|
|
161
153
|
}
|
|
162
154
|
|