@opendfieldmap/map 0.2.0-beta → 0.2.2-beta

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.
@@ -1,5 +1,5 @@
1
- // packages/map/src/runtime.ts
2
- import L4 from "leaflet";
1
+ // packages/map/src/runtime/oem.ts
2
+ import L5 from "leaflet";
3
3
  import "leaflet.markercluster";
4
4
  import {
5
5
  createOEMPointUrl,
@@ -13,25 +13,8 @@ import {
13
13
  toOEMLeafletPosition
14
14
  } from "@opendfieldmap/core";
15
15
 
16
- // packages/map/src/atlos/smoothTileLayer.ts
17
- import L from "leaflet";
18
- var SmoothTileLayer = class extends L.TileLayer {
19
- _setZoomTransform(level, center, zoom) {
20
- const map = this._map;
21
- if (!map)
22
- return;
23
- const scale = map.getZoomScale(zoom, level.zoom);
24
- const translate = level.origin.multiplyBy(scale).subtract(map._getNewPixelOrigin(center, zoom));
25
- if (L.Browser.any3d) {
26
- L.DomUtil.setTransform(level.el, translate, scale);
27
- } else {
28
- L.DomUtil.setPosition(level.el, translate);
29
- }
30
- }
31
- };
32
-
33
16
  // packages/map/src/atlos/smoothWheelZoom.ts
34
- import L2 from "leaflet";
17
+ import L from "leaflet";
35
18
  import { WHEEL_GESTURE_IDLE_MS, WheelInputRouter } from "trackpad-input";
36
19
  var ZOOM_PER_WHEEL_PIXEL = 3e-3;
37
20
  var TRACKPAD_PINCH_ZOOM_PER_PIXEL = 0.01;
@@ -74,7 +57,7 @@ var SmoothWheelZoom = class {
74
57
  lastZoomInputTime = null;
75
58
  inertiaStep = 0;
76
59
  lastFrameTime = null;
77
- pendingPanOffset = L2.point(0, 0);
60
+ pendingPanOffset = L.point(0, 0);
78
61
  panRawCenterPoint = null;
79
62
  gestureMode = null;
80
63
  gestureActive = false;
@@ -138,7 +121,7 @@ var SmoothWheelZoom = class {
138
121
  this.handleZoom(event);
139
122
  }
140
123
  handleZoom(event) {
141
- const wheelDelta = L2.DomEvent.getWheelDelta(event);
124
+ const wheelDelta = L.DomEvent.getWheelDelta(event);
142
125
  if (!wheelDelta)
143
126
  return;
144
127
  const zoomDelta = event.ctrlKey && event.deltaMode === 0 ? -event.deltaY * TRACKPAD_PINCH_ZOOM_PER_PIXEL : wheelDelta * ZOOM_PER_WHEEL_PIXEL;
@@ -160,7 +143,7 @@ var SmoothWheelZoom = class {
160
143
  this.scheduleGestureEnd();
161
144
  }
162
145
  handleTrackpadPan(event) {
163
- const offset = L2.point(event.deltaX, event.deltaY);
146
+ const offset = L.point(event.deltaX, event.deltaY);
164
147
  if (offset.x === 0 && offset.y === 0) {
165
148
  if (this.gestureActive && !this.overdragSettling) {
166
149
  this.scheduleGestureEnd();
@@ -251,7 +234,7 @@ var SmoothWheelZoom = class {
251
234
  if (!this.gestureActive || this.gestureMode !== "pan")
252
235
  return;
253
236
  const offset = this.pendingPanOffset;
254
- this.pendingPanOffset = L2.point(0, 0);
237
+ this.pendingPanOffset = L.point(0, 0);
255
238
  if (offset.x !== 0 || offset.y !== 0) {
256
239
  const overdragAmount = this.applyConstrainedPan(offset);
257
240
  this.map.fire("move").fire("drag");
@@ -277,12 +260,12 @@ var SmoothWheelZoom = class {
277
260
  this.map._rawPanBy(offset);
278
261
  return 0;
279
262
  }
280
- const maxBounds = configuredBounds instanceof L2.LatLngBounds ? configuredBounds : L2.latLngBounds(configuredBounds);
263
+ const maxBounds = configuredBounds instanceof L.LatLngBounds ? configuredBounds : L.latLngBounds(configuredBounds);
281
264
  const rawCenter = this.map.unproject(this.panRawCenterPoint, zoom);
282
265
  const limitedCenter = this.map._limitCenter(rawCenter, zoom, maxBounds);
283
266
  const limitedCenterPoint = this.map.project(limitedCenter, zoom);
284
267
  const rawOverdrag = this.panRawCenterPoint.subtract(limitedCenterPoint);
285
- const visualOverdrag = L2.point(this.resistOverdrag(rawOverdrag.x), this.resistOverdrag(rawOverdrag.y));
268
+ const visualOverdrag = L.point(this.resistOverdrag(rawOverdrag.x), this.resistOverdrag(rawOverdrag.y));
286
269
  const visualCenterPoint = limitedCenterPoint.add(visualOverdrag);
287
270
  const visualOffset = visualCenterPoint.subtract(currentCenterPoint);
288
271
  if (visualOffset.x !== 0 || visualOffset.y !== 0) {
@@ -329,7 +312,7 @@ var SmoothWheelZoom = class {
329
312
  let center = this.map.unproject(this.map.project(this.anchorLatLng, zoom).subtract(cursorOffset), zoom);
330
313
  const configuredBounds = this.map.options.maxBounds;
331
314
  if (configuredBounds) {
332
- const maxBounds = configuredBounds instanceof L2.LatLngBounds ? configuredBounds : L2.latLngBounds(configuredBounds);
315
+ const maxBounds = configuredBounds instanceof L.LatLngBounds ? configuredBounds : L.latLngBounds(configuredBounds);
333
316
  center = this.map._limitCenter(center, zoom, maxBounds);
334
317
  }
335
318
  this.map._move(center, zoom, CONTINUOUS_ZOOM_EVENT_DATA);
@@ -384,7 +367,7 @@ var SmoothWheelZoom = class {
384
367
  this.lastZoomInputTime = null;
385
368
  this.inertiaStep = 0;
386
369
  this.lastFrameTime = null;
387
- this.pendingPanOffset = L2.point(0, 0);
370
+ this.pendingPanOffset = L.point(0, 0);
388
371
  this.panRawCenterPoint = null;
389
372
  this.gestureMode = null;
390
373
  this.trackpadDragging = false;
@@ -411,13 +394,13 @@ var SmoothWheelZoom = class {
411
394
  var enableSmoothWheelZoom = (map, options) => new SmoothWheelZoom(map, options);
412
395
 
413
396
  // packages/map/src/atlos/mapOverdrag.ts
414
- import L3 from "leaflet";
397
+ import L2 from "leaflet";
415
398
  var toMapBounds = (bounds) => {
416
399
  if (!bounds)
417
400
  return null;
418
- if (bounds instanceof L3.LatLngBounds)
401
+ if (bounds instanceof L2.LatLngBounds)
419
402
  return bounds;
420
- return Array.isArray(bounds) && bounds.length === 2 ? L3.latLngBounds(bounds[0], bounds[1]) : null;
403
+ return Array.isArray(bounds) && bounds.length === 2 ? L2.latLngBounds(bounds[0], bounds[1]) : null;
421
404
  };
422
405
  var isMapOverdragged = (map, bounds) => {
423
406
  const constrainedMap = map;
@@ -426,6 +409,64 @@ var isMapOverdragged = (map, bounds) => {
426
409
  return map.project(center, map.getZoom()).distanceTo(map.project(constrainedCenter, map.getZoom())) > 1;
427
410
  };
428
411
 
412
+ // packages/map/src/assets/ghicon.svg
413
+ var ghicon_default = '<svg width="83" height="81" viewBox="0 0 83 81" xmlns="http://www.w3.org/2000/svg">\n<path fill-rule="evenodd" clip-rule="evenodd" d="M41.3763 0C18.4963 0 0 18.5625 0 41.5268C0 59.8835 11.8512 75.422 28.292 80.9215C30.3475 81.335 31.1004 80.028 31.1004 78.9286C31.1004 77.9659 31.0327 74.666 31.0327 71.2277C19.5228 73.7032 17.1259 66.2774 17.1259 66.2774C15.2762 61.4647 12.5355 60.2277 12.5355 60.2277C8.76836 57.6838 12.8099 57.6838 12.8099 57.6838C16.9887 57.9589 19.1815 61.9464 19.1815 61.9464C22.8801 68.2712 28.84 66.4841 31.2376 65.3839C31.5798 62.7024 32.6766 60.8462 33.8411 59.8151C24.6612 58.8524 15.0027 55.2774 15.0027 39.3263C15.0027 34.7887 16.6457 31.0762 19.2492 28.1888C18.8385 27.1578 17.3995 22.8943 19.6608 17.188C19.6608 17.188 23.1545 16.0878 31.0318 21.4507C34.4044 20.5417 37.8825 20.0792 41.3763 20.0753C44.87 20.0753 48.4314 20.5571 51.72 21.4507C59.5982 16.0878 63.0919 17.188 63.0919 17.188C65.3532 22.8943 63.9134 27.1578 63.5026 28.1888C66.1747 31.0762 67.75 34.7887 67.75 39.3263C67.75 55.2774 58.0915 58.7832 48.843 59.8151C50.3505 61.1213 51.6514 63.596 51.6514 67.5152C51.6514 73.0839 51.5837 77.5533 51.5837 78.9277C51.5837 80.028 52.3374 81.335 54.3921 80.9224C70.8329 75.4211 82.6841 59.8835 82.6841 41.5268C82.7518 18.5625 64.1878 0 41.3763 0Z"/>\n</svg>\n';
414
+
415
+ // packages/map/src/runtime/geometry.ts
416
+ var pointOnSegment = (point, start, end) => {
417
+ const cross = (point.x - start.x) * (end.z - start.z) - (point.z - start.z) * (end.x - start.x);
418
+ if (Math.abs(cross) > 1e-7) return false;
419
+ return point.x >= Math.min(start.x, end.x) - 1e-7 && point.x <= Math.max(start.x, end.x) + 1e-7 && point.z >= Math.min(start.z, end.z) - 1e-7 && point.z <= Math.max(start.z, end.z) + 1e-7;
420
+ };
421
+ var pointInRing = (point, ring) => {
422
+ let inside = false;
423
+ for (let index = 0, previous = ring.length - 1; index < ring.length; previous = index++) {
424
+ const current = ring[index];
425
+ const prior = ring[previous];
426
+ if (pointOnSegment(point, prior, current)) return true;
427
+ const crosses = current.z > point.z !== prior.z > point.z;
428
+ if (crosses && point.x < (prior.x - current.x) * (point.z - current.z) / (prior.z - current.z) + current.x) inside = !inside;
429
+ }
430
+ return inside;
431
+ };
432
+ var distanceSquaredToSegment = (point, start, end) => {
433
+ const dx = end.x - start.x;
434
+ const dz = end.z - start.z;
435
+ const lengthSquared = dx * dx + dz * dz;
436
+ if (!lengthSquared) return (point.x - start.x) ** 2 + (point.z - start.z) ** 2;
437
+ const projection = Math.max(0, Math.min(1, ((point.x - start.x) * dx + (point.z - start.z) * dz) / lengthSquared));
438
+ const nearestX = start.x + projection * dx;
439
+ const nearestZ = start.z + projection * dz;
440
+ return (point.x - nearestX) ** 2 + (point.z - nearestZ) ** 2;
441
+ };
442
+ var boundaryScore = (boundary, point) => {
443
+ const rings = boundary.rings.map((ring) => ring);
444
+ const distances = rings.flatMap((ring) => ring.map((start, index) => distanceSquaredToSegment(point, start, ring[(index + 1) % ring.length])));
445
+ const insideOuter = rings.length > 0 && pointInRing(point, rings[0]);
446
+ const insideHole = rings.slice(1).some((ring) => pointInRing(point, ring));
447
+ return { id: boundary.id, inside: insideOuter && !insideHole, distance: Math.min(...distances, Infinity) };
448
+ };
449
+
450
+ // packages/map/src/runtime/layers.ts
451
+ import L4 from "leaflet";
452
+
453
+ // packages/map/src/atlos/smoothTileLayer.ts
454
+ import L3 from "leaflet";
455
+ var SmoothTileLayer = class extends L3.TileLayer {
456
+ _setZoomTransform(level, center, zoom) {
457
+ const map = this._map;
458
+ if (!map)
459
+ return;
460
+ const scale = map.getZoomScale(zoom, level.zoom);
461
+ const translate = level.origin.multiplyBy(scale).subtract(map._getNewPixelOrigin(center, zoom));
462
+ if (L3.Browser.any3d) {
463
+ L3.DomUtil.setTransform(level.el, translate, scale);
464
+ } else {
465
+ L3.DomUtil.setPosition(level.el, translate);
466
+ }
467
+ }
468
+ };
469
+
429
470
  // packages/map/src/tileVersion.ts
430
471
  var lookupOEMTile = (coverage, floor, zoom, x, y) => {
431
472
  const ranges = coverage[String(zoom)]?.[floor.id]?.[String(y)] ?? [];
@@ -445,32 +486,7 @@ var lookupOEMTile = (coverage, floor, zoom, x, y) => {
445
486
  };
446
487
  var appendOEMTileVersion = (url, version) => version ? `${url}${url.includes("?") ? "&" : "?"}v=${encodeURIComponent(version)}` : url;
447
488
 
448
- // packages/map/src/assets/ghicon.svg
449
- var ghicon_default = '<svg width="83" height="81" viewBox="0 0 83 81" xmlns="http://www.w3.org/2000/svg">\n<path fill-rule="evenodd" clip-rule="evenodd" d="M41.3763 0C18.4963 0 0 18.5625 0 41.5268C0 59.8835 11.8512 75.422 28.292 80.9215C30.3475 81.335 31.1004 80.028 31.1004 78.9286C31.1004 77.9659 31.0327 74.666 31.0327 71.2277C19.5228 73.7032 17.1259 66.2774 17.1259 66.2774C15.2762 61.4647 12.5355 60.2277 12.5355 60.2277C8.76836 57.6838 12.8099 57.6838 12.8099 57.6838C16.9887 57.9589 19.1815 61.9464 19.1815 61.9464C22.8801 68.2712 28.84 66.4841 31.2376 65.3839C31.5798 62.7024 32.6766 60.8462 33.8411 59.8151C24.6612 58.8524 15.0027 55.2774 15.0027 39.3263C15.0027 34.7887 16.6457 31.0762 19.2492 28.1888C18.8385 27.1578 17.3995 22.8943 19.6608 17.188C19.6608 17.188 23.1545 16.0878 31.0318 21.4507C34.4044 20.5417 37.8825 20.0792 41.3763 20.0753C44.87 20.0753 48.4314 20.5571 51.72 21.4507C59.5982 16.0878 63.0919 17.188 63.0919 17.188C65.3532 22.8943 63.9134 27.1578 63.5026 28.1888C66.1747 31.0762 67.75 34.7887 67.75 39.3263C67.75 55.2774 58.0915 58.7832 48.843 59.8151C50.3505 61.1213 51.6514 63.596 51.6514 67.5152C51.6514 73.0839 51.5837 77.5533 51.5837 78.9277C51.5837 80.028 52.3374 81.335 54.3921 80.9224C70.8329 75.4211 82.6841 59.8835 82.6841 41.5268C82.7518 18.5625 64.1878 0 41.3763 0Z"/>\n</svg>\n';
450
-
451
- // packages/map/src/runtime.ts
452
- var mounted = /* @__PURE__ */ new WeakSet();
453
- var CLUSTER_SUBCATEGORIES = /* @__PURE__ */ new Set(["boss", "collection", "mob", "natural", "valuable", "exploration"]);
454
- var FEATURE_NAMES = ["points", "labels", "boundaries"];
455
- var BRAND_URL = "https://oem.re/";
456
- var GITHUB_URL = "https://github.com/Terra-Online/OEM-SDK";
457
- var TERMS_URL = "https://blog.opendfieldmap.org/docs/tos#intellectual-property-and-copyright";
458
- var cloneFilter = (filter) => ({
459
- types: filter.types ? [...filter.types] : void 0,
460
- subregions: filter.subregions ? [...filter.subregions] : void 0,
461
- floorOnly: filter.floorOnly
462
- });
463
- var sameList = (left, right) => left === right || !!left && !!right && left.length === right.length && left.every((value, index) => value === right[index]);
464
- var sameFilter = (left, right) => left.floorOnly === right.floorOnly && sameList(left.types, right.types) && sameList(left.subregions, right.subregions);
465
- var clonePoint = (point) => ({
466
- ...point,
467
- raw: { ...point.raw },
468
- position: { ...point.position }
469
- });
470
- var cloneCustomPoint = (point) => ({
471
- ...point,
472
- position: { ...point.position }
473
- });
489
+ // packages/map/src/runtime/layers.ts
474
490
  var OEMMarker = class extends L4.Marker {
475
491
  update() {
476
492
  const marker = this;
@@ -497,6 +513,56 @@ var CoveredTileLayer = class extends SmoothTileLayer {
497
513
  return prototype._isValidTile.call(this, coords) && lookupOEMTile(this.coverage, this.floor, coords.z, coords.x, coords.y).covered;
498
514
  }
499
515
  };
516
+
517
+ // packages/map/src/runtime/helpers.ts
518
+ var cloneFilter = (filter) => ({
519
+ types: filter.types ? [...filter.types] : void 0,
520
+ subregions: filter.subregions ? [...filter.subregions] : void 0,
521
+ floorOnly: filter.floorOnly
522
+ });
523
+ var sameList = (left, right) => left === right || !!left && !!right && left.length === right.length && left.every((value, index) => value === right[index]);
524
+ var sameFilter = (left, right) => left.floorOnly === right.floorOnly && sameList(left.types, right.types) && sameList(left.subregions, right.subregions);
525
+ var clonePoint = (point) => ({
526
+ ...point,
527
+ raw: { ...point.raw },
528
+ position: { ...point.position }
529
+ });
530
+ var cloneCustomPoint = (point) => ({
531
+ ...point,
532
+ position: { ...point.position }
533
+ });
534
+ var CLUSTER_SUBCATEGORIES = /* @__PURE__ */ new Set(["boss", "collection", "mob", "natural", "valuable", "exploration"]);
535
+ var FEATURE_NAMES = ["points", "labels", "boundaries"];
536
+ var BRAND_URL = "https://oem.re/";
537
+ var GITHUB_URL = "https://github.com/Terra-Online/OEM-SDK";
538
+ var TERMS_URL = "https://blog.opendfieldmap.org/docs/tos#intellectual-property-and-copyright";
539
+
540
+ // packages/map/src/runtime/oem.ts
541
+ var mounted = /* @__PURE__ */ new WeakSet();
542
+ var decodeAtlosPoint = (raw, region, fallbackSubregionId) => {
543
+ if (!Array.isArray(raw) && raw && "position" in raw && "raw" in raw) return raw;
544
+ const value = Array.isArray(raw) ? { id: raw[0], z: raw[1], x: raw[2], y: raw[3], tier: raw[4], type: raw[5] } : raw;
545
+ if (value?.id == null) return void 0;
546
+ const x = value.x ?? value.pos?.[1] ?? 0;
547
+ const z = value.z ?? value.pos?.[0] ?? 0;
548
+ const y = value.y ?? value.pos?.[2] ?? 0;
549
+ const tier = value.tier ?? 0;
550
+ if (![x, y, z, tier].every(Number.isFinite)) return void 0;
551
+ const subregionId = value.subregId ?? fallbackSubregionId;
552
+ const floorId = tier === 0 ? "M" : `${tier < 0 ? "B" : "L"}${Math.abs(Math.trunc(tier))}`;
553
+ const mapPosition = { regionId: region.id, subregionId, x, z, floorId };
554
+ const game = mapToGameXZPosition(mapPosition, region, subregionId);
555
+ const scale = 2 ** region.maxNativeZoom;
556
+ return {
557
+ id: String(value.id),
558
+ regionId: region.id,
559
+ subregionId,
560
+ type: value.type ?? "",
561
+ tier,
562
+ raw: { x: game.x, y, z: game.z },
563
+ position: { ...mapPosition, x: x * scale, z: z * scale }
564
+ };
565
+ };
500
566
  var OEM = class {
501
567
  constructor(container, manifest, options) {
502
568
  this.container = container;
@@ -505,6 +571,7 @@ var OEM = class {
505
571
  if (mounted.has(container)) throw new Error("This container already hosts an OEM instance");
506
572
  this.region = getOEMRegion(manifest, options.view?.regionId ?? options.regionId ?? manifest.defaultRegionId);
507
573
  this.filter = cloneFilter(options.pointFilter ?? {});
574
+ this.boundarySource = options.features?.boundarySource ?? "oem";
508
575
  this.customPoints = this.normalizeCustomPoints(options.customPoints ?? []);
509
576
  this.markerClustering = options.markerClustering ?? true;
510
577
  const initialFloor = options.view?.floorId ?? options.floorId ?? "M";
@@ -517,8 +584,8 @@ var OEM = class {
517
584
  this.root.dataset.theme = options.theme ?? "light";
518
585
  container.append(this.root);
519
586
  mounted.add(container);
520
- this.map = L4.map(this.root, {
521
- crs: L4.CRS.Simple,
587
+ this.map = L5.map(this.root, {
588
+ crs: L5.CRS.Simple,
522
589
  minZoom: 0,
523
590
  maxZoom: 3,
524
591
  zoomControl: false,
@@ -593,21 +660,27 @@ var OEM = class {
593
660
  region;
594
661
  floorId = "M";
595
662
  features = {};
663
+ boundarySource = "oem";
596
664
  listeners = /* @__PURE__ */ new Map();
597
665
  requests = /* @__PURE__ */ new Map();
598
666
  baseTiles;
599
667
  floorTiles;
600
- pointsLayer = L4.layerGroup();
601
- customPointsLayer = L4.layerGroup();
668
+ pointsLayer = L5.layerGroup();
669
+ customPointsLayer = L5.layerGroup();
602
670
  pointClusters = /* @__PURE__ */ new Map();
603
- labelsLayer = L4.layerGroup();
604
- boundariesLayer = L4.layerGroup();
671
+ labelsLayer = L5.layerGroup();
672
+ boundariesLayer = L5.layerGroup();
605
673
  points = [];
606
674
  customPoints = [];
675
+ clickPoints = [];
676
+ clickPointOptions;
677
+ clickPointSequence = 0;
607
678
  customPointsRequest;
608
679
  pointIndex;
609
680
  pointIndexRequest;
610
681
  pointShardRequests = /* @__PURE__ */ new Map();
682
+ boundaryData = /* @__PURE__ */ new Map();
683
+ boundaryDataRequests = /* @__PURE__ */ new Map();
611
684
  types = {};
612
685
  labels = [];
613
686
  visibleLabelType;
@@ -646,56 +719,126 @@ var OEM = class {
646
719
  if (!point.position || typeof point.position.regionId !== "string") {
647
720
  throw new Error(`Invalid custom point position: ${id}`);
648
721
  }
722
+ const position = point.position;
649
723
  if (point.style !== "framed" && point.style !== "no-frame") {
650
724
  throw new Error(`Invalid custom point style: ${id}`);
651
725
  }
652
726
  if (typeof point.icon !== "string" || !point.icon) {
653
727
  throw new Error(`Custom point icon must be a non-empty URL: ${id}`);
654
728
  }
655
- const pointRegion = getOEMRegion(this.manifest, point.position.regionId);
656
- toOEMLeafletMapPosition(point.position);
657
- if (point.position.subregionId && !pointRegion.subregions.some((subregion) => subregion.id === point.position.subregionId)) {
658
- throw new Error(`Unknown custom point subregion ${point.position.subregionId} in ${point.position.regionId}`);
729
+ const pointRegion = getOEMRegion(this.manifest, position.regionId);
730
+ toOEMLeafletMapPosition(position);
731
+ if (position.subregionId && !pointRegion.subregions.some((subregion) => subregion.id === position.subregionId)) {
732
+ throw new Error(`Unknown custom point subregion ${position.subregionId} in ${position.regionId}`);
659
733
  }
660
- if (point.position.floorId && !pointRegion.floors.some((floor) => floor.id === point.position.floorId)) {
661
- throw new Error(`Unknown custom point floor ${point.position.floorId} in ${point.position.regionId}`);
734
+ if (position.floorId && !pointRegion.floors.some((floor) => floor.id === position.floorId)) {
735
+ throw new Error(`Unknown custom point floor ${position.floorId} in ${position.regionId}`);
662
736
  }
663
- return { ...cloneCustomPoint(point), id };
737
+ return { ...cloneCustomPoint({ ...point, position }), id };
664
738
  });
665
739
  }
740
+ normalizeClickPointOptions(options) {
741
+ const probe = {
742
+ id: "click-point-option",
743
+ position: { regionId: this.region.id, x: 0, z: 0 },
744
+ style: options?.style,
745
+ icon: options?.icon
746
+ };
747
+ this.normalizeCustomPoints([probe]);
748
+ if (options.mode !== "multiple" && options.mode !== "single") {
749
+ throw new Error(`Invalid click point mode: ${options.mode}`);
750
+ }
751
+ return { mode: options.mode, style: options.style, icon: options.icon };
752
+ }
666
753
  position(latlng) {
667
754
  return fromOEMLeafletPosition(latlng.lat, latlng.lng, this.region, this.floorId);
668
755
  }
669
- inferSubregionId(x, y) {
670
- const selected = this.filter.subregions?.filter((id) => this.region.subregions.some((subregion) => subregion.id === id));
671
- if (selected?.length === 1) {
672
- const subregion = this.region.subregions.find((entry) => entry.id === selected[0]);
673
- if (!subregion?.bounds) return subregion?.id;
674
- const scale2 = 2 ** this.region.maxNativeZoom;
675
- const [[minX, minY], [maxX, maxY]] = subregion.bounds;
676
- const pixelX2 = x * scale2;
677
- const pixelY2 = y * scale2;
678
- if (pixelX2 >= minX && pixelX2 <= maxX && pixelY2 >= minY && pixelY2 <= maxY) return subregion.id;
756
+ loadOEMBoundaryData(reference) {
757
+ const cached = this.boundaryData.get(reference.path);
758
+ if (cached) return Promise.resolve(cached);
759
+ const pending = this.boundaryDataRequests.get(reference.path);
760
+ if (pending) return pending;
761
+ const request = fetchOEMJson(resolveOEMAsset(this.options.resources.baseUrl, reference.path), this.options.signal).then((value) => {
762
+ if (!Array.isArray(value)) throw new Error(`Invalid OEM boundary data: ${reference.path}`);
763
+ const boundaries = value;
764
+ this.boundaryData.set(reference.path, boundaries);
765
+ return boundaries;
766
+ }).finally(() => {
767
+ if (this.boundaryDataRequests.get(reference.path) === request) this.boundaryDataRequests.delete(reference.path);
768
+ });
769
+ this.boundaryDataRequests.set(reference.path, request);
770
+ return request;
771
+ }
772
+ /** Preloads OEM subregion geometry so map clicks can resolve an exact subregion. */
773
+ async prepareSubregionBoundaries() {
774
+ if (!this.region.boundaries) return;
775
+ try {
776
+ await this.loadOEMBoundaryData(this.region.boundaries);
777
+ } catch {
679
778
  }
779
+ }
780
+ inferSubregionId(x, z) {
781
+ const selected = this.filter.subregions?.filter((id) => this.region.subregions.some((subregion) => subregion.id === id));
680
782
  const scale = 2 ** this.region.maxNativeZoom;
681
- const pixelX = x * scale;
682
- const pixelY = y * scale;
683
- return this.region.subregions.find((subregion) => {
684
- if (!subregion.bounds) return false;
685
- const [[minX, minY], [maxX, maxY]] = subregion.bounds;
686
- return pixelX >= minX && pixelX <= maxX && pixelY >= minY && pixelY <= maxY;
687
- })?.id;
783
+ const point = { x: x * scale, z: z * scale };
784
+ const allowed = selected?.length ? new Set(selected) : void 0;
785
+ const geometries = this.region.boundaries ? this.boundaryData.get(this.region.boundaries.path) ?? [] : [];
786
+ const scores = geometries.filter((boundary) => this.region.subregions.some((subregion) => subregion.id === boundary.id) && (!allowed || allowed.has(boundary.id))).map((boundary) => boundaryScore(boundary, point));
787
+ const inside = scores.filter((score) => score.inside);
788
+ if (inside.length) {
789
+ const ranked = inside.map((score) => ({ ...score, wins: 0, margin: 0 }));
790
+ for (let leftIndex = 0; leftIndex < ranked.length; leftIndex += 1) {
791
+ for (let rightIndex = leftIndex + 1; rightIndex < ranked.length; rightIndex += 1) {
792
+ const left = ranked[leftIndex];
793
+ const right = ranked[rightIndex];
794
+ const delta = left.distance - right.distance;
795
+ if (Math.abs(delta) <= 1e-9) continue;
796
+ if (delta > 0) {
797
+ left.wins += 1;
798
+ left.margin += delta;
799
+ right.margin -= delta;
800
+ } else {
801
+ right.wins += 1;
802
+ right.margin -= delta;
803
+ left.margin += delta;
804
+ }
805
+ }
806
+ }
807
+ ranked.sort((left, right) => right.wins - left.wins || right.margin - left.margin || right.distance - left.distance || left.id.localeCompare(right.id));
808
+ return ranked[0].id;
809
+ }
810
+ const bounds = this.region.subregions.filter((subregion) => subregion.bounds && (!allowed || allowed.has(subregion.id))).map((subregion) => {
811
+ const [[minX, minZ], [maxX, maxZ]] = subregion.bounds;
812
+ const insideX = point.x >= minX && point.x <= maxX;
813
+ const insideZ = point.z >= minZ && point.z <= maxZ;
814
+ const dx = insideX ? Math.min(point.x - minX, maxX - point.x) : Math.min(Math.abs(point.x - minX), Math.abs(point.x - maxX));
815
+ const dz = insideZ ? Math.min(point.z - minZ, maxZ - point.z) : Math.min(Math.abs(point.z - minZ), Math.abs(point.z - maxZ));
816
+ return { id: subregion.id, inside: insideX && insideZ, distance: dx * dx + dz * dz };
817
+ }).sort((left, right) => Number(right.inside) - Number(left.inside) || left.distance - right.distance || left.id.localeCompare(right.id));
818
+ if (bounds.length) return bounds[0].id;
819
+ return scores.sort((left, right) => left.distance - right.distance || left.id.localeCompare(right.id))[0]?.id;
688
820
  }
689
821
  emitMapClick = (event) => {
690
822
  if (this.destroyed) return;
691
- const subregionId = this.inferSubregionId(event.latlng.lng, -event.latlng.lat);
823
+ const subregionId = this.inferSubregionId(event.latlng.lng, event.latlng.lat);
692
824
  const position = {
693
825
  regionId: this.region.id,
694
826
  x: event.latlng.lng,
695
- y: -event.latlng.lat,
827
+ z: event.latlng.lat,
696
828
  floorId: this.floorId,
697
829
  ...subregionId ? { subregionId } : {}
698
830
  };
831
+ if (this.clickPointOptions) {
832
+ const point = {
833
+ id: `oem-click-point-${++this.clickPointSequence}`,
834
+ position,
835
+ style: this.clickPointOptions.style,
836
+ icon: this.clickPointOptions.icon
837
+ };
838
+ if (this.clickPointOptions.mode === "single") this.clickPoints = [point];
839
+ else this.clickPoints.push(point);
840
+ this.renderCustomPoints();
841
+ }
699
842
  this.emit("click", { position, game: mapToGameXZPosition(position, this.region) });
700
843
  };
701
844
  emit(event, payload) {
@@ -724,7 +867,7 @@ var OEM = class {
724
867
  emitView = () => {
725
868
  if (this.destroyed || this.updatingView) return;
726
869
  const view = this.getView();
727
- if (this.emittedView && view.regionId === this.emittedView.regionId && view.floorId === this.emittedView.floorId && view.x === this.emittedView.x && view.y === this.emittedView.y && view.zoom === this.emittedView.zoom) return;
870
+ if (this.emittedView && view.regionId === this.emittedView.regionId && view.floorId === this.emittedView.floorId && view.x === this.emittedView.x && view.z === this.emittedView.z && view.zoom === this.emittedView.zoom) return;
728
871
  this.emittedView = view;
729
872
  this.emit("viewchange", view);
730
873
  this.renderLabels();
@@ -752,7 +895,7 @@ var OEM = class {
752
895
  this.floorTiles?.remove();
753
896
  this.floorTiles = void 0;
754
897
  this.floorId = "M";
755
- this.map.setMaxBounds(L4.latLngBounds([]));
898
+ this.map.setMaxBounds(L5.latLngBounds([]));
756
899
  this.map.setMinZoom(this.region.minZoom);
757
900
  this.map.setMaxZoom(this.region.maxZoom);
758
901
  const target = view ?? this.region.initialView;
@@ -763,10 +906,10 @@ var OEM = class {
763
906
  }
764
907
  /** Converts the region's published pixel extent to Simple CRS bounds. */
765
908
  regionBounds() {
766
- const { x, y } = this.region.boundsOffset;
767
- return L4.latLngBounds(
768
- toOEMLeafletPosition({ regionId: this.region.id, x, y }, this.region),
769
- toOEMLeafletPosition({ regionId: this.region.id, x: x + this.region.dimensions[0], y: y + this.region.dimensions[1] }, this.region)
909
+ const { x, z } = this.region.boundsOffset;
910
+ return L5.latLngBounds(
911
+ toOEMLeafletPosition({ regionId: this.region.id, x, z }, this.region),
912
+ toOEMLeafletPosition({ regionId: this.region.id, x: x + this.region.dimensions[0], z: z + this.region.dimensions[1] }, this.region)
770
913
  );
771
914
  }
772
915
  /** Creates a coverage-aware layer for one region floor. */
@@ -811,7 +954,7 @@ var OEM = class {
811
954
  /** Fits the map to an OEM pixel-coordinate extent. */
812
955
  fitBounds(bounds) {
813
956
  this.assertAlive();
814
- this.map.fitBounds(L4.latLngBounds(toOEMLeafletPosition(bounds[0], this.region), toOEMLeafletPosition(bounds[1], this.region)), { animate: false });
957
+ this.map.fitBounds(L5.latLngBounds(toOEMLeafletPosition(bounds[0], this.region), toOEMLeafletPosition(bounds[1], this.region)), { animate: false });
815
958
  }
816
959
  /** Switches regions and reloads only the features currently enabled. */
817
960
  async setRegion(regionId) {
@@ -831,6 +974,7 @@ var OEM = class {
831
974
  this.emit("regionchange", { regionId });
832
975
  this.emit("floorchange", { floorId: "M" });
833
976
  this.emitView();
977
+ await this.prepareSubregionBoundaries();
834
978
  await this.loadFeatures();
835
979
  }
836
980
  /** Switches the rendered floor while retaining the current region view. */
@@ -873,6 +1017,16 @@ var OEM = class {
873
1017
  async setFeatures(features) {
874
1018
  this.assertAlive();
875
1019
  const loads = [];
1020
+ if (features.boundarySource !== void 0) {
1021
+ if (features.boundarySource !== "oem" && features.boundarySource !== "game") {
1022
+ throw new Error(`Unknown OEM boundary source: ${features.boundarySource}`);
1023
+ }
1024
+ if (features.boundarySource !== this.boundarySource) {
1025
+ this.boundarySource = features.boundarySource;
1026
+ this.cancelRequest("boundaries");
1027
+ if (this.features.boundaries) loads.push(this.loadFeature("boundaries"));
1028
+ }
1029
+ }
876
1030
  for (const feature of FEATURE_NAMES) {
877
1031
  if (features[feature] === void 0 || features[feature] === this.features[feature]) continue;
878
1032
  this.features[feature] = features[feature];
@@ -887,7 +1041,7 @@ var OEM = class {
887
1041
  this.labelsLayer.clearLayers();
888
1042
  } else this.boundariesLayer.clearLayers();
889
1043
  }
890
- await Promise.all(loads);
1044
+ await Promise.allSettled(loads);
891
1045
  }
892
1046
  /** Replaces host-defined points without reloading static map data. */
893
1047
  setCustomPoints(points) {
@@ -897,6 +1051,22 @@ var OEM = class {
897
1051
  this.customPoints = this.normalizeCustomPoints(points);
898
1052
  this.renderCustomPoints();
899
1053
  }
1054
+ /** Enables or disables automatic custom-point creation from map clicks. */
1055
+ setClickPointMode(options) {
1056
+ this.assertAlive();
1057
+ this.clickPointOptions = options == null ? void 0 : this.normalizeClickPointOptions(options);
1058
+ if (this.clickPointOptions?.mode === "single" && this.clickPoints.length > 1) {
1059
+ this.clickPoints = [this.clickPoints.at(-1)];
1060
+ this.renderCustomPoints();
1061
+ }
1062
+ }
1063
+ /** Removes only points created by the click-point mode. */
1064
+ clearClickPoints() {
1065
+ this.assertAlive();
1066
+ if (!this.clickPoints.length) return;
1067
+ this.clickPoints = [];
1068
+ this.renderCustomPoints();
1069
+ }
900
1070
  loadCustomPoints(url) {
901
1071
  this.assertAlive();
902
1072
  const value = url.trim();
@@ -937,7 +1107,7 @@ var OEM = class {
937
1107
  this.customPointsRequest?.controller.abort();
938
1108
  this.customPointsRequest = void 0;
939
1109
  this.customPoints = [];
940
- this.customPointsLayer.clearLayers();
1110
+ this.renderCustomPoints();
941
1111
  }
942
1112
  /** Returns a loaded published point from the current region, if available. */
943
1113
  getPoint(pointId) {
@@ -992,8 +1162,9 @@ var OEM = class {
992
1162
  const cached = this.pointShardRequests.get(path);
993
1163
  if (cached) return cached;
994
1164
  const request = fetchOEMJson(resolveOEMAsset(this.options.resources.baseUrl, path), this.options.signal).then((value) => {
995
- if (!Array.isArray(value)) throw new Error(`Invalid OEM point shard: ${path}`);
996
- return value;
1165
+ const region = this.manifest.regions.find((entry) => entry.points.some((ref) => ref.path === path));
1166
+ if (!region || !Array.isArray(value)) throw new Error(`Invalid OEM point shard: ${path}`);
1167
+ return this.decodePointShard(value, path, region);
997
1168
  }).catch((error) => {
998
1169
  if (this.pointShardRequests.get(path) === request) this.pointShardRequests.delete(path);
999
1170
  throw error;
@@ -1001,6 +1172,10 @@ var OEM = class {
1001
1172
  this.pointShardRequests.set(path, request);
1002
1173
  return request;
1003
1174
  }
1175
+ decodePointShard(value, shardPath, region = this.region) {
1176
+ const fallbackSubregionId = shardPath.split("/").at(-1)?.replace(/\.json$/, "") ?? "";
1177
+ return value.map((entry) => decodeAtlosPoint(entry, region, fallbackSubregionId)).filter((entry) => !!entry);
1178
+ }
1004
1179
  cancelRequest(feature) {
1005
1180
  if (!this.requests.has(feature)) return;
1006
1181
  this.requests.get(feature).abort();
@@ -1011,7 +1186,7 @@ var OEM = class {
1011
1186
  for (const feature of this.requests.keys()) this.cancelRequest(feature);
1012
1187
  }
1013
1188
  async loadFeatures() {
1014
- await Promise.all(FEATURE_NAMES.filter((feature) => this.features[feature]).map((feature) => this.loadFeature(feature)));
1189
+ await Promise.allSettled(FEATURE_NAMES.filter((feature) => this.features[feature]).map((feature) => this.loadFeature(feature)));
1015
1190
  }
1016
1191
  /** Loads one feature with a request token so stale responses are ignored. */
1017
1192
  async loadFeature(feature) {
@@ -1023,7 +1198,11 @@ var OEM = class {
1023
1198
  try {
1024
1199
  if (feature === "points") {
1025
1200
  const [groups, types] = await Promise.all([
1026
- Promise.all(this.region.points.map((ref) => read(ref))),
1201
+ Promise.all(this.region.points.map(async (ref) => {
1202
+ const value = await read(ref);
1203
+ if (!Array.isArray(value)) throw new Error(`Invalid OEM point shard: ${ref.path}`);
1204
+ return this.decodePointShard(value, ref.path);
1205
+ })),
1027
1206
  Object.keys(this.types).length ? this.types : read(this.manifest.types)
1028
1207
  ]);
1029
1208
  if (request.signal.aborted) return;
@@ -1040,7 +1219,8 @@ var OEM = class {
1040
1219
  this.messages = messages;
1041
1220
  this.renderLabels(true);
1042
1221
  } else {
1043
- const boundaries = this.region.boundaries ? await read(this.region.boundaries) : [];
1222
+ const reference = this.boundarySource === "game" ? this.region.gameBoundaries : this.region.boundaries;
1223
+ const boundaries = reference ? this.boundarySource === "oem" ? await this.loadOEMBoundaryData(reference) : await read(reference) : [];
1044
1224
  if (request.signal.aborted) return;
1045
1225
  this.renderBoundaries(boundaries);
1046
1226
  }
@@ -1102,13 +1282,13 @@ var OEM = class {
1102
1282
  }
1103
1283
  renderCustomPoints() {
1104
1284
  this.customPointsLayer.clearLayers();
1105
- for (const point of this.customPoints) {
1285
+ for (const point of [...this.customPoints, ...this.clickPoints]) {
1106
1286
  if (point.position.regionId !== this.region.id) continue;
1107
1287
  const marker = new OEMMarker(toOEMLeafletMapPosition(point.position), {
1108
1288
  interactive: false,
1109
1289
  keyboard: false,
1110
1290
  bubblingMouseEvents: false,
1111
- icon: L4.divIcon({
1291
+ icon: L5.divIcon({
1112
1292
  html: this.createCustomPointVisual(point),
1113
1293
  className: `${point.style === "no-frame" ? "noFrameMarkerIcon" : "frameMarkerIcon"} incompleteMarker`,
1114
1294
  iconSize: point.style === "no-frame" ? [50, 50] : [32, 32],
@@ -1167,7 +1347,7 @@ var OEM = class {
1167
1347
  interactive: true,
1168
1348
  keyboard: false,
1169
1349
  bubblingMouseEvents: false,
1170
- icon: L4.divIcon({
1350
+ icon: L5.divIcon({
1171
1351
  html: this.createMarkerVisual(type, point),
1172
1352
  className: `${type.noFrame ? "noFrameMarkerIcon" : "frameMarkerIcon"} incompleteMarker`,
1173
1353
  iconSize: type.noFrame ? [50, 50] : [32, 32],
@@ -1176,13 +1356,13 @@ var OEM = class {
1176
1356
  });
1177
1357
  }
1178
1358
  createPointCluster(type) {
1179
- return L4.markerClusterGroup({
1359
+ return L5.markerClusterGroup({
1180
1360
  showCoverageOnHover: false,
1181
1361
  zoomToBoundsOnClick: !this.options.lockZoom,
1182
1362
  spiderfyOnMaxZoom: !this.options.lockZoom,
1183
1363
  disableClusteringAtZoom: 2,
1184
1364
  maxClusterRadius: 60,
1185
- iconCreateFunction: (cluster) => L4.divIcon({
1365
+ iconCreateFunction: (cluster) => L5.divIcon({
1186
1366
  html: this.createMarkerVisual(type, void 0, cluster.getChildCount()),
1187
1367
  className: `${type.noFrame ? "noFrameMarkerIcon" : "frameMarkerIcon"} markerClusterCustom`,
1188
1368
  iconSize: type.noFrame ? [50, 50] : [32, 32],
@@ -1218,13 +1398,13 @@ var OEM = class {
1218
1398
  this.boundariesLayer.clearLayers();
1219
1399
  for (const boundary of boundaries) {
1220
1400
  const rings = boundary.rings.map((ring) => ring.map((position) => toOEMLeafletPosition(position, this.region)));
1221
- L4.polygon(rings, {
1401
+ L5.polygon(rings, {
1222
1402
  color: "transparent",
1223
1403
  fillOpacity: 0.2,
1224
1404
  interactive: false,
1225
1405
  className: "subregionBoundaryFill"
1226
1406
  }).addTo(this.boundariesLayer);
1227
- L4.polygon(rings, {
1407
+ L5.polygon(rings, {
1228
1408
  weight: 2,
1229
1409
  opacity: 0.8,
1230
1410
  fill: false,
@@ -1249,7 +1429,7 @@ var OEM = class {
1249
1429
  pane: "placeLabels",
1250
1430
  interactive: false,
1251
1431
  keyboard: false,
1252
- icon: L4.divIcon({ className: "mapLabel", html: inner, iconSize: [0, 0] })
1432
+ icon: L5.divIcon({ className: "mapLabel", html: inner, iconSize: [0, 0] })
1253
1433
  }).addTo(this.labelsLayer);
1254
1434
  }
1255
1435
  }
@@ -1273,6 +1453,8 @@ var OEM = class {
1273
1453
  this.root.remove();
1274
1454
  this.points = [];
1275
1455
  this.customPoints = [];
1456
+ this.clickPoints = [];
1457
+ this.clickPointOptions = void 0;
1276
1458
  this.customPointsLayer.clearLayers();
1277
1459
  this.pointShardRequests.clear();
1278
1460
  mounted.delete(this.container);
@@ -1281,4 +1463,4 @@ var OEM = class {
1281
1463
  export {
1282
1464
  OEM
1283
1465
  };
1284
- //# sourceMappingURL=runtime-QH7IV2ZV.js.map
1466
+ //# sourceMappingURL=runtime-6E7MGGCD.js.map