@teipublisher/pb-components 2.26.1-next.3 → 3.0.0-next-4.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.
Files changed (262) hide show
  1. package/.github/workflows/docker-cypress.yml +53 -0
  2. package/.github/workflows/node.js.yml +70 -21
  3. package/.releaserc.json +7 -2
  4. package/CHANGELOG.md +363 -11
  5. package/Dockerfile +78 -70
  6. package/README.md +112 -4
  7. package/css/components.css +5 -5
  8. package/css/gridjs/mermaid.min.css +1 -1
  9. package/css/leaflet/Control.Geocoder.css +1 -126
  10. package/css/leaflet/images/layers.png +0 -0
  11. package/css/tify/tify.css +6 -5
  12. package/css/tom-select/tom-select.bootstrap4.min.css +1 -1
  13. package/css/tom-select/tom-select.bootstrap5.min.css +1 -1
  14. package/css/tom-select/tom-select.default.min.css +1 -1
  15. package/css/tom-select/tom-select.default.min.css.map +1 -0
  16. package/css/tom-select/tom-select.min.css +1 -1
  17. package/cypress.config.js +84 -0
  18. package/dist/api.html +1 -1
  19. package/dist/css/design-system.css +607 -0
  20. package/dist/demo/bundle-test.html +4 -3
  21. package/dist/demo/components.css +46 -1
  22. package/dist/demo/design-system.html +710 -0
  23. package/dist/demo/dts-client.html +2 -2
  24. package/dist/demo/pb-autocomplete.html +23 -11
  25. package/dist/demo/pb-autocomplete2.html +66 -55
  26. package/dist/demo/pb-autocomplete3.html +17 -8
  27. package/dist/demo/pb-blacklab-highlight.html +28 -11
  28. package/dist/demo/pb-blacklab-results.html +3 -2
  29. package/dist/demo/pb-browse-docs.html +24 -24
  30. package/dist/demo/pb-browse-docs2.html +3 -3
  31. package/dist/demo/pb-clipboard.html +32 -28
  32. package/dist/demo/pb-code-editor.html +6 -6
  33. package/dist/demo/pb-code-highlight.html +63 -63
  34. package/dist/demo/pb-codepen.html +1 -1
  35. package/dist/demo/pb-collapse.html +1 -1
  36. package/dist/demo/pb-collapse2.html +2 -2
  37. package/dist/demo/pb-combo-box.html +135 -130
  38. package/dist/demo/pb-custom-form.html +64 -55
  39. package/dist/demo/pb-dialog.html +12 -6
  40. package/dist/demo/pb-document.html +1 -1
  41. package/dist/demo/pb-download.html +68 -59
  42. package/dist/demo/pb-drawer.html +67 -46
  43. package/dist/demo/pb-drawer2.html +65 -58
  44. package/dist/demo/pb-edit-app.html +2 -2
  45. package/dist/demo/pb-edit-xml.html +1 -1
  46. package/dist/demo/pb-facsimile-2.html +26 -11
  47. package/dist/demo/pb-facsimile-3.html +25 -10
  48. package/dist/demo/pb-facsimile-dedup-test-2.html +48 -0
  49. package/dist/demo/pb-facsimile-dedup-test.html +48 -0
  50. package/dist/demo/pb-facsimile.html +4 -4
  51. package/dist/demo/pb-formula.html +1 -1
  52. package/dist/demo/pb-grid.html +22 -8
  53. package/dist/demo/pb-highlight.html +2 -2
  54. package/dist/demo/pb-i18n-simple.html +1 -0
  55. package/dist/demo/pb-i18n.html +15 -5
  56. package/dist/demo/pb-image-strip-standalone.html +2 -2
  57. package/dist/demo/pb-image-strip-view.html +2 -2
  58. package/dist/demo/pb-leaflet-map.html +3 -3
  59. package/dist/demo/pb-leaflet-map2.html +2 -2
  60. package/dist/demo/pb-leaflet-map3.html +3 -3
  61. package/dist/demo/pb-link.html +1 -1
  62. package/dist/demo/pb-load.html +2 -6
  63. package/dist/demo/pb-login.html +1 -3
  64. package/dist/demo/pb-manage-odds.html +9 -4
  65. package/dist/demo/pb-markdown.html +1 -1
  66. package/dist/demo/pb-media-query.html +2 -2
  67. package/dist/demo/pb-mei.html +2 -2
  68. package/dist/demo/pb-mei2.html +2 -2
  69. package/dist/demo/pb-message.html +2 -3
  70. package/dist/demo/pb-odd-editor.html +54 -52
  71. package/dist/demo/pb-page-header.html +27 -0
  72. package/dist/demo/pb-popover.html +1 -1
  73. package/dist/demo/pb-print-preview.html +2 -2
  74. package/dist/demo/pb-progress.html +4 -4
  75. package/dist/demo/pb-repeat.html +32 -36
  76. package/dist/demo/pb-search.html +16 -5
  77. package/dist/demo/pb-search2.html +4 -4
  78. package/dist/demo/pb-search3.html +3 -3
  79. package/dist/demo/pb-search4.html +3 -3
  80. package/dist/demo/pb-select-feature.html +4 -4
  81. package/dist/demo/pb-select-feature2.html +4 -4
  82. package/dist/demo/pb-select-feature3.html +2 -2
  83. package/dist/demo/pb-select-i18n.html +58 -53
  84. package/dist/demo/pb-select-odd.html +1 -1
  85. package/dist/demo/pb-select.html +190 -75
  86. package/dist/demo/pb-select2.html +91 -37
  87. package/dist/demo/pb-select3.html +109 -41
  88. package/dist/demo/pb-svg.html +1 -1
  89. package/dist/demo/pb-table-grid.html +26 -15
  90. package/dist/demo/pb-tabs.html +15 -7
  91. package/dist/demo/pb-tify.html +7 -7
  92. package/dist/demo/pb-timeline.html +1 -1
  93. package/dist/demo/pb-timeline2.html +1 -1
  94. package/dist/demo/pb-toggle-feature.html +26 -23
  95. package/dist/demo/pb-toggle-feature2.html +4 -4
  96. package/dist/demo/pb-toggle-feature3.html +2 -2
  97. package/dist/demo/pb-toggle-feature4.html +56 -54
  98. package/dist/demo/pb-version.html +2 -2
  99. package/dist/demo/pb-view.html +78 -40
  100. package/dist/demo/pb-view2.html +69 -46
  101. package/dist/demo/pb-view3.html +53 -48
  102. package/dist/demo/pb-view4.html +70 -49
  103. package/dist/demo/pb-zoom.html +2 -2
  104. package/dist/{es-global-bridge-d8ce175d.js → es-global-bridge-D8ZcUcx_.js} +0 -4
  105. package/dist/focus-mixin-VCsFap6b.js +768 -0
  106. package/dist/images/icons.svg +217 -0
  107. package/dist/jinn-codemirror-DETLdm08.js +1 -0
  108. package/dist/lib/openseadragon.min.js +80 -0
  109. package/dist/lib/openseadragon.min.js.map +1 -0
  110. package/dist/pb-code-editor.js +25 -20
  111. package/dist/pb-component-docs.js +414 -3225
  112. package/dist/pb-components-bundle.js +3046 -4402
  113. package/dist/pb-dialog-tklYGWfc.js +121 -0
  114. package/dist/pb-edit-app.js +208 -107
  115. package/dist/pb-elements.json +716 -249
  116. package/dist/pb-facsimile.js +46 -0
  117. package/dist/pb-i18n-C0NDma4h.js +1 -0
  118. package/dist/pb-leaflet-map.js +23 -23
  119. package/dist/pb-mei.js +152 -134
  120. package/dist/pb-mixin-DHoWQheB.js +1 -0
  121. package/dist/pb-odd-editor.js +1671 -1231
  122. package/dist/pb-tify.js +1 -27
  123. package/dist/unsafe-html-D5VGo9Oq.js +1 -0
  124. package/dist/urls-BEONu_g4.js +1 -0
  125. package/eslint.config.mjs +92 -0
  126. package/gh-pages.js +5 -3
  127. package/i18n/common/en.json +6 -0
  128. package/i18n/common/pl.json +2 -2
  129. package/images/icons.svg +217 -0
  130. package/index.html +0 -5
  131. package/lib/leaflet-src.js.map +1 -0
  132. package/lib/leaflet.markercluster-src.js.map +1 -0
  133. package/lib/openseadragon.min.js +6 -6
  134. package/package.json +56 -81
  135. package/pb-elements.json +716 -249
  136. package/rollup.config.mjs +312 -0
  137. package/src/assets/components.css +5 -5
  138. package/src/assets/design-system.css +607 -0
  139. package/src/authority/airtable.js +20 -21
  140. package/src/authority/anton.js +129 -129
  141. package/src/authority/custom.js +70 -27
  142. package/src/authority/geonames.js +38 -32
  143. package/src/authority/gnd.js +50 -42
  144. package/src/authority/kbga.js +136 -134
  145. package/src/authority/metagrid.js +44 -46
  146. package/src/authority/reconciliation.js +66 -68
  147. package/src/authority/registry.js +4 -4
  148. package/src/docs/demo-utils.js +91 -0
  149. package/src/docs/pb-component-docs.js +287 -147
  150. package/src/docs/pb-component-view.js +380 -273
  151. package/src/docs/pb-components-list.js +115 -51
  152. package/src/docs/pb-demo-snippet.js +199 -174
  153. package/src/dts-client.js +306 -303
  154. package/src/dts-select-endpoint.js +125 -85
  155. package/src/parse-date-service.js +184 -135
  156. package/src/pb-ajax.js +175 -173
  157. package/src/pb-authority-lookup.js +198 -158
  158. package/src/pb-autocomplete.js +731 -313
  159. package/src/pb-blacklab-highlight.js +266 -260
  160. package/src/pb-blacklab-results.js +230 -225
  161. package/src/pb-browse-docs.js +601 -484
  162. package/src/pb-browse.js +68 -65
  163. package/src/pb-clipboard.js +97 -76
  164. package/src/pb-code-editor.js +111 -103
  165. package/src/pb-code-highlight.js +234 -204
  166. package/src/pb-codepen.js +81 -73
  167. package/src/pb-collapse.js +265 -152
  168. package/src/pb-combo-box.js +191 -191
  169. package/src/pb-components-bundle.js +1 -7
  170. package/src/pb-components.js +2 -6
  171. package/src/pb-custom-form.js +230 -141
  172. package/src/pb-dialog.js +99 -63
  173. package/src/pb-document.js +118 -91
  174. package/src/pb-download.js +214 -198
  175. package/src/pb-drawer.js +146 -149
  176. package/src/pb-edit-app.js +471 -240
  177. package/src/pb-edit-xml.js +101 -98
  178. package/src/pb-events.js +126 -107
  179. package/src/pb-facs-link.js +130 -101
  180. package/src/pb-facsimile.js +494 -410
  181. package/src/pb-fetch.js +389 -0
  182. package/src/pb-formula.js +152 -154
  183. package/src/pb-geolocation.js +130 -132
  184. package/src/pb-grid-action.js +59 -56
  185. package/src/pb-grid.js +388 -228
  186. package/src/pb-highlight.js +142 -142
  187. package/src/pb-hotkeys.js +40 -42
  188. package/src/pb-i18n.js +115 -127
  189. package/src/pb-icon-button.js +108 -0
  190. package/src/pb-icon.js +283 -0
  191. package/src/pb-image-strip.js +85 -79
  192. package/src/pb-lang.js +142 -57
  193. package/src/pb-leaflet-map.js +551 -483
  194. package/src/pb-link.js +132 -126
  195. package/src/pb-load.js +495 -428
  196. package/src/pb-login.js +303 -248
  197. package/src/pb-manage-odds.js +384 -338
  198. package/src/pb-map-icon.js +90 -90
  199. package/src/pb-map-layer.js +86 -86
  200. package/src/pb-markdown.js +107 -110
  201. package/src/pb-media-query.js +75 -73
  202. package/src/pb-mei.js +523 -303
  203. package/src/pb-message.js +144 -98
  204. package/src/pb-mixin.js +268 -265
  205. package/src/pb-navigation.js +83 -96
  206. package/src/pb-observable.js +39 -39
  207. package/src/pb-odd-editor.js +1209 -948
  208. package/src/pb-odd-elementspec-editor.js +375 -310
  209. package/src/pb-odd-model-editor.js +1189 -941
  210. package/src/pb-odd-parameter-editor.js +269 -170
  211. package/src/pb-odd-rendition-editor.js +184 -131
  212. package/src/pb-page.js +451 -422
  213. package/src/pb-paginate.js +260 -178
  214. package/src/pb-panel.js +217 -183
  215. package/src/pb-popover-themes.js +16 -9
  216. package/src/pb-popover.js +297 -288
  217. package/src/pb-print-preview.js +128 -128
  218. package/src/pb-progress.js +52 -52
  219. package/src/pb-repeat.js +141 -108
  220. package/src/pb-restricted.js +85 -78
  221. package/src/pb-search.js +258 -230
  222. package/src/pb-select-feature.js +210 -126
  223. package/src/pb-select-odd.js +184 -118
  224. package/src/pb-select-template.js +113 -78
  225. package/src/pb-select.js +330 -229
  226. package/src/pb-split-list.js +181 -176
  227. package/src/pb-svg.js +81 -80
  228. package/src/pb-table-column.js +55 -55
  229. package/src/pb-table-grid.js +334 -205
  230. package/src/pb-tabs.js +238 -61
  231. package/src/pb-tify.js +3331 -126
  232. package/src/pb-timeline.js +394 -255
  233. package/src/pb-toggle-feature.js +196 -188
  234. package/src/pb-upload.js +201 -176
  235. package/src/pb-version.js +22 -34
  236. package/src/pb-view-annotate.js +138 -102
  237. package/src/pb-view.js +1722 -1272
  238. package/src/pb-zoom.js +144 -46
  239. package/src/search-result-service.js +256 -223
  240. package/src/seed-element.js +14 -22
  241. package/src/settings.js +4 -4
  242. package/src/theming.js +98 -91
  243. package/src/urls.js +403 -289
  244. package/src/utils.js +53 -51
  245. package/vite.config.js +86 -0
  246. package/.github/workflows/main.yml +0 -24
  247. package/.github/workflows/release.js.yml +0 -34
  248. package/css/pb-styles.css +0 -51
  249. package/dist/iron-form-3b8dcaa7.js +0 -210
  250. package/dist/jinn-codemirror-da0e2d1f.js +0 -1
  251. package/dist/paper-checkbox-515a5284.js +0 -1597
  252. package/dist/paper-icon-button-b1d31571.js +0 -398
  253. package/dist/paper-listbox-a3b7175c.js +0 -1265
  254. package/dist/pb-i18n-0611135a.js +0 -1
  255. package/dist/pb-mixin-b1caa22e.js +0 -158
  256. package/dist/polymer-hack.js +0 -1
  257. package/dist/vaadin-element-mixin-fe4a4883.js +0 -527
  258. package/lib/Control.Geocoder.min.js +0 -2
  259. package/lib/Control.Geocoder.min.js.map +0 -1
  260. package/src/assets/pb-styles.css +0 -51
  261. package/src/pb-light-dom.js +0 -41
  262. package/src/polymer-hack.js +0 -6
