@teipublisher/pb-components 2.26.1-next.3 → 3.0.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.
Files changed (154) hide show
  1. package/.github/workflows/main.yml +3 -3
  2. package/.github/workflows/node.js.yml +3 -3
  3. package/.github/workflows/release.js.yml +4 -4
  4. package/.releaserc.json +2 -2
  5. package/CHANGELOG.md +262 -11
  6. package/Dockerfile +78 -70
  7. package/css/components.css +5 -5
  8. package/css/leaflet/images/layers.png +0 -0
  9. package/dist/demo/components.css +46 -1
  10. package/dist/demo/pb-browse-docs2.html +1 -1
  11. package/dist/demo/pb-dialog.html +3 -5
  12. package/dist/demo/pb-drawer2.html +1 -1
  13. package/dist/demo/pb-facsimile.html +2 -2
  14. package/dist/demo/pb-grid.html +19 -6
  15. package/dist/demo/pb-leaflet-map.html +1 -1
  16. package/dist/demo/pb-login.html +0 -2
  17. package/dist/demo/pb-message.html +1 -2
  18. package/dist/demo/pb-progress.html +2 -2
  19. package/dist/demo/pb-repeat.html +1 -3
  20. package/dist/demo/pb-search.html +7 -4
  21. package/dist/demo/pb-search3.html +1 -1
  22. package/dist/demo/pb-search4.html +2 -2
  23. package/dist/demo/pb-view3.html +1 -1
  24. package/dist/{iron-form-3b8dcaa7.js → iron-form-dfb3e3b1.js} +95 -95
  25. package/dist/paper-checkbox-645e1077.js +200 -0
  26. package/dist/{paper-icon-button-b1d31571.js → paper-icon-button-984162bd.js} +1 -1
  27. package/dist/{paper-checkbox-515a5284.js → paper-inky-focus-behavior-fa16796b.js} +58 -247
  28. package/dist/{paper-listbox-a3b7175c.js → paper-listbox-5f5d1cec.js} +152 -162
  29. package/dist/pb-code-editor.js +25 -20
  30. package/dist/pb-component-docs.js +68 -64
  31. package/dist/pb-components-bundle.js +1983 -2293
  32. package/dist/pb-edit-app.js +167 -107
  33. package/dist/pb-elements.json +176 -120
  34. package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
  35. package/dist/pb-leaflet-map.js +23 -23
  36. package/dist/pb-mei.js +56 -41
  37. package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
  38. package/dist/pb-odd-editor.js +1023 -782
  39. package/dist/pb-tify.js +2 -2
  40. package/dist/vaadin-element-mixin-beb74ffd.js +545 -0
  41. package/gh-pages.js +5 -3
  42. package/i18n/common/en.json +6 -0
  43. package/i18n/common/pl.json +2 -2
  44. package/lib/openseadragon.min.js +6 -6
  45. package/package.json +3 -3
  46. package/pb-elements.json +176 -120
  47. package/src/assets/components.css +5 -5
  48. package/src/authority/airtable.js +20 -21
  49. package/src/authority/anton.js +129 -129
  50. package/src/authority/custom.js +23 -21
  51. package/src/authority/geonames.js +38 -32
  52. package/src/authority/gnd.js +50 -42
  53. package/src/authority/kbga.js +137 -134
  54. package/src/authority/metagrid.js +44 -46
  55. package/src/authority/reconciliation.js +66 -67
  56. package/src/authority/registry.js +4 -4
  57. package/src/docs/pb-component-docs.js +2 -2
  58. package/src/docs/pb-component-view.js +5 -5
  59. package/src/docs/pb-components-list.js +2 -2
  60. package/src/docs/pb-demo-snippet.js +2 -2
  61. package/src/dts-client.js +299 -297
  62. package/src/dts-select-endpoint.js +90 -82
  63. package/src/parse-date-service.js +184 -135
  64. package/src/pb-ajax.js +158 -171
  65. package/src/pb-authority-lookup.js +191 -156
  66. package/src/pb-autocomplete.js +292 -280
  67. package/src/pb-blacklab-highlight.js +264 -259
  68. package/src/pb-blacklab-results.js +236 -221
  69. package/src/pb-browse-docs.js +540 -475
  70. package/src/pb-browse.js +68 -65
  71. package/src/pb-clipboard.js +79 -76
  72. package/src/pb-code-editor.js +110 -102
  73. package/src/pb-code-highlight.js +209 -204
  74. package/src/pb-codepen.js +79 -72
  75. package/src/pb-collapse.js +211 -151
  76. package/src/pb-combo-box.js +190 -190
  77. package/src/pb-components-bundle.js +1 -1
  78. package/src/pb-components.js +1 -0
  79. package/src/pb-custom-form.js +173 -153
  80. package/src/pb-dialog.js +98 -62
  81. package/src/pb-document.js +89 -90
  82. package/src/pb-download.js +212 -196
  83. package/src/pb-drawer.js +145 -148
  84. package/src/pb-edit-app.js +301 -229
  85. package/src/pb-edit-xml.js +100 -97
  86. package/src/pb-events.js +114 -107
  87. package/src/pb-facs-link.js +104 -102
  88. package/src/pb-facsimile.js +474 -410
  89. package/src/pb-formula.js +151 -153
  90. package/src/pb-geolocation.js +129 -131
  91. package/src/pb-grid-action.js +53 -56
  92. package/src/pb-grid.js +231 -228
  93. package/src/pb-highlight.js +140 -140
  94. package/src/pb-hotkeys.js +40 -42
  95. package/src/pb-i18n.js +101 -104
  96. package/src/pb-image-strip.js +84 -78
  97. package/src/pb-lang.js +142 -57
  98. package/src/pb-leaflet-map.js +488 -485
  99. package/src/pb-link.js +126 -124
  100. package/src/pb-load.js +431 -429
  101. package/src/pb-login.js +299 -244
  102. package/src/pb-manage-odds.js +352 -336
  103. package/src/pb-map-icon.js +89 -89
  104. package/src/pb-map-layer.js +85 -85
  105. package/src/pb-markdown.js +90 -99
  106. package/src/pb-media-query.js +74 -72
  107. package/src/pb-mei.js +306 -295
  108. package/src/pb-message.js +139 -97
  109. package/src/pb-mixin.js +269 -264
  110. package/src/pb-navigation.js +80 -95
  111. package/src/pb-observable.js +38 -38
  112. package/src/pb-odd-editor.js +1054 -958
  113. package/src/pb-odd-elementspec-editor.js +349 -298
  114. package/src/pb-odd-model-editor.js +1075 -909
  115. package/src/pb-odd-parameter-editor.js +200 -178
  116. package/src/pb-odd-rendition-editor.js +136 -124
  117. package/src/pb-page.js +431 -422
  118. package/src/pb-paginate.js +228 -179
  119. package/src/pb-panel.js +198 -182
  120. package/src/pb-popover-themes.js +15 -8
  121. package/src/pb-popover.js +296 -287
  122. package/src/pb-print-preview.js +127 -127
  123. package/src/pb-progress.js +51 -51
  124. package/src/pb-repeat.js +105 -104
  125. package/src/pb-restricted.js +84 -77
  126. package/src/pb-search.js +256 -228
  127. package/src/pb-select-feature.js +127 -120
  128. package/src/pb-select-odd.js +132 -124
  129. package/src/pb-select-template.js +89 -78
  130. package/src/pb-select.js +251 -227
  131. package/src/pb-split-list.js +179 -174
  132. package/src/pb-svg.js +80 -79
  133. package/src/pb-table-column.js +54 -54
  134. package/src/pb-table-grid.js +221 -203
  135. package/src/pb-tabs.js +61 -63
  136. package/src/pb-tify.js +154 -154
  137. package/src/pb-timeline.js +382 -249
  138. package/src/pb-toggle-feature.js +195 -187
  139. package/src/pb-upload.js +184 -174
  140. package/src/pb-version.js +30 -30
  141. package/src/pb-view-annotate.js +135 -98
  142. package/src/pb-view.js +1282 -1270
  143. package/src/pb-zoom.js +127 -45
  144. package/src/polymer-hack.js +1 -1
  145. package/src/search-result-service.js +256 -223
  146. package/src/seed-element.js +13 -20
  147. package/src/settings.js +4 -4
  148. package/src/theming.js +98 -91
  149. package/src/urls.js +289 -289
  150. package/src/utils.js +53 -51
  151. package/css/pb-styles.css +0 -51
  152. package/dist/vaadin-element-mixin-fe4a4883.js +0 -527
  153. package/src/assets/pb-styles.css +0 -51
  154. package/src/pb-light-dom.js +0 -41
