@geolonia/embed 2.0.1 → 2.0.2-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/embed +1 -2
- package/dist/embed-chunks/21811c8ee88c2037c1dc.js +2 -0
- package/dist/{embed.js.LICENSE.txt → embed-chunks/21811c8ee88c2037c1dc.js.LICENSE.txt} +0 -0
- package/dist/embed-chunks/5ae1cbf5b6a878d13f8b.js +1 -0
- package/dist/embed.js +1 -2
- package/package.json +1 -1
- package/src/lib/geolonia-map.js +17 -15
- package/src/lib/simplestyle-vector.js +2 -2
- package/src/lib/simplestyle.js +16 -13
- package/src/lib/simplestyle.test.js +7 -8
- package/dist/embed-chunks/2e295cdb0214d17e9c48.js +0 -1
package/package.json
CHANGED
package/src/lib/geolonia-map.js
CHANGED
|
@@ -5,6 +5,9 @@ import GeoloniaControl from '@geolonia/mbgl-geolonia-control';
|
|
|
5
5
|
import GestureHandling from '@geolonia/mbgl-gesture-handling';
|
|
6
6
|
import parseAtts from './parse-atts';
|
|
7
7
|
|
|
8
|
+
import SimpleStyle from './simplestyle';
|
|
9
|
+
import SimpleStyleVector from './simplestyle-vector';
|
|
10
|
+
|
|
8
11
|
import * as util from './util';
|
|
9
12
|
|
|
10
13
|
const isCssSelector = (string) => {
|
|
@@ -200,28 +203,27 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
200
203
|
|
|
201
204
|
if (atts.simpleVector) {
|
|
202
205
|
const simpleVectorAttributeValue = util.parseSimpleVector(atts.simpleVector);
|
|
203
|
-
const { default: SimpleStyleVector } = await import('./simplestyle-vector');
|
|
204
206
|
new SimpleStyleVector(simpleVectorAttributeValue).addTo(map);
|
|
205
207
|
}
|
|
206
208
|
|
|
207
209
|
if (atts.geojson) {
|
|
208
210
|
const el = isCssSelector(atts.geojson);
|
|
209
|
-
|
|
211
|
+
let json;
|
|
210
212
|
if (el) {
|
|
211
|
-
|
|
212
|
-
new SimpleStyle(json, {
|
|
213
|
-
cluster: (atts.cluster === 'on'),
|
|
214
|
-
clusterColor: atts.clusterColor,
|
|
215
|
-
}).addTo(map);
|
|
213
|
+
json = JSON.parse(el.textContent);
|
|
216
214
|
} else {
|
|
217
|
-
fetch(atts.geojson)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
215
|
+
const response = await fetch(atts.geojson);
|
|
216
|
+
json = await response.json();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const ss = new SimpleStyle(json, {
|
|
220
|
+
cluster: (atts.cluster === 'on'),
|
|
221
|
+
clusterColor: atts.clusterColor,
|
|
222
|
+
});
|
|
223
|
+
ss.addTo(map);
|
|
224
|
+
|
|
225
|
+
if (!container.dataset || (!container.dataset.lng && !container.dataset.lat)) {
|
|
226
|
+
ss.fitBounds();
|
|
225
227
|
}
|
|
226
228
|
}
|
|
227
229
|
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import maplibregl from 'maplibre-gl';
|
|
4
4
|
import turfCenter from '@turf/center';
|
|
5
|
-
import sanitizeHtml from 'sanitize-html';
|
|
6
5
|
|
|
7
6
|
const textColor = '#000000';
|
|
8
7
|
const textHaloColor = '#FFFFFF';
|
|
@@ -204,7 +203,8 @@ class SimpleStyleVector {
|
|
|
204
203
|
this.setPopup(map, 'vt-circle-simple-style-points');
|
|
205
204
|
}
|
|
206
205
|
|
|
207
|
-
setPopup(map, source) {
|
|
206
|
+
async setPopup(map, source) {
|
|
207
|
+
const { default: sanitizeHtml } = await import('sanitize-html');
|
|
208
208
|
map.on('click', source, (e) => {
|
|
209
209
|
const center = turfCenter(e.features[0]).geometry.coordinates;
|
|
210
210
|
const description = e.features[0].properties.description;
|
package/src/lib/simplestyle.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import maplibregl from 'maplibre-gl';
|
|
4
4
|
import geojsonExtent from '@mapbox/geojson-extent';
|
|
5
5
|
import turfCenter from '@turf/center';
|
|
6
|
-
import sanitizeHtml from 'sanitize-html';
|
|
7
6
|
|
|
8
7
|
const textColor = '#000000';
|
|
9
8
|
const textHaloColor = '#FFFFFF';
|
|
@@ -19,8 +18,6 @@ class SimpleStyle {
|
|
|
19
18
|
cluster: true,
|
|
20
19
|
heatmap: false, // TODO: It should support heatmap.
|
|
21
20
|
clusterColor: '#ff0000',
|
|
22
|
-
duration: 3000,
|
|
23
|
-
padding: 30,
|
|
24
21
|
...options,
|
|
25
22
|
};
|
|
26
23
|
}
|
|
@@ -116,16 +113,21 @@ class SimpleStyle {
|
|
|
116
113
|
this.setPointGeometries();
|
|
117
114
|
this.setCluster();
|
|
118
115
|
|
|
119
|
-
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
120
118
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
119
|
+
fitBounds(options = {}) {
|
|
120
|
+
const _options = {
|
|
121
|
+
duration: 3000,
|
|
122
|
+
padding: 30,
|
|
123
|
+
...options,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const bounds = geojsonExtent(this.geojson);
|
|
127
|
+
if (bounds) {
|
|
128
|
+
window.requestAnimationFrame(() => {
|
|
129
|
+
this.map.fitBounds(bounds, _options);
|
|
130
|
+
});
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
return this;
|
|
@@ -231,7 +233,8 @@ class SimpleStyle {
|
|
|
231
233
|
this.setPopup(this.map, `${this.options.id}-circle-points`);
|
|
232
234
|
}
|
|
233
235
|
|
|
234
|
-
setPopup(map, source) {
|
|
236
|
+
async setPopup(map, source) {
|
|
237
|
+
const { default: sanitizeHtml } = await import('sanitize-html');
|
|
235
238
|
map.on('click', source, (e) => {
|
|
236
239
|
const center = turfCenter(e.features[0]).geometry.coordinates;
|
|
237
240
|
const description = e.features[0].properties.description;
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import assert from 'assert';
|
|
4
4
|
|
|
5
|
+
window.URL.createObjectURL = () => {}; // To prevent `TypeError: window.URL.createObjectURL is not a function`
|
|
6
|
+
window.requestAnimationFrame = (cb) => cb();
|
|
7
|
+
|
|
5
8
|
class Map {
|
|
6
9
|
constructor(json, options) {
|
|
7
10
|
this.json = json;
|
|
@@ -69,11 +72,10 @@ const geojson = {
|
|
|
69
72
|
|
|
70
73
|
describe('Tests for simpleStyle()', () => {
|
|
71
74
|
it('should has sources and layers as expected', async () => {
|
|
72
|
-
window.URL.createObjectURL = () => {}; // To prevent `TypeError: window.URL.createObjectURL is not a function`
|
|
73
75
|
const { default: simpleStyle } = await import('./simplestyle');
|
|
74
76
|
|
|
75
77
|
const map = new Map();
|
|
76
|
-
new simpleStyle(geojson).addTo(map);
|
|
78
|
+
new simpleStyle(geojson).addTo(map).fitBounds();
|
|
77
79
|
|
|
78
80
|
assert.deepEqual([ 'geolonia-simple-style', 'geolonia-simple-style-points' ], Object.keys(map.sources));
|
|
79
81
|
assert.deepEqual(8, map.layers.length);
|
|
@@ -81,11 +83,10 @@ describe('Tests for simpleStyle()', () => {
|
|
|
81
83
|
});
|
|
82
84
|
|
|
83
85
|
it('should has sources and layers as expected with custom IDs', async () => {
|
|
84
|
-
window.URL.createObjectURL = () => {}; // To prevent `TypeError: window.URL.createObjectURL is not a function`
|
|
85
86
|
const { default: simpleStyle } = await import('./simplestyle');
|
|
86
87
|
|
|
87
88
|
const map = new Map();
|
|
88
|
-
new simpleStyle(geojson, {id: 'hello-world'}).addTo(map);
|
|
89
|
+
new simpleStyle(geojson, {id: 'hello-world'}).addTo(map).fitBounds();
|
|
89
90
|
|
|
90
91
|
assert.deepEqual([ 'hello-world', 'hello-world-points' ], Object.keys(map.sources));
|
|
91
92
|
assert.deepEqual(8, map.layers.length);
|
|
@@ -93,7 +94,6 @@ describe('Tests for simpleStyle()', () => {
|
|
|
93
94
|
});
|
|
94
95
|
|
|
95
96
|
it('should has sources and layers as expected with empty GeoJSON', async () => {
|
|
96
|
-
window.URL.createObjectURL = () => {}; // To prevent `TypeError: window.URL.createObjectURL is not a function`
|
|
97
97
|
const { default: simpleStyle } = await import('./simplestyle');
|
|
98
98
|
|
|
99
99
|
const map = new Map();
|
|
@@ -103,7 +103,7 @@ describe('Tests for simpleStyle()', () => {
|
|
|
103
103
|
'features': [],
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
new simpleStyle(empty, {id: 'hello-world'}).addTo(map);
|
|
106
|
+
new simpleStyle(empty, {id: 'hello-world'}).addTo(map).fitBounds();
|
|
107
107
|
|
|
108
108
|
assert.deepEqual([ 'hello-world', 'hello-world-points' ], Object.keys(map.sources));
|
|
109
109
|
assert.deepEqual(8, map.layers.length);
|
|
@@ -111,7 +111,6 @@ describe('Tests for simpleStyle()', () => {
|
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
it('should update GeoJSON', async () => {
|
|
114
|
-
window.URL.createObjectURL = () => {}; // To prevent `TypeError: window.URL.createObjectURL is not a function`
|
|
115
114
|
const { default: simpleStyle } = await import('./simplestyle');
|
|
116
115
|
|
|
117
116
|
const map = new Map();
|
|
@@ -121,7 +120,7 @@ describe('Tests for simpleStyle()', () => {
|
|
|
121
120
|
'features': [],
|
|
122
121
|
};
|
|
123
122
|
|
|
124
|
-
const ss = new simpleStyle(empty).addTo(map);
|
|
123
|
+
const ss = new simpleStyle(empty).addTo(map).fitBounds();
|
|
125
124
|
|
|
126
125
|
assert.deepEqual([ 'geolonia-simple-style', 'geolonia-simple-style-points' ], Object.keys(map.sources));
|
|
127
126
|
assert.deepEqual(8, map.layers.length);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_geolonia_embed=self.webpackChunk_geolonia_embed||[]).push([[577],{7577:(e,t,o)=>{o.r(t),o.d(t,{default:()=>y}),o(2526),o(1817),o(9070);var i=o(2739),l=o.n(i),r=o(1235),s=o(8007),a=o.n(s);function n(e,t){for(var o=0;o<t.length;o++){var i=t[o];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var c="#000000",u="#FFFFFF",g="rgba(255, 0, 0, 0.4)",p="#FFFFFF";const y=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.sourceName="vt-geolonia-simple-style",this.url=t}var t,o;return t=e,(o=[{key:"addTo",value:function(e){var t=this,o=e.getContainer();if(!o.dataset||!o.dataset.lng&&!o.dataset.lat){var i=!1;e.on("sourcedata",(function(o){if(o.sourceId===t.sourceName){var l=e.getSource(o.sourceId);!0===(l&&l.loaded())&&(i||(i=!0,e.fitBounds(l.bounds,{duration:0,padding:30})))}}))}e.addSource(this.sourceName,{type:"vector",url:this.url}),this.setPolygonGeometries(e),this.setLineGeometries(e),e.addLayer({id:"vt-geolonia-simple-style-polygon-symbol",type:"symbol",source:this.sourceName,"source-layer":"g-simplestyle-v1",filter:["==","$type","Polygon"],paint:{"text-color":["string",["get","text-color"],c],"text-halo-color":["string",["get","text-halo-color"],u],"text-halo-width":1},layout:{"text-field":["get","title"],"text-font":["Noto Sans Regular"],"text-size":12,"text-max-width":12,"text-allow-overlap":!1}}),e.addLayer({id:"vt-geolonia-simple-style-linestring-symbol",type:"symbol",source:this.sourceName,"source-layer":"g-simplestyle-v1",filter:["==","$type","LineString"],paint:{"text-color":["string",["get","text-color"],c],"text-halo-color":["string",["get","text-halo-color"],u],"text-halo-width":1},layout:{"symbol-placement":"line","text-field":["get","title"],"text-font":["Noto Sans Regular"],"text-size":12,"text-max-width":12,"text-allow-overlap":!1}}),this.setPointGeometries(e)}},{key:"setPolygonGeometries",value:function(e){e.addLayer({id:"vt-geolonia-simple-style-polygon",type:"fill",source:this.sourceName,"source-layer":"g-simplestyle-v1",filter:["==","$type","Polygon"],paint:{"fill-color":["string",["get","fill"],g],"fill-opacity":["number",["get","fill-opacity"],1],"fill-outline-color":["string",["get","stroke"],p]}}),this.setPopup(e,"vt-geolonia-simple-style-polygon")}},{key:"setLineGeometries",value:function(e){e.addLayer({id:"vt-geolonia-simple-style-linestring",type:"line",source:this.sourceName,"source-layer":"g-simplestyle-v1",filter:["==","$type","LineString"],paint:{"line-width":["number",["get","stroke-width"],2],"line-color":["string",["get","stroke"],g],"line-opacity":["number",["get","stroke-opacity"],1]},layout:{"line-cap":"round","line-join":"round"}}),this.setPopup(e,"vt-geolonia-simple-style-linestring")}},{key:"setPointGeometries",value:function(e){e.addLayer({id:"vt-circle-simple-style-points",type:"circle",source:this.sourceName,"source-layer":"g-simplestyle-v1",filter:["==","$type","Point"],paint:{"circle-radius":["case",["==","small",["get","marker-size"]],7,["==","large",["get","marker-size"]],13,9],"circle-color":["string",["get","marker-color"],g],"circle-opacity":["number",["get","fill-opacity"],1],"circle-stroke-width":["number",["get","stroke-width"],1],"circle-stroke-color":["string",["get","stroke"],p],"circle-stroke-opacity":["number",["get","stroke-opacity"],1]}}),e.addLayer({id:"vt-geolonia-simple-style-points",type:"symbol",source:this.sourceName,"source-layer":"g-simplestyle-v1",filter:["==","$type","Point"],paint:{"text-color":["string",["get","text-color"],c],"text-halo-color":["string",["get","text-halo-color"],u],"text-halo-width":1},layout:{"icon-image":["case",["==","large",["get","marker-size"]],["image",["concat",["get","marker-symbol"],"-15"]],["image",["concat",["get","marker-symbol"],"-11"]]],"text-field":["get","title"],"text-font":["Noto Sans Regular"],"text-size":12,"text-anchor":"top","text-max-width":12,"text-offset":["case",["==","small",["get","marker-size"]],["literal",[0,.6]],["==","large",["get","marker-size"]],["literal",[0,1.2]],["literal",[0,.8]]],"text-allow-overlap":!1}}),this.setPopup(e,"vt-circle-simple-style-points")}},{key:"setPopup",value:function(e,t){e.on("click",t,(function(t){var o=(0,r.Z)(t.features[0]).geometry.coordinates,i=t.features[0].properties.description;i&&(new(l().Popup)).setLngLat(o).setHTML(a()(i)).addTo(e)})),e.on("mouseenter",t,(function(t){t.features[0].properties.description&&(e.getCanvas().style.cursor="pointer")})),e.on("mouseleave",t,(function(){e.getCanvas().style.cursor=""}))}}])&&n(t.prototype,o),e}()}}]);
|