@@ -1,14 +1,14 @@
1
- import { LitElement, html, css } from 'lit-element';
2
- import "@lrnwebcomponents/es-global-bridge";
1
+ import { LitElement, html, css } from 'lit';
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,590 @@ 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
- }
139
-
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
- });
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
+ this._mapReady = false;
139
+ this._markerLayer = null;
140
+ }
141
+
142
+ connectedCallback() {
143
+ super.connectedCallback();
144
+
145
+ this._layers = this.querySelectorAll('pb-map-layer');
146
+ this._markers = this.querySelectorAll('pb-map-icon');
173
147
 
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();
148
+ /**
149
+ * Custom event which passes an array of pb-geolocation within event details
150
+ * @param {{ detail: any[]; }} ev
151
+ */
152
+ this.subscribeTo('pb-update-map', ev => {
153
+ if (!this._markerLayer) return;
154
+ this._markerLayer.clearLayers();
155
+
156
+ /**
157
+ * @param {{ latitude: any; longitude: any; label: any; }} loc
158
+ */
159
+ /**
160
+ * @param {{ latitude: any; longitude: any; label: any; }} loc
161
+ */
162
+ ev.detail.forEach(loc => {
163
+ const marker = L.marker([loc.latitude, loc.longitude]);
164
+ if (loc.label) {
165
+ marker.bindTooltip(loc.label);
166
+ }
167
+ marker.addEventListener('click', () => {
168
+ this.emitTo('pb-leaflet-marker-click', { element: loc });
200
169
  });
170
+ marker.bindTooltip(loc.label);
171
+ this.setMarkerIcon(marker);
172
+ this._markerLayer.addLayer(marker);
173
+ });
174
+ this._fitBounds();
175
+ });
201
176
 
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
- }
177
+ /**
178
+ * React to pb-update event triggered by a pb-view
179
+ *
180
+ * @param {{ detail: { root: { querySelectorAll: (arg0: string) => any[]; }; }; }} ev
181
+ */
182
+ this.subscribeTo('pb-update', ev => {
183
+ if (!this._markerLayer) return;
184
+ this._markerLayer.clearLayers();
185
+ const locations = ev.detail.root.querySelectorAll('pb-geolocation');
186
+ /**
187
+ * @param {{ latitude: any; longitude: any; }} loc
188
+ */
189
+ locations.forEach(loc => {
190
+ const coords = L.latLng(loc.latitude, loc.longitude);
191
+ const marker = L.marker(coords);
192
+ this._markerLayer.addLayer(marker);
193
+ if (loc.label) {
194
+ marker.bindTooltip(loc.label);
195
+ }
196
+ if (loc.popup) {
197
+ marker.bindPopup(loc.popup);
198
+ }
199
+ marker.addEventListener('click', () => {
200
+ this.emitTo('pb-leaflet-marker-click', { element: loc });
244
201
  });
245
- }
202
+ this.setMarkerIcon(marker);
203
+ });
204
+ this._fitBounds();
205
+ });
246
206
 
