@geolonia/embed 2.1.4 → 2.1.5

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.5",
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,317 @@
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
+ margin: 10px;
70
+ min-height: 20px;
71
+ padding: 2px 24px 2px 0;
72
+ position: relative
73
+ }
74
+
75
+ .maplibregl-ctrl-attrib.maplibregl-compact-show {
76
+ padding: 2px 28px 2px 8px;
77
+ visibility: visible
78
+ }
79
+
80
+ .maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact-show,.maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact-show {
81
+ border-radius: 12px;
82
+ padding: 2px 8px 2px 28px
83
+ }
84
+
85
+ .maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-inner {
86
+ display: none
87
+ }
88
+
89
+ .maplibregl-ctrl-attrib-button {
90
+ background-color: hsla(0,0%,100%,.5);
91
+ 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");
92
+ border: 0;
93
+ border-radius: 12px;
94
+ box-sizing: border-box;
95
+ cursor: pointer;
96
+ display: none;
97
+ height: 24px;
98
+ outline: none;
99
+ position: absolute;
100
+ right: 0;
101
+ top: 0;
102
+ width: 24px
103
+ }
104
+
105
+ .maplibregl-ctrl-attrib summary.maplibregl-ctrl-attrib-button {
106
+ appearance: none;
107
+ list-style: none
108
+ }
109
+
110
+ .maplibregl-ctrl-attrib summary.maplibregl-ctrl-attrib-button::-webkit-details-marker {
111
+ display: none
112
+ }
113
+
114
+ .maplibregl-ctrl-bottom-left .maplibregl-ctrl-attrib-button,.maplibregl-ctrl-top-left .maplibregl-ctrl-attrib-button {
115
+ left: 0
116
+ }
117
+
118
+ .maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-button,.maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-inner {
119
+ display: block
120
+ }
121
+
122
+ .maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-button {
123
+ background-color: rgb(0 0 0/5%)
124
+ }
125
+
126
+ .maplibregl-ctrl-bottom-right>.maplibregl-ctrl-attrib.maplibregl-compact:after {
127
+ bottom: 0;
128
+ right: 0
129
+ }
130
+
131
+ .maplibregl-ctrl-top-right>.maplibregl-ctrl-attrib.maplibregl-compact:after {
132
+ right: 0;
133
+ top: 0
134
+ }
135
+
136
+ .maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact:after {
137
+ left: 0;
138
+ top: 0
139
+ }
140
+
141
+ .maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact:after {
142
+ bottom: 0;
143
+ left: 0
144
+ }
145
+ }
146
+
147
+ @media screen and (-ms-high-contrast:active) {
148
+ .maplibregl-ctrl-attrib.maplibregl-compact:after {
149
+ 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")
150
+ }
151
+ }
152
+
153
+ @media screen and (-ms-high-contrast:black-on-white) {
154
+ .maplibregl-ctrl-attrib.maplibregl-compact:after {
155
+ 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")
156
+ }
157
+ }
158
+
159
+ .maplibregl-ctrl-attrib a {
160
+ color: rgba(0,0,0,.75);
161
+ text-decoration: none;
162
+ white-space: nowrap;
163
+ }
164
+
165
+ .maplibregl-ctrl-attrib a:hover {
166
+ color: inherit;
167
+ text-decoration: underline
168
+ }
169
+
170
+ .maplibregl-attrib-empty {
171
+ display: none
172
+ }
173
+ `;
174
+
175
+ this._updateAttributions();
176
+ this._updateCompact();
177
+
178
+ this._map.on('styledata', this._updateData);
179
+ this._map.on('sourcedata', this._updateData);
180
+ this._map.on('terrain', this._updateData);
181
+ this._map.on('resize', this._updateCompact);
182
+ this._map.on('drag', this._updateCompactMinimize);
183
+
184
+ shadow.appendChild(style);
185
+ shadow.appendChild(this._shadowContainer);
186
+
187
+ return this._container;
188
+ }
189
+
190
+ onRemove() {
191
+ DOM.remove(this._container);
192
+
193
+ this._map.off('styledata', this._updateData);
194
+ this._map.off('sourcedata', this._updateData);
195
+ this._map.off('terrain', this._updateData);
196
+ this._map.off('resize', this._updateCompact);
197
+ this._map.off('drag', this._updateCompactMinimize);
198
+
199
+ this._map = undefined;
200
+ this._compact = undefined;
201
+ this._attribHTML = undefined;
202
+ }
203
+
204
+ _setElementTitle(element, title) {
205
+ const str = this._map._getUIString(`AttributionControl.${title}`);
206
+ element.title = str;
207
+ element.setAttribute('aria-label', str);
208
+ }
209
+
210
+ _toggleAttribution() {
211
+ if (this._shadowContainer.classList.contains('maplibregl-compact')) {
212
+ if (this._shadowContainer.classList.contains('maplibregl-compact-show')) {
213
+ this._shadowContainer.setAttribute('open', '');
214
+ this._shadowContainer.classList.remove('maplibregl-compact-show');
215
+ } else {
216
+ this._shadowContainer.classList.add('maplibregl-compact-show');
217
+ this._shadowContainer.removeAttribute('open');
218
+ }
219
+ }
220
+ }
221
+
222
+ _updateData(e) {
223
+ if (e && (e.sourceDataType === 'metadata' || e.sourceDataType === 'visibility' || e.dataType === 'style' || e.type === 'terrain')) {
224
+ this._updateAttributions();
225
+ }
226
+ }
227
+
228
+ _updateAttributions() {
229
+ if (!this._map.style) return;
230
+ let attributions = [];
231
+ if (this.options.customAttribution) {
232
+ if (Array.isArray(this.options.customAttribution)) {
233
+ attributions = attributions.concat(
234
+ this.options.customAttribution.map((attribution) => {
235
+ if (typeof attribution !== 'string') return '';
236
+ return attribution;
237
+ }),
238
+ );
239
+ } else if (typeof this.options.customAttribution === 'string') {
240
+ attributions.push(this.options.customAttribution);
241
+ }
242
+ }
243
+
244
+ if (this._map.style.stylesheet) {
245
+ const stylesheet = this._map.style.stylesheet;
246
+ this.styleOwner = stylesheet.owner;
247
+ this.styleId = stylesheet.id;
248
+ }
249
+
250
+ const sourceCaches = this._map.style.sourceCaches;
251
+ for (const id in sourceCaches) {
252
+ const sourceCache = sourceCaches[id];
253
+ if (sourceCache.used || sourceCache.usedForTerrain) {
254
+ const source = sourceCache.getSource();
255
+ if (source.attribution && attributions.indexOf(source.attribution) < 0) {
256
+ attributions.push(source.attribution);
257
+ }
258
+ }
259
+ }
260
+
261
+ // remove any entries that are whitespace
262
+ attributions = attributions.filter((e) => String(e).trim());
263
+
264
+ // remove any entries that are substrings of another entry.
265
+ // first sort by length so that substrings come first
266
+ attributions.sort((a, b) => a.length - b.length);
267
+ attributions = attributions.filter((attrib, i) => {
268
+ for (let j = i + 1; j < attributions.length; j++) {
269
+ if (attributions[j].indexOf(attrib) >= 0) { return false; }
270
+ }
271
+ return true;
272
+ });
273
+
274
+ // check if attribution string is different to minimize DOM changes
275
+ const attribHTML = attributions.join(' | ');
276
+ if (attribHTML === this._attribHTML) return;
277
+
278
+ this._attribHTML = attribHTML;
279
+
280
+ if (attributions.length) {
281
+ this._innerContainer.innerHTML = attribHTML;
282
+ this._shadowContainer.classList.remove('maplibregl-attrib-empty');
283
+ } else {
284
+ this._shadowContainer.classList.add('maplibregl-attrib-empty');
285
+ }
286
+ this._updateCompact();
287
+ // remove old DOM node from _editLink
288
+ this._editLink = null;
289
+ }
290
+
291
+ _updateCompact() {
292
+ if (this._map.getCanvasContainer().offsetWidth <= 640 || this._compact) {
293
+ if (this._compact === false) {
294
+ this._shadowContainer.setAttribute('open', '');
295
+ } else if (!this._shadowContainer.classList.contains('maplibregl-compact') && !this._shadowContainer.classList.contains('maplibregl-attrib-empty')) {
296
+ this._shadowContainer.setAttribute('open', '');
297
+ this._shadowContainer.classList.add('maplibregl-compact', 'maplibregl-compact-show');
298
+ }
299
+ } else {
300
+ this._shadowContainer.setAttribute('open', '');
301
+ if (this._shadowContainer.classList.contains('maplibregl-compact')) {
302
+ this._shadowContainer.classList.remove('maplibregl-compact', 'maplibregl-compact-show');
303
+ }
304
+ }
305
+ }
306
+
307
+ _updateCompactMinimize() {
308
+ if (this._shadowContainer.classList.contains('maplibregl-compact')) {
309
+ if (this._shadowContainer.classList.contains('maplibregl-compact-show')) {
310
+ this._shadowContainer.classList.remove('maplibregl-compact-show');
311
+ }
312
+ }
313
+ }
314
+
315
+ }
316
+
317
+ 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))) {