@geolonia/maps-core 0.4.0 → 0.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.
- package/dist/npm/index.cjs +119 -9
- package/dist/npm/index.d.cts +5 -2
- package/dist/npm/index.d.ts +5 -2
- package/dist/npm/index.js +128 -24
- package/package.json +3 -3
package/dist/npm/index.cjs
CHANGED
|
@@ -52,7 +52,7 @@ __export(index_exports, {
|
|
|
52
52
|
module.exports = __toCommonJS(index_exports);
|
|
53
53
|
|
|
54
54
|
// src/lib/maplibre-util.ts
|
|
55
|
-
var import_maplibre_gl = require("maplibre-gl");
|
|
55
|
+
var import_maplibre_gl = __toESM(require("maplibre-gl"), 1);
|
|
56
56
|
var _docStyle, _userSelect, _selectProp, _transformProp;
|
|
57
57
|
var _DOM = class _DOM {
|
|
58
58
|
static testProp(props) {
|
|
@@ -103,7 +103,7 @@ var _DOM = class _DOM {
|
|
|
103
103
|
}
|
|
104
104
|
static mousePos(el, e) {
|
|
105
105
|
const rect = el.getBoundingClientRect();
|
|
106
|
-
return new import_maplibre_gl.Point(
|
|
106
|
+
return new import_maplibre_gl.default.Point(
|
|
107
107
|
e.clientX - rect.left - el.clientLeft,
|
|
108
108
|
e.clientY - rect.top - el.clientTop
|
|
109
109
|
);
|
|
@@ -113,7 +113,7 @@ var _DOM = class _DOM {
|
|
|
113
113
|
const points = [];
|
|
114
114
|
for (let i = 0; i < touches.length; i++) {
|
|
115
115
|
points.push(
|
|
116
|
-
new import_maplibre_gl.Point(
|
|
116
|
+
new import_maplibre_gl.default.Point(
|
|
117
117
|
touches[i].clientX - rect.left - el.clientLeft,
|
|
118
118
|
touches[i].clientY - rect.top - el.clientTop
|
|
119
119
|
)
|
|
@@ -1313,6 +1313,107 @@ var SimpleStyleVector = class {
|
|
|
1313
1313
|
};
|
|
1314
1314
|
var simplestyle_vector_default = SimpleStyleVector;
|
|
1315
1315
|
|
|
1316
|
+
// src/lib/legacy-options.ts
|
|
1317
|
+
var CONTROL_POSITIONS = [
|
|
1318
|
+
"top-right",
|
|
1319
|
+
"bottom-right",
|
|
1320
|
+
"bottom-left",
|
|
1321
|
+
"top-left"
|
|
1322
|
+
];
|
|
1323
|
+
function toControlAttr(value) {
|
|
1324
|
+
const v = value.toLowerCase();
|
|
1325
|
+
if (CONTROL_POSITIONS.includes(v)) {
|
|
1326
|
+
return v;
|
|
1327
|
+
}
|
|
1328
|
+
return v === "on";
|
|
1329
|
+
}
|
|
1330
|
+
function isCssSelector(value) {
|
|
1331
|
+
if (/^https?:\/\//.test(value) || /^\.?\.?\//.test(value)) {
|
|
1332
|
+
return null;
|
|
1333
|
+
}
|
|
1334
|
+
try {
|
|
1335
|
+
return document.querySelector(value);
|
|
1336
|
+
} catch {
|
|
1337
|
+
return null;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
function resolveGeojson(value) {
|
|
1341
|
+
const el = isCssSelector(value);
|
|
1342
|
+
if (el?.textContent) {
|
|
1343
|
+
return JSON.parse(el.textContent);
|
|
1344
|
+
}
|
|
1345
|
+
return value;
|
|
1346
|
+
}
|
|
1347
|
+
function isDomElement(o) {
|
|
1348
|
+
return typeof HTMLElement !== "undefined" ? o instanceof HTMLElement : !!o && typeof o === "object" && o.nodeType === 1;
|
|
1349
|
+
}
|
|
1350
|
+
function optionsFromContainer(container) {
|
|
1351
|
+
const ds = container.dataset;
|
|
1352
|
+
const options = {
|
|
1353
|
+
container,
|
|
1354
|
+
bearing: Number.parseFloat(ds.bearing ?? "") || 0,
|
|
1355
|
+
pitch: Number.parseFloat(ds.pitch ?? "") || 0,
|
|
1356
|
+
zoom: Number.parseFloat(ds.zoom ?? "") || 0,
|
|
1357
|
+
hash: ds.hash === "on",
|
|
1358
|
+
marker: (ds.marker ?? "on") === "on",
|
|
1359
|
+
markerColor: ds.markerColor ?? "#E4402F",
|
|
1360
|
+
openPopup: ds.openPopup === "on",
|
|
1361
|
+
loader: ds.loader !== "off",
|
|
1362
|
+
gestureHandling: ds.gestureHandling !== "off",
|
|
1363
|
+
navigationControl: toControlAttr(ds.navigationControl ?? "on"),
|
|
1364
|
+
geolocateControl: toControlAttr(ds.geolocateControl ?? "off"),
|
|
1365
|
+
fullscreenControl: toControlAttr(ds.fullscreenControl ?? "off"),
|
|
1366
|
+
scaleControl: toControlAttr(ds.scaleControl ?? "off"),
|
|
1367
|
+
geoloniaControl: toControlAttr(ds.geoloniaControl ?? "on"),
|
|
1368
|
+
cluster: (ds.cluster ?? "on") === "on",
|
|
1369
|
+
clusterColor: ds.clusterColor ?? "#ff0000",
|
|
1370
|
+
"3d": ds["3d"] === "on"
|
|
1371
|
+
};
|
|
1372
|
+
if (ds.style) options.style = ds.style;
|
|
1373
|
+
if (ds.lang !== void 0) {
|
|
1374
|
+
options.lang = ds.lang;
|
|
1375
|
+
}
|
|
1376
|
+
if (ds.key) options.apiKey = ds.key;
|
|
1377
|
+
if (ds.stage) options.stage = ds.stage;
|
|
1378
|
+
const hasLat = ds.lat !== void 0 && ds.lat !== "";
|
|
1379
|
+
const hasLng = ds.lng !== void 0 && ds.lng !== "";
|
|
1380
|
+
if (hasLat && hasLng) {
|
|
1381
|
+
options.center = [
|
|
1382
|
+
Number.parseFloat(ds.lng),
|
|
1383
|
+
Number.parseFloat(ds.lat)
|
|
1384
|
+
];
|
|
1385
|
+
}
|
|
1386
|
+
if (ds.customMarker) options.customMarker = ds.customMarker;
|
|
1387
|
+
if (ds.customMarkerOffset) {
|
|
1388
|
+
const [x, y] = ds.customMarkerOffset.split(",").map((n) => Number(n.trim()));
|
|
1389
|
+
options.customMarkerOffset = [x || 0, y || 0];
|
|
1390
|
+
}
|
|
1391
|
+
if (ds.geojson) options.geojson = resolveGeojson(ds.geojson);
|
|
1392
|
+
if (ds.simpleVector) options.simpleVector = ds.simpleVector;
|
|
1393
|
+
if (ds.minZoom !== void 0 && ds.minZoom !== "" && (Number(ds.minZoom) === 0 || Number(ds.minZoom))) {
|
|
1394
|
+
options.minZoom = Number(ds.minZoom);
|
|
1395
|
+
}
|
|
1396
|
+
if (ds.maxZoom !== void 0 && ds.maxZoom !== "" && (Number(ds.maxZoom) === 0 || Number(ds.maxZoom))) {
|
|
1397
|
+
options.maxZoom = Number(ds.maxZoom);
|
|
1398
|
+
}
|
|
1399
|
+
return options;
|
|
1400
|
+
}
|
|
1401
|
+
function normalizeConstructorArg(arg) {
|
|
1402
|
+
if (typeof arg === "string") {
|
|
1403
|
+
const el = document.querySelector(arg) || document.getElementById(arg);
|
|
1404
|
+
if (!el) {
|
|
1405
|
+
throw new Error(
|
|
1406
|
+
`[Geolonia] No HTML elements found matching \`${arg}\`. Please ensure the map container element exists.`
|
|
1407
|
+
);
|
|
1408
|
+
}
|
|
1409
|
+
return optionsFromContainer(el);
|
|
1410
|
+
}
|
|
1411
|
+
if (isDomElement(arg)) {
|
|
1412
|
+
return optionsFromContainer(arg);
|
|
1413
|
+
}
|
|
1414
|
+
return arg;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1316
1417
|
// src/lib/geolonia-map.ts
|
|
1317
1418
|
var pmtilesRegistered = false;
|
|
1318
1419
|
function ensurePMTiles() {
|
|
@@ -1323,7 +1424,8 @@ function ensurePMTiles() {
|
|
|
1323
1424
|
}
|
|
1324
1425
|
var GeoloniaMap = class extends import_maplibre_gl5.default.Map {
|
|
1325
1426
|
// biome-ignore lint/correctness/noUnreachableSuper: intentional singleton pattern - returns existing map instance before super()
|
|
1326
|
-
constructor(
|
|
1427
|
+
constructor(arg) {
|
|
1428
|
+
const options = normalizeConstructorArg(arg);
|
|
1327
1429
|
ensurePMTiles();
|
|
1328
1430
|
if (options.apiKey) {
|
|
1329
1431
|
keyring.setApiKey(options.apiKey);
|
|
@@ -1451,24 +1553,30 @@ var GeoloniaMap = class extends import_maplibre_gl5.default.Map {
|
|
|
1451
1553
|
const fullscreen = parseControlOption(options.fullscreenControl ?? false);
|
|
1452
1554
|
if (fullscreen.enabled) {
|
|
1453
1555
|
this.addControl(
|
|
1454
|
-
new import_maplibre_gl5.FullscreenControl(),
|
|
1556
|
+
new import_maplibre_gl5.default.FullscreenControl(),
|
|
1455
1557
|
fullscreen.position
|
|
1456
1558
|
);
|
|
1457
1559
|
}
|
|
1458
1560
|
const nav = parseControlOption(options.navigationControl ?? true);
|
|
1459
1561
|
if (nav.enabled) {
|
|
1460
|
-
this.addControl(
|
|
1562
|
+
this.addControl(
|
|
1563
|
+
new import_maplibre_gl5.default.NavigationControl(),
|
|
1564
|
+
nav.position
|
|
1565
|
+
);
|
|
1461
1566
|
}
|
|
1462
1567
|
const geolocate = parseControlOption(options.geolocateControl ?? false);
|
|
1463
1568
|
if (geolocate.enabled) {
|
|
1464
1569
|
this.addControl(
|
|
1465
|
-
new import_maplibre_gl5.GeolocateControl({}),
|
|
1570
|
+
new import_maplibre_gl5.default.GeolocateControl({}),
|
|
1466
1571
|
geolocate.position
|
|
1467
1572
|
);
|
|
1468
1573
|
}
|
|
1469
1574
|
const scale = parseControlOption(options.scaleControl ?? false);
|
|
1470
1575
|
if (scale.enabled) {
|
|
1471
|
-
this.addControl(
|
|
1576
|
+
this.addControl(
|
|
1577
|
+
new import_maplibre_gl5.default.ScaleControl({}),
|
|
1578
|
+
scale.position
|
|
1579
|
+
);
|
|
1472
1580
|
}
|
|
1473
1581
|
this.on("load", (event) => {
|
|
1474
1582
|
const map = event.target;
|
|
@@ -1511,7 +1619,9 @@ var GeoloniaMap = class extends import_maplibre_gl5.default.Map {
|
|
|
1511
1619
|
}
|
|
1512
1620
|
const content = container.dataset?.popupContent;
|
|
1513
1621
|
if (content) {
|
|
1514
|
-
const popup = new import_maplibre_gl5.Popup({ offset: [0, -25] }).setHTML(
|
|
1622
|
+
const popup = new import_maplibre_gl5.default.Popup({ offset: [0, -25] }).setHTML(
|
|
1623
|
+
content
|
|
1624
|
+
);
|
|
1515
1625
|
marker.setPopup(popup);
|
|
1516
1626
|
if (options.openPopup) {
|
|
1517
1627
|
marker.togglePopup();
|
package/dist/npm/index.d.cts
CHANGED
|
@@ -108,12 +108,15 @@ declare function getLang(): "ja" | "en";
|
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
110
|
* Geolonia Map - extends MapLibre GL Map with Geolonia-specific features.
|
|
111
|
-
*
|
|
111
|
+
*
|
|
112
|
+
* Accepts a {@link GeoloniaMapOptions} object, or — for backward compatibility
|
|
113
|
+
* with the old embed API — a CSS selector string or an HTMLElement, in which
|
|
114
|
+
* case the container's `data-*` attributes are read into options.
|
|
112
115
|
*/
|
|
113
116
|
declare class GeoloniaMap extends maplibregl.Map {
|
|
114
117
|
private geoloniaSourcesUrl;
|
|
115
118
|
private __styleExtensionLoadRequired;
|
|
116
|
-
constructor(
|
|
119
|
+
constructor(arg: string | HTMLElement | GeoloniaMapOptions);
|
|
117
120
|
setStyle(style: string | StyleSpecification, options?: StyleSwapOptions & StyleOptions): this;
|
|
118
121
|
remove(): void;
|
|
119
122
|
loadImage(url: string, callback: GetImageCallback): void;
|
package/dist/npm/index.d.ts
CHANGED
|
@@ -108,12 +108,15 @@ declare function getLang(): "ja" | "en";
|
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
110
|
* Geolonia Map - extends MapLibre GL Map with Geolonia-specific features.
|
|
111
|
-
*
|
|
111
|
+
*
|
|
112
|
+
* Accepts a {@link GeoloniaMapOptions} object, or — for backward compatibility
|
|
113
|
+
* with the old embed API — a CSS selector string or an HTMLElement, in which
|
|
114
|
+
* case the container's `data-*` attributes are read into options.
|
|
112
115
|
*/
|
|
113
116
|
declare class GeoloniaMap extends maplibregl.Map {
|
|
114
117
|
private geoloniaSourcesUrl;
|
|
115
118
|
private __styleExtensionLoadRequired;
|
|
116
|
-
constructor(
|
|
119
|
+
constructor(arg: string | HTMLElement | GeoloniaMapOptions);
|
|
117
120
|
setStyle(style: string | StyleSpecification, options?: StyleSwapOptions & StyleOptions): this;
|
|
118
121
|
remove(): void;
|
|
119
122
|
loadImage(url: string, callback: GetImageCallback): void;
|
package/dist/npm/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
|
|
|
7
7
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
8
|
|
|
9
9
|
// src/lib/maplibre-util.ts
|
|
10
|
-
import
|
|
10
|
+
import maplibregl from "maplibre-gl";
|
|
11
11
|
var _docStyle, _userSelect, _selectProp, _transformProp;
|
|
12
12
|
var _DOM = class _DOM {
|
|
13
13
|
static testProp(props) {
|
|
@@ -58,7 +58,7 @@ var _DOM = class _DOM {
|
|
|
58
58
|
}
|
|
59
59
|
static mousePos(el, e) {
|
|
60
60
|
const rect = el.getBoundingClientRect();
|
|
61
|
-
return new Point(
|
|
61
|
+
return new maplibregl.Point(
|
|
62
62
|
e.clientX - rect.left - el.clientLeft,
|
|
63
63
|
e.clientY - rect.top - el.clientTop
|
|
64
64
|
);
|
|
@@ -68,7 +68,7 @@ var _DOM = class _DOM {
|
|
|
68
68
|
const points = [];
|
|
69
69
|
for (let i = 0; i < touches.length; i++) {
|
|
70
70
|
points.push(
|
|
71
|
-
new Point(
|
|
71
|
+
new maplibregl.Point(
|
|
72
72
|
touches[i].clientX - rect.left - el.clientLeft,
|
|
73
73
|
touches[i].clientY - rect.top - el.clientTop
|
|
74
74
|
)
|
|
@@ -434,17 +434,11 @@ var GeoloniaControl = class {
|
|
|
434
434
|
};
|
|
435
435
|
|
|
436
436
|
// src/lib/geolonia-map.ts
|
|
437
|
-
import
|
|
438
|
-
FullscreenControl,
|
|
439
|
-
GeolocateControl,
|
|
440
|
-
NavigationControl,
|
|
441
|
-
Popup,
|
|
442
|
-
ScaleControl
|
|
443
|
-
} from "maplibre-gl";
|
|
437
|
+
import maplibregl5 from "maplibre-gl";
|
|
444
438
|
import { Protocol } from "pmtiles";
|
|
445
439
|
|
|
446
440
|
// src/lib/geolonia-marker.ts
|
|
447
|
-
import
|
|
441
|
+
import maplibregl2 from "maplibre-gl";
|
|
448
442
|
import tinycolor from "tinycolor2";
|
|
449
443
|
var MARKER_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 67">
|
|
450
444
|
<path class="left" d="M26 0C11.664 0 0 11.663 0 26c0 22.14 26 41 26 41V26h0C26 11.663 26 0 26 0z" fill="#E4402F"/>
|
|
@@ -452,7 +446,7 @@ var MARKER_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 67">
|
|
|
452
446
|
<circle cx="26" cy="26" r="9" fill="#FFF"/>
|
|
453
447
|
</svg>`;
|
|
454
448
|
var DEFAULT_COLOR = "#E4402F";
|
|
455
|
-
var GeoloniaMarker = class extends
|
|
449
|
+
var GeoloniaMarker = class extends maplibregl2.Marker {
|
|
456
450
|
constructor(options = {}) {
|
|
457
451
|
if (!options.element) {
|
|
458
452
|
const markerElement = document.createElement("div");
|
|
@@ -482,7 +476,7 @@ var GeoloniaMarker = class extends maplibregl.Marker {
|
|
|
482
476
|
// src/lib/simplestyle.ts
|
|
483
477
|
import bbox from "@turf/bbox";
|
|
484
478
|
import turfCenter from "@turf/center";
|
|
485
|
-
import
|
|
479
|
+
import maplibregl3 from "maplibre-gl";
|
|
486
480
|
|
|
487
481
|
// src/lib/keyring.ts
|
|
488
482
|
var _apiKey, _stage, _isGeoloniaStyle;
|
|
@@ -911,7 +905,7 @@ var SimpleStyle = class {
|
|
|
911
905
|
const description = e.features[0].properties?.description;
|
|
912
906
|
if (description) {
|
|
913
907
|
const sanitizedDescription = await sanitizeDescription(description);
|
|
914
|
-
new
|
|
908
|
+
new maplibregl3.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
915
909
|
}
|
|
916
910
|
};
|
|
917
911
|
const mouseEnterHandler = (e) => {
|
|
@@ -1053,7 +1047,7 @@ var SimpleStyle = class {
|
|
|
1053
1047
|
|
|
1054
1048
|
// src/lib/simplestyle-vector.ts
|
|
1055
1049
|
import turfCenter2 from "@turf/center";
|
|
1056
|
-
import
|
|
1050
|
+
import maplibregl4 from "maplibre-gl";
|
|
1057
1051
|
var textColor2 = "#000000";
|
|
1058
1052
|
var textHaloColor2 = "#FFFFFF";
|
|
1059
1053
|
var backgroundColor2 = "rgba(255, 0, 0, 0.4)";
|
|
@@ -1259,7 +1253,7 @@ var SimpleStyleVector = class {
|
|
|
1259
1253
|
const description = e.features[0].properties?.description;
|
|
1260
1254
|
if (description) {
|
|
1261
1255
|
const sanitizedDescription = await sanitizeDescription(description);
|
|
1262
|
-
new
|
|
1256
|
+
new maplibregl4.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
1263
1257
|
}
|
|
1264
1258
|
});
|
|
1265
1259
|
map.on("mouseenter", source, (e) => {
|
|
@@ -1274,17 +1268,119 @@ var SimpleStyleVector = class {
|
|
|
1274
1268
|
};
|
|
1275
1269
|
var simplestyle_vector_default = SimpleStyleVector;
|
|
1276
1270
|
|
|
1271
|
+
// src/lib/legacy-options.ts
|
|
1272
|
+
var CONTROL_POSITIONS = [
|
|
1273
|
+
"top-right",
|
|
1274
|
+
"bottom-right",
|
|
1275
|
+
"bottom-left",
|
|
1276
|
+
"top-left"
|
|
1277
|
+
];
|
|
1278
|
+
function toControlAttr(value) {
|
|
1279
|
+
const v = value.toLowerCase();
|
|
1280
|
+
if (CONTROL_POSITIONS.includes(v)) {
|
|
1281
|
+
return v;
|
|
1282
|
+
}
|
|
1283
|
+
return v === "on";
|
|
1284
|
+
}
|
|
1285
|
+
function isCssSelector(value) {
|
|
1286
|
+
if (/^https?:\/\//.test(value) || /^\.?\.?\//.test(value)) {
|
|
1287
|
+
return null;
|
|
1288
|
+
}
|
|
1289
|
+
try {
|
|
1290
|
+
return document.querySelector(value);
|
|
1291
|
+
} catch {
|
|
1292
|
+
return null;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
function resolveGeojson(value) {
|
|
1296
|
+
const el = isCssSelector(value);
|
|
1297
|
+
if (el?.textContent) {
|
|
1298
|
+
return JSON.parse(el.textContent);
|
|
1299
|
+
}
|
|
1300
|
+
return value;
|
|
1301
|
+
}
|
|
1302
|
+
function isDomElement(o) {
|
|
1303
|
+
return typeof HTMLElement !== "undefined" ? o instanceof HTMLElement : !!o && typeof o === "object" && o.nodeType === 1;
|
|
1304
|
+
}
|
|
1305
|
+
function optionsFromContainer(container) {
|
|
1306
|
+
const ds = container.dataset;
|
|
1307
|
+
const options = {
|
|
1308
|
+
container,
|
|
1309
|
+
bearing: Number.parseFloat(ds.bearing ?? "") || 0,
|
|
1310
|
+
pitch: Number.parseFloat(ds.pitch ?? "") || 0,
|
|
1311
|
+
zoom: Number.parseFloat(ds.zoom ?? "") || 0,
|
|
1312
|
+
hash: ds.hash === "on",
|
|
1313
|
+
marker: (ds.marker ?? "on") === "on",
|
|
1314
|
+
markerColor: ds.markerColor ?? "#E4402F",
|
|
1315
|
+
openPopup: ds.openPopup === "on",
|
|
1316
|
+
loader: ds.loader !== "off",
|
|
1317
|
+
gestureHandling: ds.gestureHandling !== "off",
|
|
1318
|
+
navigationControl: toControlAttr(ds.navigationControl ?? "on"),
|
|
1319
|
+
geolocateControl: toControlAttr(ds.geolocateControl ?? "off"),
|
|
1320
|
+
fullscreenControl: toControlAttr(ds.fullscreenControl ?? "off"),
|
|
1321
|
+
scaleControl: toControlAttr(ds.scaleControl ?? "off"),
|
|
1322
|
+
geoloniaControl: toControlAttr(ds.geoloniaControl ?? "on"),
|
|
1323
|
+
cluster: (ds.cluster ?? "on") === "on",
|
|
1324
|
+
clusterColor: ds.clusterColor ?? "#ff0000",
|
|
1325
|
+
"3d": ds["3d"] === "on"
|
|
1326
|
+
};
|
|
1327
|
+
if (ds.style) options.style = ds.style;
|
|
1328
|
+
if (ds.lang !== void 0) {
|
|
1329
|
+
options.lang = ds.lang;
|
|
1330
|
+
}
|
|
1331
|
+
if (ds.key) options.apiKey = ds.key;
|
|
1332
|
+
if (ds.stage) options.stage = ds.stage;
|
|
1333
|
+
const hasLat = ds.lat !== void 0 && ds.lat !== "";
|
|
1334
|
+
const hasLng = ds.lng !== void 0 && ds.lng !== "";
|
|
1335
|
+
if (hasLat && hasLng) {
|
|
1336
|
+
options.center = [
|
|
1337
|
+
Number.parseFloat(ds.lng),
|
|
1338
|
+
Number.parseFloat(ds.lat)
|
|
1339
|
+
];
|
|
1340
|
+
}
|
|
1341
|
+
if (ds.customMarker) options.customMarker = ds.customMarker;
|
|
1342
|
+
if (ds.customMarkerOffset) {
|
|
1343
|
+
const [x, y] = ds.customMarkerOffset.split(",").map((n) => Number(n.trim()));
|
|
1344
|
+
options.customMarkerOffset = [x || 0, y || 0];
|
|
1345
|
+
}
|
|
1346
|
+
if (ds.geojson) options.geojson = resolveGeojson(ds.geojson);
|
|
1347
|
+
if (ds.simpleVector) options.simpleVector = ds.simpleVector;
|
|
1348
|
+
if (ds.minZoom !== void 0 && ds.minZoom !== "" && (Number(ds.minZoom) === 0 || Number(ds.minZoom))) {
|
|
1349
|
+
options.minZoom = Number(ds.minZoom);
|
|
1350
|
+
}
|
|
1351
|
+
if (ds.maxZoom !== void 0 && ds.maxZoom !== "" && (Number(ds.maxZoom) === 0 || Number(ds.maxZoom))) {
|
|
1352
|
+
options.maxZoom = Number(ds.maxZoom);
|
|
1353
|
+
}
|
|
1354
|
+
return options;
|
|
1355
|
+
}
|
|
1356
|
+
function normalizeConstructorArg(arg) {
|
|
1357
|
+
if (typeof arg === "string") {
|
|
1358
|
+
const el = document.querySelector(arg) || document.getElementById(arg);
|
|
1359
|
+
if (!el) {
|
|
1360
|
+
throw new Error(
|
|
1361
|
+
`[Geolonia] No HTML elements found matching \`${arg}\`. Please ensure the map container element exists.`
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
return optionsFromContainer(el);
|
|
1365
|
+
}
|
|
1366
|
+
if (isDomElement(arg)) {
|
|
1367
|
+
return optionsFromContainer(arg);
|
|
1368
|
+
}
|
|
1369
|
+
return arg;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1277
1372
|
// src/lib/geolonia-map.ts
|
|
1278
1373
|
var pmtilesRegistered = false;
|
|
1279
1374
|
function ensurePMTiles() {
|
|
1280
1375
|
if (pmtilesRegistered) return;
|
|
1281
1376
|
pmtilesRegistered = true;
|
|
1282
1377
|
const protocol = new Protocol();
|
|
1283
|
-
|
|
1378
|
+
maplibregl5.addProtocol("pmtiles", protocol.tile);
|
|
1284
1379
|
}
|
|
1285
|
-
var GeoloniaMap = class extends
|
|
1380
|
+
var GeoloniaMap = class extends maplibregl5.Map {
|
|
1286
1381
|
// biome-ignore lint/correctness/noUnreachableSuper: intentional singleton pattern - returns existing map instance before super()
|
|
1287
|
-
constructor(
|
|
1382
|
+
constructor(arg) {
|
|
1383
|
+
const options = normalizeConstructorArg(arg);
|
|
1288
1384
|
ensurePMTiles();
|
|
1289
1385
|
if (options.apiKey) {
|
|
1290
1386
|
keyring.setApiKey(options.apiKey);
|
|
@@ -1412,24 +1508,30 @@ var GeoloniaMap = class extends maplibregl4.Map {
|
|
|
1412
1508
|
const fullscreen = parseControlOption(options.fullscreenControl ?? false);
|
|
1413
1509
|
if (fullscreen.enabled) {
|
|
1414
1510
|
this.addControl(
|
|
1415
|
-
new FullscreenControl(),
|
|
1511
|
+
new maplibregl5.FullscreenControl(),
|
|
1416
1512
|
fullscreen.position
|
|
1417
1513
|
);
|
|
1418
1514
|
}
|
|
1419
1515
|
const nav = parseControlOption(options.navigationControl ?? true);
|
|
1420
1516
|
if (nav.enabled) {
|
|
1421
|
-
this.addControl(
|
|
1517
|
+
this.addControl(
|
|
1518
|
+
new maplibregl5.NavigationControl(),
|
|
1519
|
+
nav.position
|
|
1520
|
+
);
|
|
1422
1521
|
}
|
|
1423
1522
|
const geolocate = parseControlOption(options.geolocateControl ?? false);
|
|
1424
1523
|
if (geolocate.enabled) {
|
|
1425
1524
|
this.addControl(
|
|
1426
|
-
new GeolocateControl({}),
|
|
1525
|
+
new maplibregl5.GeolocateControl({}),
|
|
1427
1526
|
geolocate.position
|
|
1428
1527
|
);
|
|
1429
1528
|
}
|
|
1430
1529
|
const scale = parseControlOption(options.scaleControl ?? false);
|
|
1431
1530
|
if (scale.enabled) {
|
|
1432
|
-
this.addControl(
|
|
1531
|
+
this.addControl(
|
|
1532
|
+
new maplibregl5.ScaleControl({}),
|
|
1533
|
+
scale.position
|
|
1534
|
+
);
|
|
1433
1535
|
}
|
|
1434
1536
|
this.on("load", (event) => {
|
|
1435
1537
|
const map = event.target;
|
|
@@ -1472,7 +1574,9 @@ var GeoloniaMap = class extends maplibregl4.Map {
|
|
|
1472
1574
|
}
|
|
1473
1575
|
const content = container.dataset?.popupContent;
|
|
1474
1576
|
if (content) {
|
|
1475
|
-
const popup = new Popup({ offset: [0, -25] }).setHTML(
|
|
1577
|
+
const popup = new maplibregl5.Popup({ offset: [0, -25] }).setHTML(
|
|
1578
|
+
content
|
|
1579
|
+
);
|
|
1476
1580
|
marker.setPopup(popup);
|
|
1477
1581
|
if (options.openPopup) {
|
|
1478
1582
|
marker.togglePopup();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geolonia/maps-core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/npm/index.cjs",
|
|
6
6
|
"module": "dist/npm/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@turf/bbox": "^7.3.4",
|
|
23
23
|
"@turf/center": "^7.3.4",
|
|
24
24
|
"pmtiles": "^4.4.0",
|
|
25
|
-
"sanitize-html": "^2.17.
|
|
25
|
+
"sanitize-html": "^2.17.4",
|
|
26
26
|
"tinycolor2": "^1.4.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"maplibre-gl": "5.7.0",
|
|
39
39
|
"tsup": "^8",
|
|
40
40
|
"typescript": "^5.8",
|
|
41
|
-
"vite": "^
|
|
41
|
+
"vite": "^8.0.16",
|
|
42
42
|
"vitest": "^4.1.2"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|