247
207
  /**
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.
208
+ * React to events send by pb-geolocation
209
+ *
210
+ * @param {{ detail: { coordinates: { latitude: number; longitude: number; }, label: string; }; }} ev
252
211
  */
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);
212
+ this.subscribeTo('pb-geolocation', ev => {
213
+ if (ev.detail.coordinates) {
214
+ this.latitude = ev.detail.coordinates.latitude;
215
+ this.longitude = ev.detail.coordinates.longitude;
216
+ if (
217
+ ev.detail.clear &&
218
+ this._markerLayer &&
219
+ typeof this._markerLayer.clearLayers === 'function'
220
+ ) {
221
+ this._markerLayer.clearLayers();
260
222
  }
261
- }
262
223
 
263
- firstUpdated() {
264
- if (!this.toggle) {
265
- this.disabled = false;
266
- }
224
+ if (!this._hasMarker(this.latitude, this.longitude)) {
225
+ const marker = L.marker([this.latitude, this.longitude]);
226
+ marker.addEventListener('click', () => {
227
+ this.emitTo('pb-leaflet-marker-click', ev.detail);
228
+ });
229
+ if (ev.detail.label) {
230
+ marker.bindTooltip(ev.detail.label);
231
+ }
232
+ if (ev.detail.popup) {
233
+ marker.bindPopup(ev.detail.popup);
234
+ }
235
+ this.setMarkerIcon(marker);
236
+ if (this._markerLayer && typeof this._markerLayer.addLayer === 'function') {
237
+ this._markerLayer.addLayer(marker);
238
+ }
239
+
240
+ if (ev.detail.fitBounds) {
241
+ this._fitBounds();
242
+ }
267
243
 
268
- if (window.L !== undefined) {
269
- this._initMap();
270
- return;
244
+ console.log('<pb-leaflet-map> added marker');
245
+ } else {
246
+ console.log('<pb-leaflet-map> Marker already added to map');
271
247
  }
272
248
 
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
- });
289
- }
290
-
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
- `;
249
+ if (this.toggle) {
250
+ this.disabled = false;
251
+ }
252
+ const activateMarker = ev.detail.event;
253
+ this._locationChanged(this.latitude, this.longitude, ev.detail.zoom, activateMarker);
254
+ }
255
+ });
256
+ }
257
+
258
+ /**
259
+ * The underlying leafletjs map. Can be used for custom scripts.
260
+ *
261
+ * Will be null until the component is fully loaded. Listen to `pb-ready` on the component to
262
+ * be sure it has initialized.
263
+ */
264
+ get map() {
265
+ return this._map;
266
+ }
267
+
268
+ setMarkerIcon(layer) {
269
+ if (this._icons && this._icons.default) {
270
+ layer.setIcon(this._icons.default);
299
271
  }
272
+ }
300
273
 
301
- static get styles() {
302
- return css`
303
- :host {
304
- display: block;
305
- }
306
-
307
- :host([disabled]) {
308
- visibility: hidden;
309
- }
274
+ firstUpdated() {
275
+ if (!this.toggle) this.disabled = false;
310
276
 
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
- `;
277
+ if (window.L !== undefined) {
278
+ this._initMap();
279
+ return;
322
280
  }
323
281
 
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;
282
+ window.ESGlobalBridge.requestAvailability();
283
+ const leafletPath = resolveURL('../lib/leaflet-src.js');
284
+ const pluginPath = resolveURL('../lib/leaflet.markercluster-src.js');
285
+ const geoCodingPath = resolveURL('../lib/Control.Geocoder.min.js');
286
+
287
+ const loadGeocodingOrInit = () => {
288
+ if (this.geoCoding) {
289
+ // Check if the geocoding script URL is accessible before trying to load it
290
+ fetch(geoCodingPath, { method: 'HEAD' })
291
+ .then(response => {
292
+ if (response.ok) {
293
+ return window.ESGlobalBridge.instance.load('geocoding', geoCodingPath);
294
+ } else {
295
+ throw new Error(
296
+ `Geocoding script not available at ${geoCodingPath} (${response.status})`,
297
+ );
344
298
  }
345
- this._markerLayer = L.markerClusterGroup(options);
346
- } 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
- }
299
+ })
300
+ .then(this._initMap.bind(this))
301
+ .catch(error => {
302
+ console.warn(
303
+ '<pb-leaflet-map> Failed to load geocoding script, initializing map without geocoding:',
304
+ error,
305
+ );
306
+ this._initMap();
307
+ });
308
+ } else {
309
+ this._initMap();
310
+ }
311
+ };
312
+
313
+ window.ESGlobalBridge.instance
314
+ .load('leaflet', leafletPath)
315
+ .then(() => {
316
+ if (this.cluster) {
317
+ window.ESGlobalBridge.instance
318
+ .load('plugin', pluginPath)
319
+ .then(loadGeocodingOrInit)
320
+ .catch(error => {
321
+ console.warn(
322
+ '<pb-leaflet-map> Failed to load marker cluster plugin, initializing without clustering:',
323
+ error,
324
+ );
325
+ loadGeocodingOrInit();
371
326
  });
372
- L.control.closeButton = (options) => new L.Control.CloseButton(options);
373
- L.control.closeButton({ position: 'topright' }).addTo(this._map);
327
+ } else {
328
+ loadGeocodingOrInit();
374
329
  }
375
-
376
- this._configureGeoCoding();
330
+ })
331
+ .catch(error => {
332
+ console.error('<pb-leaflet-map> Failed to load Leaflet library:', error);
333
+ });
334
+ }
335
+
336
+ render() {
337
+ const cssPath = resolveURL(this.cssPath);
338
+ return html`
339
+ <link rel="Stylesheet" href="${cssPath}/leaflet.css" />
340
+ <link rel="Stylesheet" href="${cssPath}/MarkerCluster.Default.css" />
341
+ ${this.geoCoding
342
+ ? html`<link rel="Stylesheet" href="${cssPath}/Control.Geocoder.css" />`
343
+ : null}
344
+ <div id="map" style="height: 100%; width: 100%"></div>
345
+ `;
346
+ }
347
+
348
+ static get styles() {
349
+ return css`
350
+ :host {
351
+ display: block;
352
+ }
353
+
354
+ :host([disabled]) {
355
+ visibility: hidden;
356
+ }
357
+
358
+ .close {
359
+ border-radius: 4px;
360
+ background-color: #fff;
361
+ color: inherit;
362
+ padding: 8px;
363
+ font-size: 18px;
364
+ font-weight: bold;
365
+ text-decoration: none;
366
+ cursor: pointer;
367
+ }
368
+ `;
369
+ }
370
+
371
+ _initMap() {
372
+ if (this._map) {
373
+ return;
377
374
  }
378
375
 
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
- });
376
+ L.Icon.Default.imagePath = resolveURL(this.imagesPath);
377
+
378
+ const crs = L.CRS[this.crs] || L.CRS.EPSG3857;
379
+ this._map = L.map(this.shadowRoot.getElementById('map'), {
380
+ zoom: this.zoom,
381
+ center: L.latLng(this.latitude, this.longitude),
382
+ crs,
383
+ });
384
+ this._configureLayers();
385
+ this._configureMarkers();
386
+
387
+ if (this.cluster && typeof L.markerClusterGroup === 'function') {
388
+ const options = {};
389
+ if (this.disableClusteringAt) options.disableClusteringAtZoom = this.disableClusteringAt;
390
+ this._markerLayer = L.markerClusterGroup(options);
391
+ } else {
392
+ this._markerLayer = L.layerGroup();
393
+ }
394
+ this._markerLayer.addTo(this._map);
395
+ this._mapReady = true;
396
+
397
+ this.signalReady();
398
+
399
+ L.control.scale().addTo(this._map);
400
+
401
+ if (this.toggle) {
402
+ let container;
403
+ L.Control.CloseButton = L.Control.extend({
404
+ options: {
405
+ position: 'topright',
406
+ },
407
+ onAdd: map => {
408
+ container = L.DomUtil.create('div');
409
+ container.className = 'close';
410
+ container.innerHTML = 'X';
411
+ L.DomEvent.on(container, 'click', this._hide.bind(this));
412
+ return container;
413
+ },
414
+ onRemove: map => {
415
+ L.DomEvent.off(container, 'click', this._hide.bind(this));
416
+ },
417
+ });
418
+ L.control.closeButton = options => new L.Control.CloseButton(options);
419
+ L.control.closeButton({ position: 'topright' }).addTo(this._map);
427
420
  }
428
421
 
429
- _configureMarkers() {
430
- if (this._markers.length === 0) {
431
- return;
432
- }
422
+ this._configureGeoCoding();
423
+ }
433
424
 
434
- this._icons = {};
435
- this._markers.forEach(config => {
436
- if (config.iconUrl) {
437
- this._icons[config.name] = L.icon(config.options);
438
- }
439
- })
425
+ _configureGeoCoding() {
426
+ if (!this.geoCoding) {
427
+ return;
440
428
  }
441
429
 
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
- }
469
- });
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;
430
+ // Check if geocoding library is properly loaded
431
+ if (!L.Control || !L.Control.Geocoder) {
432
+ console.warn(
433
+ '<pb-leaflet-map> Geocoding library not properly loaded, skipping geocoding configuration',
434
+ );
435
+ return;
475
436
  }
476
437
 
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
- }
438
+ // Check if nominatim method exists
439
+ if (!L.Control.Geocoder.nominatim) {
440
+ console.warn(
441
+ '<pb-leaflet-map> Nominatim geocoder not available, skipping geocoding configuration',
442
+ );
443
+ return;
488
444
  }
489
445
 
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;
446
+ const geocoder = L.Control.Geocoder.nominatim({
447
+ geocodingQueryParams: {
448
+ 'accept-language': 'en',
449
+ },
450
+ });
451
+ const control = L.Control.geocoder({
452
+ defaultMarkGeocode: false,
453
+ geocoder,
454
+ placeholder: i18n('search.search'),
455
+ suggestMinLength: 3,
456
+ });
457
+ control.on('markgeocode', e => {
458
+ const { geocode } = e;
459
+ const options = {
460
+ coordinates: {
461
+ longitude: geocode.center.lng,
462
+ latitude: geocode.center.lat,
463
+ },
464
+ name: geocode.name,
465
+ label: geocode.html,
466
+ properties: geocode.properties,
467
+ };
468
+ this.emitTo('pb-geocode', options);
469
+ });
470
+ control.addTo(this._map);
471
+
472
+ this._map.on('click', e => {
473
+ if (e.originalEvent.ctrlKey || e.originalEvent.metaKey) {
474
+ e.originalEvent.stopPropagation();
475
+ geocoder.reverse(e.latlng, this._map.options.crs.scale(this._map.getZoom()), results => {
476
+ const geocode = results[0];
477
+ const options = {
478
+ coordinates: {
479
+ longitude: e.latlng.lng,
480
+ latitude: e.latlng.lat,
481
+ },
482
+ name: geocode.name,
483
+ label: geocode.html,
484
+ properties: geocode.properties,
485
+ };
486
+ this.emitTo('pb-geocode', options);
499
487
  });
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
- }
488
+ }
489
+ });
490
+ }
491
+
492
+ _configureMarkers() {
493
+ if (this._markers.length === 0) {
494
+ return;
507
495
  }
508
496
 
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
- }
497
+ this._icons = {};
498
+ this._markers.forEach(config => {
499
+ if (config.iconUrl) {
500
+ this._icons[config.name] = L.icon(config.options);
501
+ }
502
+ });
503
+ }
504
+
505
+ _configureLayers() {
506
+ if (this._layers.length === 0) {
507
+ // configure a default layer
508
+ L.tileLayer(
509
+ 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token={accessToken}',
510
+ {
511
+ attribution:
512
+ '&copy; <a href="https://www.mapbox.com/about/maps/">Mapbox</a> &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank" rel="noopener">Improve this map</a></strong>',
513
+ maxZoom: 18,
514
+ zoomOffset: -1,
515
+ tileSize: 512,
516
+ accessToken: this.accessToken,
517
+ },
518
+ ).addTo(this._map);
519
+ return;
537
520
  }
521
+ const layers = L.control.layers(null, null, { collapsed: true });
522
+ this._layers.forEach(config => {
523
+ let layer;
524
+ switch (config.type) {
525
+ case 'geojson':
526
+ config.data().then(data => {
527
+ layer = L.geoJSON([data]);
528
+ this._addLayer(config, layer, layers);
529
+ });
530
+ break;
531
+ default:
532
+ layer = L.tileLayer(config.url, config.options);
533
+ this._addLayer(config, layer, layers);
534
+ break;
535
+ }
536
+ });
537
+ // only show layer control if there's more than one layer
538
+ if (this._layers.length > 1) {
539
+ layers.addTo(this._map);
540
+ }
541
+ this._layers = null;
542
+ }
538
543
 
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;
544
+ _addLayer(config, layer, layers) {
545
+ if (config.show) {
546
+ layer.addTo(this._map);
548
547
  }
548
+ if (config.label) {
549
+ if (config.base) {
550
+ layers.addBaseLayer(layer, config.label);
551
+ } else {
552
+ layers.addOverlay(layer, config.label);
553
+ }
554
+ }
555
+ }
549
556
 
550
- _hide() {
551
- this.disabled = true;
557
+ _fitBounds() {
558
+ if (!this._markerLayer) return;
559
+ if (!this.fitMarkers) {
560
+ return;
561
+ }
562
+ const bounds = L.latLngBounds();
563
+ let len = 0;
564
+ this._markerLayer.eachLayer(layer => {
565
+ bounds.extend(layer.getLatLng());
566
+ len += 1;
567
+ });
568
+ if (len === 0) {
569
+ this._map.fitWorld();
570
+ } else if (len === 1) {
571
+ this._map.fitBounds(bounds, { maxZoom: this.zoom });
572
+ } else {
573
+ this._map.fitBounds(bounds);
574
+ }
575
+ }
576
+
577
+ _locationChanged(lat, long, zoom, setActive) {
578
+ if (!this._markerLayer) return;
579
+ if (this._map) {
580
+ const coords = L.latLng([lat, long]);
581
+ this._markerLayer.eachLayer(layer => {
582
+ if (layer.getLatLng().equals(coords)) {
583
+ if (zoom && !this.noScroll) {
584
+ layer.openTooltip();
585
+ this._map.setView(coords, zoom);
586
+ } else if (this.cluster) {
587
+ this._markerLayer.zoomToShowLayer(layer, () => layer.openTooltip());
588
+ } else {
589
+ layer.openTooltip();
590
+ if (zoom) {
591
+ this._map.setView(coords, zoom);
592
+ } else {
593
+ this._map.panTo(coords);
594
+ }
595
+ }
596
+ if (setActive && this._icons && this._icons.active) {
597
+ layer.setIcon(this._icons.active);
598
+ }
599
+ } else if (this._icons && this._icons.default && layer.getIcon() !== this._icons.default) {
600
+ layer.setIcon(this._icons.default);
601
+ }
602
+ });
552
603
  }
604
+ }
605
+
606
+ _hasMarker(lat, long) {
607
+ if (!this._markerLayer) return null;
608
+ const coords = L.latLng([lat, long]);
609
+ let found = null;
610
+ this._markerLayer.eachLayer(layer => {
611
+ if (layer instanceof L.Marker && layer.getLatLng().equals(coords)) {
612
+ found = layer;
613
+ }
614
+ });
615
+ return found;
616
+ }
617
+
618
+ _hide() {
619
+ this.disabled = true;
620
+ }
553
621
  }
554
- customElements.define('pb-leaflet-map', PbLeafletMap);
622
+ customElements.define('pb-leaflet-map', PbLeafletMap);