@@ -1,14 +1,14 @@
1
1
  import { LitElement, html, css } from 'lit-element';
2
- import "@lrnwebcomponents/es-global-bridge";
2
+ import '@lrnwebcomponents/es-global-bridge';
3
3
  import { pbMixin } from './pb-mixin.js';
4
4
  import { resolveURL } from './utils.js';
5
- import { get as i18n } from "./pb-i18n.js";
5
+ import { get as i18n } from './pb-i18n.js';
6
6
  import './pb-map-layer.js';
7
7
  import './pb-map-icon.js';
8
8
 
9
9
  /**
10
10
  * A wrapper component for [leaflet](https://leafletjs.com/) displaying a map.
11
- *
11
+ *
12
12
  * The map layers displayed can be configured via nested `pb-map-layer` (see docs) elements,
13
13
  * icons via `pb-map-icon`.
14
14
  *
@@ -33,522 +33,525 @@ import './pb-map-icon.js';
33
33
  * @fires pb-geocode - emitted if geocoding is enabled and the user searches or selects a location from the map
34
34
  */
35
35
  export class PbLeafletMap extends pbMixin(LitElement) {
36
- static get properties() {
37
- return {
38
- ...super.properties,
39
- latitude: {
40
- type: Number
41
- },
42
- longitude: {
43
- type: Number
44
- },
45
- zoom: {
46
- type: Number
47
- },
48
- crs: {
49
- type: String
50
- },
51
- /**
52
- * If set, the map will automatically zoom so it can fit all the markers
53
- */
54
- fitMarkers: {
55
- type: Boolean,
56
- attribute: 'fit-markers'
57
- },
58
- /**
59
- * If set, combine markers into clusters if they are located too close together
60
- * to display as single markers
61
- */
62
- cluster: {
63
- type: Boolean
64
- },
65
- /**
66
- * Limits up to which zoom level markers are arranged into clusters.
67
- * Using a higher zoom level here will result in more markers to be shown.
68
- *
69
- * Requires `cluster` option to be enabled.
70
- */
71
- disableClusteringAt: {
72
- type: Number,
73
- attribute: 'disable-clustering-at'
74
- },
75
- /**
76
- * If enabled, the map will not automatically scroll to the coordinates received via `pb-geolocation`
77
- */
78
- noScroll: {
79
- type: Boolean,
80
- attribute: 'no-scroll'
81
- },
82
- accessToken: {
83
- type: String,
84
- attribute: 'access-token'
85
- },
86
- /**
87
- * If enabled, the map will remain invisible until an event is received from `pb-geolocation`.
88
- * In this case the map also offers a close button to hide it again.
89
- */
90
- toggle: {
91
- type: Boolean
92
- },
93
- imagesPath: {
94
- type: String,
95
- attribute: 'images-path'
96
- },
97
- cssPath: {
98
- type: String,
99
- attribute: 'css-path'
100
- },
101
- /**
102
- * Enables geocoding: an additional control will allow users to search for a place.
103
- * Reverse geocoding is also possible: clicking on the map while pressing ctrl or cmd
104
- * will request information about the current location.
105
- *
106
- * In both cases, a `pb-geocode` event will be emitted containing additional information
107
- * about the place in the event details (see demo).
108
- *
109
- * For lookups the free OSM/Nominatim service is used.
110
- */
111
- geoCoding: {
112
- type: Boolean,
113
- attribute: 'geo-coding'
114
- },
115
- _map: {
116
- type: Object
117
- }
118
- };
119
- }
120
-
121
- constructor() {
122
- super();
123
- this.latitude = 51.505;
124
- this.longitude = -0.09;
125
- this.zoom = 15;
126
- this.crs = 'EPSG3857';
127
- this.accessToken = '';
128
- this.imagesPath = '../images/leaflet/';
129
- this.cssPath = '../css/leaflet';
130
- this.toggle = false;
131
- this.noScroll = false;
132
- this.disabled = true;
133
- this.cluster = false;
134
- this.fitMarkers = false;
135
- this.disableClusteringAt = null;
136
- this._icons = {};
137
- this.geoCoding = false;
138
- }
36
+ static get properties() {
37
+ return {
38
+ ...super.properties,
39
+ latitude: {
40
+ type: Number,
41
+ },
42
+ longitude: {
43
+ type: Number,
44
+ },
45
+ zoom: {
46
+ type: Number,
47
+ },
48
+ crs: {
49
+ type: String,
50
+ },
51
+ /**
52
+ * If set, the map will automatically zoom so it can fit all the markers
53
+ */
54
+ fitMarkers: {
55
+ type: Boolean,
56
+ attribute: 'fit-markers',
57
+ },
58
+ /**
59
+ * If set, combine markers into clusters if they are located too close together
60
+ * to display as single markers
61
+ */
62
+ cluster: {
63
+ type: Boolean,
64
+ },
65
+ /**
66
+ * Limits up to which zoom level markers are arranged into clusters.
67
+ * Using a higher zoom level here will result in more markers to be shown.
68
+ *
69
+ * Requires `cluster` option to be enabled.
70
+ */
71
+ disableClusteringAt: {
72
+ type: Number,
73
+ attribute: 'disable-clustering-at',
74
+ },
75
+ /**
76
+ * If enabled, the map will not automatically scroll to the coordinates received via `pb-geolocation`
77
+ */
78
+ noScroll: {
79
+ type: Boolean,
80
+ attribute: 'no-scroll',
81
+ },
82
+ accessToken: {
83
+ type: String,
84
+ attribute: 'access-token',
85
+ },
86
+ /**
87
+ * If enabled, the map will remain invisible until an event is received from `pb-geolocation`.
88
+ * In this case the map also offers a close button to hide it again.
89
+ */
90
+ toggle: {
91
+ type: Boolean,
92
+ },
93
+ imagesPath: {
94
+ type: String,
95
+ attribute: 'images-path',
96
+ },
97
+ cssPath: {
98
+ type: String,
99
+ attribute: 'css-path',
100
+ },
101
+ /**
102
+ * Enables geocoding: an additional control will allow users to search for a place.
103
+ * Reverse geocoding is also possible: clicking on the map while pressing ctrl or cmd
104
+ * will request information about the current location.
105
+ *
106
+ * In both cases, a `pb-geocode` event will be emitted containing additional information
107
+ * about the place in the event details (see demo).
108
+ *
109
+ * For lookups the free OSM/Nominatim service is used.
110
+ */
111
+ geoCoding: {
112
+ type: Boolean,
113
+ attribute: 'geo-coding',
114
+ },
115
+ _map: {
116
+ type: Object,
117
+ },
118
+ };
119
+ }
120
+
121
+ constructor() {
122
+ super();
123
+ this.latitude = 51.505;
124
+ this.longitude = -0.09;
125
+ this.zoom = 15;
126
+ this.crs = 'EPSG3857';
127
+ this.accessToken = '';
128
+ this.imagesPath = '../images/leaflet/';
129
+ this.cssPath = '../css/leaflet';
130
+ this.toggle = false;
131
+ this.noScroll = false;
132
+ this.disabled = true;
133
+ this.cluster = false;
134
+ this.fitMarkers = false;
135
+ this.disableClusteringAt = null;
136
+ this._icons = {};
137
+ this.geoCoding = false;
138
+ }
139
+
140
+ connectedCallback() {
141
+ super.connectedCallback();
142
+
143
+ this._layers = this.querySelectorAll('pb-map-layer');
144
+ this._markers = this.querySelectorAll('pb-map-icon');
139
145
 
140
- connectedCallback() {
141
- super.connectedCallback();
142
-
143
- this._layers = this.querySelectorAll('pb-map-layer');
144
- this._markers = this.querySelectorAll('pb-map-icon');
145
-
146
- /**
147
- * Custom event which passes an array of pb-geolocation within event details
148
- * @param {{ detail: any[]; }} ev
149
- */
150
- this.subscribeTo('pb-update-map', (ev) => {
151
- this._markerLayer.clearLayers();
152
-
153
- /**
154
- * @param {{ latitude: any; longitude: any; label: any; }} loc
155
- */
156
- /**
157
- * @param {{ latitude: any; longitude: any; label: any; }} loc
158
- */
159
- ev.detail.forEach((loc) => {
160
- const marker = L.marker([loc.latitude, loc.longitude]);
161
- if (loc.label) {
162
- marker.bindTooltip(loc.label);
163
- }
164
- marker.addEventListener('click', () => {
165
- this.emitTo('pb-leaflet-marker-click', { element: loc });
166
- });
167
- marker.bindTooltip(loc.label);
168
- this.setMarkerIcon(marker);
169
- this._markerLayer.addLayer(marker);
170
- });
171
- this._fitBounds();
172
- });
173
-
174
- /**
175
- * React to pb-update event triggered by a pb-view
176
- *
177
- * @param {{ detail: { root: { querySelectorAll: (arg0: string) => any[]; }; }; }} ev
178
- */
179
- this.subscribeTo('pb-update', (ev) => {
180
- this._markerLayer.clearLayers();
181
- const locations = ev.detail.root.querySelectorAll('pb-geolocation');
182
- /**
183
- * @param {{ latitude: any; longitude: any; }} loc
184
- */
185
- locations.forEach((loc) => {
186
- const coords = L.latLng(loc.latitude, loc.longitude);
187
- const marker = L.marker(coords).addTo(this._markerLayer);
188
- if (loc.label) {
189
- marker.bindTooltip(loc.label);
190
- }
191
- if (loc.popup) {
192
- marker.bindPopup(loc.popup);
193
- }
194
- marker.addEventListener('click', () => {
195
- this.emitTo('pb-leaflet-marker-click', { element: loc });
196
- });
197
- this.setMarkerIcon(marker);
198
- });
199
- this._fitBounds();
146
+ /**
147
+ * Custom event which passes an array of pb-geolocation within event details
148
+ * @param {{ detail: any[]; }} ev
149
+ */
150
+ this.subscribeTo('pb-update-map', ev => {
151
+ this._markerLayer.clearLayers();
152
+
153
+ /**
154
+ * @param {{ latitude: any; longitude: any; label: any; }} loc
155
+ */
156
+ /**
157
+ * @param {{ latitude: any; longitude: any; label: any; }} loc
158
+ */
159
+ ev.detail.forEach(loc => {
160
+ const marker = L.marker([loc.latitude, loc.longitude]);
161
+ if (loc.label) {
162
+ marker.bindTooltip(loc.label);
163
+ }
164
+ marker.addEventListener('click', () => {
165
+ this.emitTo('pb-leaflet-marker-click', { element: loc });
200
166
  });
167
+ marker.bindTooltip(loc.label);
168
+ this.setMarkerIcon(marker);
169
+ this._markerLayer.addLayer(marker);
170
+ });
171
+ this._fitBounds();
172
+ });
201
173
 
202
- /**
203
- * React to events send by pb-geolocation
204
- *
205
- * @param {{ detail: { coordinates: { latitude: number; longitude: number; }, label: string; }; }} ev
206
- */
207
- this.subscribeTo('pb-geolocation', (ev) => {
208
- if (ev.detail.coordinates) {
209
- this.latitude = ev.detail.coordinates.latitude;
210
- this.longitude = ev.detail.coordinates.longitude;
211
- if (ev.detail.clear) {
212
- this._markerLayer.clearLayers();
213
- }
214
-
215
- if (!this._hasMarker(this.latitude, this.longitude)) {
216
- const marker = L.marker([this.latitude, this.longitude]);
217
- marker.addEventListener('click', () => {
218
- this.emitTo('pb-leaflet-marker-click', ev.detail);
219
- });
220
- if (ev.detail.label) {
221
- marker.bindTooltip(ev.detail.label);
222
- }
223
- if (ev.detail.popup) {
224
- marker.bindPopup(ev.detail.popup);
225
- }
226
- this.setMarkerIcon(marker);
227
- marker.addTo(this._markerLayer);
228
-
229
- if (ev.detail.fitBounds) {
230
- this._fitBounds();
231
- }
232
-
233
- console.log('<pb-leaflet-map> added marker');
234
- } else {
235
- console.log('<pb-leaflet-map> Marker already added to map');
236
- }
237
-
238
- if (this.toggle) {
239
- this.disabled = false;
240
- }
241
- const activateMarker = ev.detail.event;
242
- this._locationChanged(this.latitude, this.longitude, ev.detail.zoom, activateMarker);
243
- }
174
+ /**
175
+ * React to pb-update event triggered by a pb-view
176
+ *
177
+ * @param {{ detail: { root: { querySelectorAll: (arg0: string) => any[]; }; }; }} ev
178
+ */
179
+ this.subscribeTo('pb-update', ev => {
180
+ this._markerLayer.clearLayers();
181
+ const locations = ev.detail.root.querySelectorAll('pb-geolocation');
182
+ /**
183
+ * @param {{ latitude: any; longitude: any; }} loc
184
+ */
185
+ locations.forEach(loc => {
186
+ const coords = L.latLng(loc.latitude, loc.longitude);
187
+ const marker = L.marker(coords).addTo(this._markerLayer);
188
+ if (loc.label) {
189
+ marker.bindTooltip(loc.label);
190
+ }
191
+ if (loc.popup) {
192
+ marker.bindPopup(loc.popup);
193
+ }
194
+ marker.addEventListener('click', () => {
195
+ this.emitTo('pb-leaflet-marker-click', { element: loc });
244
196
  });
245
- }
197
+ this.setMarkerIcon(marker);
198
+ });
199
+ this._fitBounds();
200
+ });
246
201
 
247
202
  /**
248
- * The underlying leafletjs map. Can be used for custom scripts.
249
- *
250
- * Will be null until the component is fully loaded. Listen to `pb-ready` on the component to
251
- * be sure it has initialized.
203
+ * React to events send by pb-geolocation
204
+ *
205
+ * @param {{ detail: { coordinates: { latitude: number; longitude: number; }, label: string; }; }} ev
252
206
  */
253
- get map() {
254
- return this._map;
255
- }
256
-
257
- setMarkerIcon(layer) {
258
- if (this._icons && this._icons.default) {
259
- layer.setIcon(this._icons.default);
207
+ this.subscribeTo('pb-geolocation', ev => {
208
+ if (ev.detail.coordinates) {
209
+ this.latitude = ev.detail.coordinates.latitude;
210
+ this.longitude = ev.detail.coordinates.longitude;
211
+ if (ev.detail.clear) {
212
+ this._markerLayer.clearLayers();
260
213
  }
261
- }
262
214
 
263
- firstUpdated() {
264
- if (!this.toggle) {
265
- this.disabled = false;
266
- }
215
+ if (!this._hasMarker(this.latitude, this.longitude)) {
216
+ const marker = L.marker([this.latitude, this.longitude]);
217
+ marker.addEventListener('click', () => {
218
+ this.emitTo('pb-leaflet-marker-click', ev.detail);
219
+ });
220
+ if (ev.detail.label) {
221
+ marker.bindTooltip(ev.detail.label);
222
+ }
223
+ if (ev.detail.popup) {
224
+ marker.bindPopup(ev.detail.popup);
225
+ }
226
+ this.setMarkerIcon(marker);
227
+ marker.addTo(this._markerLayer);
228
+
229
+ if (ev.detail.fitBounds) {
230
+ this._fitBounds();
231
+ }
267
232
 
268
- if (window.L !== undefined) {
269
- this._initMap();
270
- return;
233
+ console.log('<pb-leaflet-map> added marker');
234
+ } else {
235
+ console.log('<pb-leaflet-map> Marker already added to map');
271
236
  }
272
237
 
273
- window.ESGlobalBridge.requestAvailability();
274
- const leafletPath = resolveURL('../lib/leaflet-src.js');
275
- const pluginPath = resolveURL('../lib/leaflet.markercluster-src.js');
276
- const geoCodingPath = resolveURL('../lib/Control.Geocoder.min.js');
277
- window.ESGlobalBridge.instance.load("leaflet", leafletPath)
278
- .then(() => {
279
- window.ESGlobalBridge.instance.load("plugin", pluginPath)
280
- .then(() => {
281
- if (this.geoCoding) {
282
- window.ESGlobalBridge.instance.load("geocoding", geoCodingPath)
283
- .then(this._initMap.bind(this));
284
- } else {
285
- this._initMap();
286
- }
287
- });
288
- });
238
+ if (this.toggle) {
239
+ this.disabled = false;
240
+ }
241
+ const activateMarker = ev.detail.event;
242
+ this._locationChanged(this.latitude, this.longitude, ev.detail.zoom, activateMarker);
243
+ }
244
+ });
245
+ }
246
+
247
+ /**
248
+ * The underlying leafletjs map. Can be used for custom scripts.
249
+ *
250
+ * Will be null until the component is fully loaded. Listen to `pb-ready` on the component to
251
+ * be sure it has initialized.
252
+ */
253
+ get map() {
254
+ return this._map;
255
+ }
256
+
257
+ setMarkerIcon(layer) {
258
+ if (this._icons && this._icons.default) {
259
+ layer.setIcon(this._icons.default);
289
260
  }
261
+ }
290
262
 
291
- render() {
292
- const cssPath = resolveURL(this.cssPath);
293
- return html`
294
- <link rel="Stylesheet" href="${cssPath}/leaflet.css">
295
- <link rel="Stylesheet" href="${cssPath}/MarkerCluster.Default.css">
296
- ${this.geoCoding ? html`<link rel="Stylesheet" href="${cssPath}/Control.Geocoder.css">` : null}
297
- <div id="map" style="height: 100%; width: 100%"></div>
298
- `;
263
+ firstUpdated() {
264
+ if (!this.toggle) {
265
+ this.disabled = false;
299
266
  }
300
267
 
301
- static get styles() {
302
- return css`
303
- :host {
304
- display: block;
305
- }
306
-
307
- :host([disabled]) {
308
- visibility: hidden;
309
- }
310
-
311
- .close {
312
- border-radius: 4px;
313
- background-color: #fff;
314
- color: inherit;
315
- padding: 8px;
316
- font-size: 18px;
317
- font-weight: bold;
318
- text-decoration: none;
319
- cursor: pointer;
320
- }
321
- `;
268
+ if (window.L !== undefined) {
269
+ this._initMap();
270
+ return;
322
271
  }
323
272
 
324
- _initMap() {
325
- if (this._map) {
326
- return;
327
- }
328
-
329
- L.Icon.Default.imagePath = resolveURL(this.imagesPath);
330
-
331
- const crs = L.CRS[this.crs] || L.CRS.EPSG3857;
332
- this._map = L.map(this.shadowRoot.getElementById('map'), {
333
- zoom: this.zoom,
334
- center: L.latLng(this.latitude, this.longitude),
335
- crs
336
- });
337
- this._configureLayers();
338
- this._configureMarkers();
339
-
340
- if (this.cluster) {
341
- const options = {};
342
- if (this.disableClusteringAt) {
343
- options.disableClusteringAtZoom = this.disableClusteringAt;
344
- }
345
- this._markerLayer = L.markerClusterGroup(options);
273
+ window.ESGlobalBridge.requestAvailability();
274
+ const leafletPath = resolveURL('../lib/leaflet-src.js');
275
+ const pluginPath = resolveURL('../lib/leaflet.markercluster-src.js');
276
+ const geoCodingPath = resolveURL('../lib/Control.Geocoder.min.js');
277
+ window.ESGlobalBridge.instance.load('leaflet', leafletPath).then(() => {
278
+ window.ESGlobalBridge.instance.load('plugin', pluginPath).then(() => {
279
+ if (this.geoCoding) {
280
+ window.ESGlobalBridge.instance
281
+ .load('geocoding', geoCodingPath)
282
+ .then(this._initMap.bind(this));
346
283
  } else {
347
- this._markerLayer = L.layerGroup();
348
- }
349
- this._markerLayer.addTo(this._map);
350
-
351
- this.signalReady();
352
-
353
- L.control.scale().addTo(this._map);
354
-
355
- if (this.toggle) {
356
- let container;
357
- L.Control.CloseButton = L.Control.extend({
358
- options: {
359
- position: 'topright'
360
- },
361
- onAdd: (map) => {
362
- container = L.DomUtil.create('div');
363
- container.className = 'close';
364
- container.innerHTML = 'X';
365
- L.DomEvent.on(container, 'click', this._hide.bind(this));
366
- return container;
367
- },
368
- onRemove: (map) => {
369
- L.DomEvent.off(container, 'click', this._hide.bind(this));
370
- }
371
- });
372
- L.control.closeButton = (options) => new L.Control.CloseButton(options);
373
- L.control.closeButton({ position: 'topright' }).addTo(this._map);
284
+ this._initMap();
374
285
  }
375
-
376
- this._configureGeoCoding();
286
+ });
287
+ });
288
+ }
289
+
290
+ render() {
291
+ const cssPath = resolveURL(this.cssPath);
292
+ return html`
293
+ <link rel="Stylesheet" href="${cssPath}/leaflet.css" />
294
+ <link rel="Stylesheet" href="${cssPath}/MarkerCluster.Default.css" />
295
+ ${this.geoCoding
296
+ ? html`<link rel="Stylesheet" href="${cssPath}/Control.Geocoder.css" />`
297
+ : null}
298
+ <div id="map" style="height: 100%; width: 100%"></div>
299
+ `;
300
+ }
301
+
302
+ static get styles() {
303
+ return css`
304
+ :host {
305
+ display: block;
306
+ }
307
+
308
+ :host([disabled]) {
309
+ visibility: hidden;
310
+ }
311
+
312
+ .close {
313
+ border-radius: 4px;
314
+ background-color: #fff;
315
+ color: inherit;
316
+ padding: 8px;
317
+ font-size: 18px;
318
+ font-weight: bold;
319
+ text-decoration: none;
320
+ cursor: pointer;
321
+ }
322
+ `;
323
+ }
324
+
325
+ _initMap() {
326
+ if (this._map) {
327
+ return;
377
328
  }
378
329
 
379
- _configureGeoCoding() {
380
- if (!this.geoCoding) {
381
- return;
382
- }
383
- const geocoder = L.Control.Geocoder.nominatim({
384
- geocodingQueryParams: {
385
- 'accept-language': 'en'
386
- }
387
- });
388
- const control = L.Control.geocoder({
389
- defaultMarkGeocode: false,
390
- geocoder,
391
- placeholder: i18n('search.search'),
392
- suggestMinLength: 3
393
- });
394
- control.on('markgeocode', (e) => {
395
- const {geocode} = e;
396
- const options = {
397
- coordinates: {
398
- longitude: geocode.center.lng,
399
- latitude: geocode.center.lat,
400
- },
401
- name: geocode.name,
402
- label: geocode.html,
403
- properties: geocode.properties
404
- };
405
- this.emitTo('pb-geocode', options);
406
- });
407
- control.addTo(this._map);
408
-
409
- this._map.on('click', (e) => {
410
- if (e.originalEvent.ctrlKey || e.originalEvent.metaKey) {
411
- e.originalEvent.stopPropagation();
412
- geocoder.reverse(e.latlng, this._map.options.crs.scale(this._map.getZoom()), (results) => {
413
- const geocode = results[0];
414
- const options = {
415
- coordinates: {
416
- longitude: e.latlng.lng,
417
- latitude: e.latlng.lat,
418
- },
419
- name: geocode.name,
420
- label: geocode.html,
421
- properties: geocode.properties
422
- };
423
- this.emitTo('pb-geocode', options);
424
- });
425
- }
426
- });
330
+ L.Icon.Default.imagePath = resolveURL(this.imagesPath);
331
+
332
+ const crs = L.CRS[this.crs] || L.CRS.EPSG3857;
333
+ this._map = L.map(this.shadowRoot.getElementById('map'), {
334
+ zoom: this.zoom,
335
+ center: L.latLng(this.latitude, this.longitude),
336
+ crs,
337
+ });
338
+ this._configureLayers();
339
+ this._configureMarkers();
340
+
341
+ if (this.cluster) {
342
+ const options = {};
343
+ if (this.disableClusteringAt) {
344
+ options.disableClusteringAtZoom = this.disableClusteringAt;
345
+ }
346
+ this._markerLayer = L.markerClusterGroup(options);
347
+ } else {
348
+ this._markerLayer = L.layerGroup();
349
+ }
350
+ this._markerLayer.addTo(this._map);
351
+
352
+ this.signalReady();
353
+
354
+ L.control.scale().addTo(this._map);
355
+
356
+ if (this.toggle) {
357
+ let container;
358
+ L.Control.CloseButton = L.Control.extend({
359
+ options: {
360
+ position: 'topright',
361
+ },
362
+ onAdd: map => {
363
+ container = L.DomUtil.create('div');
364
+ container.className = 'close';
365
+ container.innerHTML = 'X';
366
+ L.DomEvent.on(container, 'click', this._hide.bind(this));
367
+ return container;
368
+ },
369
+ onRemove: map => {
370
+ L.DomEvent.off(container, 'click', this._hide.bind(this));
371
+ },
372
+ });
373
+ L.control.closeButton = options => new L.Control.CloseButton(options);
374
+ L.control.closeButton({ position: 'topright' }).addTo(this._map);
427
375
  }
428
376
 
429
- _configureMarkers() {
430
- if (this._markers.length === 0) {
431
- return;
432
- }
377
+ this._configureGeoCoding();
378
+ }
433
379
 
434
- this._icons = {};
435
- this._markers.forEach(config => {
436
- if (config.iconUrl) {
437
- this._icons[config.name] = L.icon(config.options);
438
- }
439
- })
380
+ _configureGeoCoding() {
381
+ if (!this.geoCoding) {
382
+ return;
440
383
  }
441
-
442
- _configureLayers() {
443
- if (this._layers.length === 0) {
444
- // configure a default layer
445
- L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token={accessToken}', {
446
- attribution: <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
447
- maxZoom: 18,
448
- zoomOffset: -1,
449
- tileSize: 512,
450
- accessToken: this.accessToken
451
- }).addTo(this._map);
452
- return;
453
- }
454
- const layers = L.control.layers(null, null, { collapsed: false });
455
- this._layers.forEach(config => {
456
- let layer;
457
- switch (config.type) {
458
- case 'geojson':
459
- config.data().then((data) => {
460
- layer = L.geoJSON([data]);
461
- this._addLayer(config, layer, layers);
462
- });
463
- break;
464
- default:
465
- layer = L.tileLayer(config.url, config.options);
466
- this._addLayer(config, layer, layers);
467
- break;
468
- }
384
+ const geocoder = L.Control.Geocoder.nominatim({
385
+ geocodingQueryParams: {
386
+ 'accept-language': 'en',
387
+ },
388
+ });
389
+ const control = L.Control.geocoder({
390
+ defaultMarkGeocode: false,
391
+ geocoder,
392
+ placeholder: i18n('search.search'),
393
+ suggestMinLength: 3,
394
+ });
395
+ control.on('markgeocode', e => {
396
+ const { geocode } = e;
397
+ const options = {
398
+ coordinates: {
399
+ longitude: geocode.center.lng,
400
+ latitude: geocode.center.lat,
401
+ },
402
+ name: geocode.name,
403
+ label: geocode.html,
404
+ properties: geocode.properties,
405
+ };
406
+ this.emitTo('pb-geocode', options);
407
+ });
408
+ control.addTo(this._map);
409
+
410
+ this._map.on('click', e => {
411
+ if (e.originalEvent.ctrlKey || e.originalEvent.metaKey) {
412
+ e.originalEvent.stopPropagation();
413
+ geocoder.reverse(e.latlng, this._map.options.crs.scale(this._map.getZoom()), results => {
414
+ const geocode = results[0];
415
+ const options = {
416
+ coordinates: {
417
+ longitude: e.latlng.lng,
418
+ latitude: e.latlng.lat,
419
+ },
420
+ name: geocode.name,
421
+ label: geocode.html,
422
+ properties: geocode.properties,
423
+ };
424
+ this.emitTo('pb-geocode', options);
469
425
  });
470
- // only show layer control if there's more than one layer
471
- if (this._layers.length > 1) {
472
- layers.addTo(this._map);
473
- }
474
- this._layers = null;
475
- }
426
+ }
427
+ });
428
+ }
476
429
 
477
- _addLayer(config, layer, layers) {
478
- if (config.show) {
479
- layer.addTo(this._map);
480
- }
481
- if (config.label) {
482
- if (config.base) {
483
- layers.addBaseLayer(layer, config.label);
484
- } else {
485
- layers.addOverlay(layer, config.label);
486
- }
487
- }
430
+ _configureMarkers() {
431
+ if (this._markers.length === 0) {
432
+ return;
488
433
  }
489
434
 
490
- _fitBounds() {
491
- if (!this.fitMarkers) {
492
- return;
493
- }
494
- const bounds = L.latLngBounds();
495
- let len = 0;
496
- this._markerLayer.eachLayer((layer) => {
497
- bounds.extend(layer.getLatLng());
498
- len += 1;
499
- });
500
- if (len === 0) {
501
- this._map.fitWorld();
502
- } else if (len === 1) {
503
- this._map.fitBounds(bounds, {maxZoom: this.zoom});
504
- } else {
505
- this._map.fitBounds(bounds);
506
- }
435
+ this._icons = {};
436
+ this._markers.forEach(config => {
437
+ if (config.iconUrl) {
438
+ this._icons[config.name] = L.icon(config.options);
439
+ }
440
+ });
441
+ }
442
+
443
+ _configureLayers() {
444
+ if (this._layers.length === 0) {
445
+ // configure a default layer
446
+ L.tileLayer(
447
+ 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token={accessToken}',
448
+ {
449
+ attribution:
450
+ '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
451
+ maxZoom: 18,
452
+ zoomOffset: -1,
453
+ tileSize: 512,
454
+ accessToken: this.accessToken,
455
+ },
456
+ ).addTo(this._map);
457
+ return;
507
458
  }
508
-
509
- _locationChanged(lat, long, zoom, setActive) {
510
- if (this._map) {
511
- const coords = L.latLng([lat, long]);
512
- this._markerLayer.eachLayer((layer) => {
513
- if (layer.getLatLng().equals(coords)) {
514
- if (zoom && !this.noScroll) {
515
- layer.openTooltip();
516
- this._map.setView(coords, zoom);
517
- } else if (this.cluster) {
518
- this._markerLayer.zoomToShowLayer(layer, () =>
519
- layer.openTooltip()
520
- );
521
- } else {
522
- layer.openTooltip();
523
- if (zoom) {
524
- this._map.setView(coords, zoom);
525
- } else {
526
- this._map.panTo(coords);
527
- }
528
- }
529
- if (setActive && this._icons && this._icons.active) {
530
- layer.setIcon(this._icons.active);
531
- }
532
- } else if (this._icons && this._icons.default && layer.getIcon() !== this._icons.default) {
533
- layer.setIcon(this._icons.default);
534
- }
535
- });
536
- }
459
+ const layers = L.control.layers(null, null, { collapsed: true });
460
+ this._layers.forEach(config => {
461
+ let layer;
462
+ switch (config.type) {
463
+ case 'geojson':
464
+ config.data().then(data => {
465
+ layer = L.geoJSON([data]);
466
+ this._addLayer(config, layer, layers);
467
+ });
468
+ break;
469
+ default:
470
+ layer = L.tileLayer(config.url, config.options);
471
+ this._addLayer(config, layer, layers);
472
+ break;
473
+ }
474
+ });
475
+ // only show layer control if there's more than one layer
476
+ if (this._layers.length > 1) {
477
+ layers.addTo(this._map);
537
478
  }
479
+ this._layers = null;
480
+ }
538
481
 
539
- _hasMarker(lat, long) {
540
- const coords = L.latLng([lat, long]);
541
- let found = null;
542
- this._markerLayer.eachLayer((layer) => {
543
- if (layer instanceof L.Marker && layer.getLatLng().equals(coords)) {
544
- found = layer;
545
- }
546
- });
547
- return found;
482
+ _addLayer(config, layer, layers) {
483
+ if (config.show) {
484
+ layer.addTo(this._map);
485
+ }
486
+ if (config.label) {
487
+ if (config.base) {
488
+ layers.addBaseLayer(layer, config.label);
489
+ } else {
490
+ layers.addOverlay(layer, config.label);
491
+ }
548
492
  }
493
+ }
549
494
 
550
- _hide() {
551
- this.disabled = true;
495
+ _fitBounds() {
496
+ if (!this.fitMarkers) {
497
+ return;
498
+ }
499
+ const bounds = L.latLngBounds();
500
+ let len = 0;
501
+ this._markerLayer.eachLayer(layer => {
502
+ bounds.extend(layer.getLatLng());
503
+ len += 1;
504
+ });
505
+ if (len === 0) {
506
+ this._map.fitWorld();
507
+ } else if (len === 1) {
508
+ this._map.fitBounds(bounds, { maxZoom: this.zoom });
509
+ } else {
510
+ this._map.fitBounds(bounds);
511
+ }
512
+ }
513
+
514
+ _locationChanged(lat, long, zoom, setActive) {
515
+ if (this._map) {
516
+ const coords = L.latLng([lat, long]);
517
+ this._markerLayer.eachLayer(layer => {
518
+ if (layer.getLatLng().equals(coords)) {
519
+ if (zoom && !this.noScroll) {
520
+ layer.openTooltip();
521
+ this._map.setView(coords, zoom);
522
+ } else if (this.cluster) {
523
+ this._markerLayer.zoomToShowLayer(layer, () => layer.openTooltip());
524
+ } else {
525
+ layer.openTooltip();
526
+ if (zoom) {
527
+ this._map.setView(coords, zoom);
528
+ } else {
529
+ this._map.panTo(coords);
530
+ }
531
+ }
532
+ if (setActive && this._icons && this._icons.active) {
533
+ layer.setIcon(this._icons.active);
534
+ }
535
+ } else if (this._icons && this._icons.default && layer.getIcon() !== this._icons.default) {
536
+ layer.setIcon(this._icons.default);
537
+ }
538
+ });
552
539
  }
540
+ }
541
+
542
+ _hasMarker(lat, long) {
543
+ const coords = L.latLng([lat, long]);
544
+ let found = null;
545
+ this._markerLayer.eachLayer(layer => {
546
+ if (layer instanceof L.Marker && layer.getLatLng().equals(coords)) {
547
+ found = layer;
548
+ }
549
+ });
550
+ return found;
551
+ }
552
+
553
+ _hide() {
554
+ this.disabled = true;
555
+ }
553
556
  }
554
- customElements.define('pb-leaflet-map', PbLeafletMap);
557
+ customElements.define('pb-leaflet-map', PbLeafletMap);