@geolonia/embed 2.1.4 → 2.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geolonia/embed",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "description": "Geolonia embed JS API",
5
5
  "main": "dist/embed.js",
6
6
  "types": "src/embed.d.ts",
@@ -50,6 +50,7 @@
50
50
  "@geolonia/mbgl-geolonia-control": "^0.4.2",
51
51
  "@geolonia/mbgl-gesture-handling": "^1.0.15",
52
52
  "@mapbox/geojson-extent": "^0.3.2",
53
+ "@mapbox/point-geometry": "^0.1.0",
53
54
  "@turf/center": "^6.0.1",
54
55
  "core-js": "^3.6.5",
55
56
  "intersection-observer": "^0.5.1",
package/src/embed.js CHANGED
@@ -13,7 +13,7 @@ import * as util from './lib/util';
13
13
  import parseAtts from './lib/parse-atts';
14
14
  import parseApiKey from './lib/parse-api-key';
15
15
  import pkg from '../package.json';
16
- import simpleStyle from './lib/simplestyle';
16
+ import SimpleStyle from './lib/simplestyle';
17
17
 
18
18
  if ( util.checkPermission() ) {
19
19
  let isDOMContentLoaded = false;
@@ -88,7 +88,9 @@ if ( util.checkPermission() ) {
88
88
  }
89
89
 
90
90
  window.geolonia.Map = GeoloniaMap;
91
- window.geolonia.simpleStyle = simpleStyle;
91
+ window.geolonia.simpleStyle = // backward compatibility
92
+ window.geolonia.SimpleStyle =
93
+ SimpleStyle;
92
94
  window.geolonia.Marker = GeoloniaMarker;
93
95
  window.geolonia.AmazonLocationServiceMapProvider = AmazonLocationServiceMapProvider;
94
96
  window.geolonia.embedVersion = pkg.version;
@@ -0,0 +1,319 @@
1
+ import { DOM, bindAll } from './maplibre-util';
2
+
3
+ /**
4
+ * This class is a copy of maplibre-gl-js's AttributionControl class and rewrite by shadow DOM.
5
+ * https://github.com/maplibre/maplibre-gl-js/blob/main/src/ui/control/attribution_control.ts
6
+ */
7
+
8
+ class CustomAttributionControl {
9
+
10
+ constructor(options = {}) {
11
+ this.options = options;
12
+ this._map;
13
+ this._compact;
14
+ this._container;
15
+ this._shadowContainer;
16
+ this._innerContainer;
17
+ this._compactButton;
18
+ this._editLink;
19
+ this._attribHTML;
20
+ this.styleId;
21
+ this.styleOwner;
22
+
23
+ bindAll([
24
+ '_toggleAttribution',
25
+ '_updateData',
26
+ '_updateCompact',
27
+ '_updateCompactMinimize',
28
+ ], this);
29
+ }
30
+
31
+ getDefaultPosition() {
32
+ return 'bottom-right';
33
+ }
34
+
35
+ onAdd(map) {
36
+ this._map = map;
37
+ this._compact = this.options && this.options.compact;
38
+ this._container = DOM.create('div');
39
+
40
+ const shadow = this._container.attachShadow({mode: 'open'});
41
+
42
+ this._shadowContainer = DOM.create('details', 'maplibregl-ctrl maplibregl-ctrl-attrib');
43
+ this._compactButton = DOM.create('summary', 'maplibregl-ctrl-attrib-button', this._shadowContainer);
44
+ this._compactButton.addEventListener('click', this._toggleAttribution);
45
+ this._setElementTitle(this._compactButton, 'ToggleAttribution');
46
+ this._innerContainer = DOM.create('div', 'maplibregl-ctrl-attrib-inner', this._shadowContainer);
47
+
48
+ const style = document.createElement('style');
49
+ style.textContent = `
50
+ .maplibregl-ctrl {
51
+ clear: both;
52
+ pointer-events: auto;
53
+ transform: translate(0);
54
+ }
55
+ .maplibregl-ctrl-attrib-button:focus,.maplibregl-ctrl-group button:focus {
56
+ box-shadow: 0 0 2px 2px #0096ff
57
+ }
58
+ .maplibregl-ctrl.maplibregl-ctrl-attrib {
59
+ background-color: hsla(0,0%,100%,.5);
60
+ margin: 0;
61
+ padding: 0 5px
62
+ }
63
+
64
+ @media screen {
65
+ .maplibregl-ctrl-attrib.maplibregl-compact {
66
+ background-color: #fff;
67
+ border-radius: 12px;
68
+ box-sizing: content-box;
69
+ min-height: 20px;
70
+ padding: 2px 24px 2px 0;
71
+ position: relative;
72
+ margin: 10px 10px 10px auto;
73
+ width: 0;
74
+ }
75
+
76
+ .maplibregl-ctrl-attrib.maplibregl-compact-show {
77
+ padding: 2px 28px 2px 8px;
78
+ visibility: visible;
79
+ width: auto;
80
+ }
81
+
82
+ .maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact-show,.maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact-show {
83
+ border-radius: 12px;
84
+ padding: 2px 8px 2px 28px
85
+ }
86
+
87
+ .maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-inner {
88
+ display: none
89
+ }
90
+
91
+ .maplibregl-ctrl-attrib-button {
92
+ background-color: hsla(0,0%,100%,.5);
93
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='24' height='24' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E");
94
+ border: 0;
95
+ border-radius: 12px;
96
+ box-sizing: border-box;
97
+ cursor: pointer;
98
+ display: none;
99
+ height: 24px;
100
+ outline: none;
101
+ position: absolute;
102
+ right: 0;
103
+ top: 0;
104
+ width: 24px
105
+ }
106
+
107
+ .maplibregl-ctrl-attrib summary.maplibregl-ctrl-attrib-button {
108
+ appearance: none;
109
+ list-style: none
110
+ }
111
+
112
+ .maplibregl-ctrl-attrib summary.maplibregl-ctrl-attrib-button::-webkit-details-marker {
113
+ display: none
114
+ }
115
+
116
+ .maplibregl-ctrl-bottom-left .maplibregl-ctrl-attrib-button,.maplibregl-ctrl-top-left .maplibregl-ctrl-attrib-button {
117
+ left: 0
118
+ }
119
+
120
+ .maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-button,.maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-inner {
121
+ display: block
122
+ }
123
+
124
+ .maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-button {
125
+ background-color: rgb(0 0 0/5%)
126
+ }
127
+
128
+ .maplibregl-ctrl-bottom-right>.maplibregl-ctrl-attrib.maplibregl-compact:after {
129
+ bottom: 0;
130
+ right: 0
131
+ }
132
+
133
+ .maplibregl-ctrl-top-right>.maplibregl-ctrl-attrib.maplibregl-compact:after {
134
+ right: 0;
135
+ top: 0
136
+ }
137
+
138
+ .maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact:after {
139
+ left: 0;
140
+ top: 0
141
+ }
142
+
143
+ .maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact:after {
144
+ bottom: 0;
145
+ left: 0
146
+ }
147
+ }
148
+
149
+ @media screen and (-ms-high-contrast:active) {
150
+ .maplibregl-ctrl-attrib.maplibregl-compact:after {
151
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='24' height='24' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' fill='%23fff'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E")
152
+ }
153
+ }
154
+
155
+ @media screen and (-ms-high-contrast:black-on-white) {
156
+ .maplibregl-ctrl-attrib.maplibregl-compact:after {
157
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='24' height='24' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E")
158
+ }
159
+ }
160
+
161
+ .maplibregl-ctrl-attrib a {
162
+ color: rgba(0,0,0,.75);
163
+ text-decoration: none;
164
+ white-space: nowrap;
165
+ }
166
+
167
+ .maplibregl-ctrl-attrib a:hover {
168
+ color: inherit;
169
+ text-decoration: underline
170
+ }
171
+
172
+ .maplibregl-attrib-empty {
173
+ display: none
174
+ }
175
+ `;
176
+
177
+ this._updateAttributions();
178
+ this._updateCompact();
179
+
180
+ this._map.on('styledata', this._updateData);
181
+ this._map.on('sourcedata', this._updateData);
182
+ this._map.on('terrain', this._updateData);
183
+ this._map.on('resize', this._updateCompact);
184
+ this._map.on('drag', this._updateCompactMinimize);
185
+
186
+ shadow.appendChild(style);
187
+ shadow.appendChild(this._shadowContainer);
188
+
189
+ return this._container;
190
+ }
191
+
192
+ onRemove() {
193
+ DOM.remove(this._container);
194
+
195
+ this._map.off('styledata', this._updateData);
196
+ this._map.off('sourcedata', this._updateData);
197
+ this._map.off('terrain', this._updateData);
198
+ this._map.off('resize', this._updateCompact);
199
+ this._map.off('drag', this._updateCompactMinimize);
200
+
201
+ this._map = undefined;
202
+ this._compact = undefined;
203
+ this._attribHTML = undefined;
204
+ }
205
+
206
+ _setElementTitle(element, title) {
207
+ const str = this._map._getUIString(`AttributionControl.${title}`);
208
+ element.title = str;
209
+ element.setAttribute('aria-label', str);
210
+ }
211
+
212
+ _toggleAttribution() {
213
+ if (this._shadowContainer.classList.contains('maplibregl-compact')) {
214
+ if (this._shadowContainer.classList.contains('maplibregl-compact-show')) {
215
+ this._shadowContainer.setAttribute('open', '');
216
+ this._shadowContainer.classList.remove('maplibregl-compact-show');
217
+ } else {
218
+ this._shadowContainer.classList.add('maplibregl-compact-show');
219
+ this._shadowContainer.removeAttribute('open');
220
+ }
221
+ }
222
+ }
223
+
224
+ _updateData(e) {
225
+ if (e && (e.sourceDataType === 'metadata' || e.sourceDataType === 'visibility' || e.dataType === 'style' || e.type === 'terrain')) {
226
+ this._updateAttributions();
227
+ }
228
+ }
229
+
230
+ _updateAttributions() {
231
+ if (!this._map.style) return;
232
+ let attributions = [];
233
+ if (this.options.customAttribution) {
234
+ if (Array.isArray(this.options.customAttribution)) {
235
+ attributions = attributions.concat(
236
+ this.options.customAttribution.map((attribution) => {
237
+ if (typeof attribution !== 'string') return '';
238
+ return attribution;
239
+ }),
240
+ );
241
+ } else if (typeof this.options.customAttribution === 'string') {
242
+ attributions.push(this.options.customAttribution);
243
+ }
244
+ }
245
+
246
+ if (this._map.style.stylesheet) {
247
+ const stylesheet = this._map.style.stylesheet;
248
+ this.styleOwner = stylesheet.owner;
249
+ this.styleId = stylesheet.id;
250
+ }
251
+
252
+ const sourceCaches = this._map.style.sourceCaches;
253
+ for (const id in sourceCaches) {
254
+ const sourceCache = sourceCaches[id];
255
+ if (sourceCache.used || sourceCache.usedForTerrain) {
256
+ const source = sourceCache.getSource();
257
+ if (source.attribution && attributions.indexOf(source.attribution) < 0) {
258
+ attributions.push(source.attribution);
259
+ }
260
+ }
261
+ }
262
+
263
+ // remove any entries that are whitespace
264
+ attributions = attributions.filter((e) => String(e).trim());
265
+
266
+ // remove any entries that are substrings of another entry.
267
+ // first sort by length so that substrings come first
268
+ attributions.sort((a, b) => a.length - b.length);
269
+ attributions = attributions.filter((attrib, i) => {
270
+ for (let j = i + 1; j < attributions.length; j++) {
271
+ if (attributions[j].indexOf(attrib) >= 0) { return false; }
272
+ }
273
+ return true;
274
+ });
275
+
276
+ // check if attribution string is different to minimize DOM changes
277
+ const attribHTML = attributions.join(' | ');
278
+ if (attribHTML === this._attribHTML) return;
279
+
280
+ this._attribHTML = attribHTML;
281
+
282
+ if (attributions.length) {
283
+ this._innerContainer.innerHTML = attribHTML;
284
+ this._shadowContainer.classList.remove('maplibregl-attrib-empty');
285
+ } else {
286
+ this._shadowContainer.classList.add('maplibregl-attrib-empty');
287
+ }
288
+ this._updateCompact();
289
+ // remove old DOM node from _editLink
290
+ this._editLink = null;
291
+ }
292
+
293
+ _updateCompact() {
294
+ if (this._map.getCanvasContainer().offsetWidth <= 640 || this._compact) {
295
+ if (this._compact === false) {
296
+ this._shadowContainer.setAttribute('open', '');
297
+ } else if (!this._shadowContainer.classList.contains('maplibregl-compact') && !this._shadowContainer.classList.contains('maplibregl-attrib-empty')) {
298
+ this._shadowContainer.setAttribute('open', '');
299
+ this._shadowContainer.classList.add('maplibregl-compact', 'maplibregl-compact-show');
300
+ }
301
+ } else {
302
+ this._shadowContainer.setAttribute('open', '');
303
+ if (this._shadowContainer.classList.contains('maplibregl-compact')) {
304
+ this._shadowContainer.classList.remove('maplibregl-compact', 'maplibregl-compact-show');
305
+ }
306
+ }
307
+ }
308
+
309
+ _updateCompactMinimize() {
310
+ if (this._shadowContainer.classList.contains('maplibregl-compact')) {
311
+ if (this._shadowContainer.classList.contains('maplibregl-compact-show')) {
312
+ this._shadowContainer.classList.remove('maplibregl-compact-show');
313
+ }
314
+ }
315
+ }
316
+
317
+ }
318
+
319
+ export default CustomAttributionControl;
@@ -2,6 +2,7 @@ import 'whatwg-fetch';
2
2
  import 'promise-polyfill/src/polyfill';
3
3
  import maplibregl from 'maplibre-gl';
4
4
  import GeoloniaControl from '@geolonia/mbgl-geolonia-control';
5
+ import CustomAttributionControl from './CustomAttributionControl';
5
6
  import GestureHandling from '@geolonia/mbgl-gesture-handling';
6
7
  import parseAtts from './parse-atts';
7
8
 
@@ -128,6 +129,8 @@ export default class GeoloniaMap extends maplibregl.Map {
128
129
  const { position: geoloniaControlPosition } = util.parseControlOption(atts.geoloniaControl);
129
130
  map.addControl(new GeoloniaControl(), geoloniaControlPosition);
130
131
 
132
+ map.addControl(new CustomAttributionControl(), 'bottom-right');
133
+
131
134
  const { enabled: fullscreenControlEnabled, position: fullscreenControlPosition } = util.parseControlOption(atts.fullscreenControl);
132
135
  if (fullscreenControlEnabled) {
133
136
  // IE patch for fullscreen mode
@@ -0,0 +1,125 @@
1
+ import Point from '@mapbox/point-geometry';
2
+
3
+ /**
4
+ * This class is a copy of maplibre-gl-js's util DOM class and rewrite it to JavaScript.
5
+ * https://github.com/maplibre/maplibre-gl-js/blob/main/src/util/dom.ts
6
+ * */
7
+ export class DOM {
8
+ static #docStyle = typeof window !== 'undefined' && window.document && window.document.documentElement.style;
9
+
10
+ static #userSelect;
11
+
12
+ static #selectProp = DOM.testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']);
13
+
14
+ static #transformProp = DOM.testProp(['transform', 'WebkitTransform']);
15
+
16
+ static testProp(props) {
17
+ if (!DOM['#docStyle']) return props[0];
18
+ for (let i = 0; i < props.length; i++) {
19
+ if (props[i] in DOM['#docStyle']) {
20
+ return props[i];
21
+ }
22
+ }
23
+ return props[0];
24
+ }
25
+
26
+ static create(tagName, className, container) {
27
+ const el = window.document.createElement(tagName);
28
+ if (className !== undefined) el.className = className;
29
+ if (container) container.appendChild(el);
30
+ return el;
31
+ }
32
+
33
+ static createNS(namespaceURI, tagName) {
34
+ const el = window.document.createElementNS(namespaceURI, tagName);
35
+ return el;
36
+ }
37
+
38
+ static disableDrag() {
39
+ if (DOM['#docStyle'] && DOM['#selectProp']) {
40
+ DOM['#userSelect'] = DOM['#docStyle'][DOM['#selectProp']];
41
+ DOM['#docStyle'][DOM['#selectProp']] = 'none';
42
+ }
43
+ }
44
+
45
+ static enableDrag() {
46
+ if (DOM['#docStyle'] && DOM['#selectProp']) {
47
+ DOM['#docStyle'][DOM['#selectProp']] = DOM['#userSelect'];
48
+ }
49
+ }
50
+
51
+ static setTransform(el, value) {
52
+ el.style[DOM['#transformProp']] = value;
53
+ }
54
+
55
+ static addEventListener(target, type, callback, options) {
56
+ if ('passive' in options) {
57
+ target.addEventListener(type, callback, options);
58
+ } else {
59
+ target.addEventListener(type, callback, options.capture);
60
+ }
61
+ }
62
+
63
+ static removeEventListener(target, type, callback, options) {
64
+ if ('passive' in options) {
65
+ target.removeEventListener(type, callback, options);
66
+ } else {
67
+ target.removeEventListener(type, callback, options.capture);
68
+ }
69
+ }
70
+
71
+ // Suppress the next click, but only if it's immediate.
72
+ static #suppressClickInternal(e) {
73
+ e.preventDefault();
74
+ e.stopPropagation();
75
+ window.removeEventListener('click', DOM['#transformProp'], true);
76
+ }
77
+
78
+ static suppressClick() {
79
+ window.addEventListener('click', DOM['#transformProp'], true);
80
+ window.setTimeout(() => {
81
+ window.removeEventListener('click', DOM['#transformProp'], true);
82
+ }, 0);
83
+ }
84
+
85
+ static mousePos(el, e) {
86
+ const rect = el.getBoundingClientRect();
87
+ return new Point(
88
+ e.clientX - rect.left - el.clientLeft,
89
+ e.clientY - rect.top - el.clientTop,
90
+ );
91
+ }
92
+
93
+ static touchPos(el, touches) {
94
+ const rect = el.getBoundingClientRect();
95
+ const points = [];
96
+ for (let i = 0; i < touches.length; i++) {
97
+ points.push(new Point(
98
+ touches[i].clientX - rect.left - el.clientLeft,
99
+ touches[i].clientY - rect.top - el.clientTop,
100
+ ));
101
+ }
102
+ return points;
103
+ }
104
+
105
+ static mouseButton(e) {
106
+ return e.button;
107
+ }
108
+
109
+ static remove(node) {
110
+ if (node.parentNode) {
111
+ node.parentNode.removeChild(node);
112
+ }
113
+ }
114
+ }
115
+
116
+ /**
117
+ * This function is a copy of maplibre-gl-js's util function and rewrite it to JavaScript.
118
+ * https://github.com/maplibre/maplibre-gl-js/blob/main/src/util/util.ts#L223-L228
119
+ * */
120
+ export function bindAll(fns, context) {
121
+ fns.forEach((fn) => {
122
+ if (!context[fn]) { return; }
123
+ context[fn] = context[fn].bind(context);
124
+ });
125
+ }
package/src/lib/util.js CHANGED
@@ -201,7 +201,7 @@ export function getOptions(container, params, atts) {
201
201
  zoom: parseFloat(atts.zoom),
202
202
  hash: (atts.hash === 'on'),
203
203
  localIdeographFontFamily: 'sans-serif',
204
- attributionControl: true,
204
+ attributionControl: false,
205
205
  };
206
206
 
207
207
  if (atts.minZoom !== '' && (Number(atts.minZoom) === 0 || Number(atts.minZoom))) {