pukaad-ui-lib 1.222.0 → 1.224.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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pukaad-ui-lib",
3
3
  "configKey": "pukaadUI",
4
- "version": "1.222.0",
4
+ "version": "1.224.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -21,10 +21,14 @@ const mapContainer = ref(null);
21
21
  let map = null;
22
22
  let polygonLayer = null;
23
23
  let marker = null;
24
+ let L = null;
25
+ let drawDebounceTimer = null;
26
+ let subdistrictsCache = null;
27
+ let districtsCache = null;
24
28
  const { getProvinceById } = useThaiAddress();
25
29
  onMounted(async () => {
26
30
  const leafletModule = await import("leaflet");
27
- const L = leafletModule.default ?? leafletModule;
31
+ L = leafletModule.default ?? leafletModule;
28
32
  if (mapContainer.value) {
29
33
  map = L.map(mapContainer.value, {
30
34
  zoomControl: false,
@@ -40,29 +44,51 @@ onMounted(async () => {
40
44
  }
41
45
  });
42
46
  const resizeObserver = new ResizeObserver(() => {
43
- if (map) {
44
- map.invalidateSize();
45
- }
47
+ if (map) map.invalidateSize();
46
48
  });
47
49
  resizeObserver.observe(mapContainer.value);
48
- setTimeout(() => {
49
- if (map) map.invalidateSize();
50
- }, 550);
51
- drawPolygon(L);
50
+ const intersectionObserver = new IntersectionObserver(
51
+ (entries) => {
52
+ entries.forEach((entry) => {
53
+ if (entry.isIntersecting && map) {
54
+ map.invalidateSize();
55
+ if (polygonLayer) {
56
+ map.flyToBounds(polygonLayer.getBounds(), { padding: [20, 20], duration: 0.3 });
57
+ }
58
+ }
59
+ });
60
+ },
61
+ { threshold: 0.1 }
62
+ );
63
+ intersectionObserver.observe(mapContainer.value);
64
+ [100, 300, 600, 1200].forEach((delay) => {
65
+ setTimeout(() => {
66
+ if (map) map.invalidateSize();
67
+ }, delay);
68
+ });
69
+ drawPolygon();
52
70
  }
53
71
  });
54
72
  watch(
55
73
  () => [props.provinceId, props.amphurId, props.tambonId],
56
74
  async () => {
57
- if (typeof window !== "undefined") {
58
- const leafletModule = await import("leaflet");
59
- const L = leafletModule.default ?? leafletModule;
60
- drawPolygon(L);
75
+ if (typeof window === "undefined") return;
76
+ if (!map) {
77
+ await new Promise((resolve) => {
78
+ const timer = setInterval(() => {
79
+ if (map) {
80
+ clearInterval(timer);
81
+ resolve();
82
+ }
83
+ }, 50);
84
+ });
61
85
  }
86
+ if (drawDebounceTimer) clearTimeout(drawDebounceTimer);
87
+ drawDebounceTimer = setTimeout(() => drawPolygon(), 80);
62
88
  }
63
89
  );
64
- const drawPolygon = async (L) => {
65
- if (!map) return;
90
+ const drawPolygon = async () => {
91
+ if (!map || !L) return;
66
92
  if (polygonLayer) {
67
93
  map.removeLayer(polygonLayer);
68
94
  polygonLayer = null;
@@ -73,15 +99,19 @@ const drawPolygon = async (L) => {
73
99
  }
74
100
  let feature = null;
75
101
  if (props.tambonId) {
76
- const module = await import("@/runtime/geo/subdistricts.json");
77
- const subdistrictsGeoJson = module.default || module;
78
- feature = subdistrictsGeoJson.features.find(
102
+ if (!subdistrictsCache) {
103
+ const module = await import("@/runtime/geo/subdistricts.json");
104
+ subdistrictsCache = module.default || module;
105
+ }
106
+ feature = subdistrictsCache.features.find(
79
107
  (f) => f.properties.tam_code === props.tambonId?.toString()
80
108
  );
81
109
  } else if (props.amphurId) {
82
- const module = await import("@/runtime/geo/districts.json");
83
- const districtsGeoJson = module.default || module;
84
- feature = districtsGeoJson.features.find(
110
+ if (!districtsCache) {
111
+ const module = await import("@/runtime/geo/districts.json");
112
+ districtsCache = module.default || module;
113
+ }
114
+ feature = districtsCache.features.find(
85
115
  (f) => f.properties.amp_code === props.amphurId?.toString()
86
116
  );
87
117
  } else if (props.provinceId) {
@@ -105,7 +135,7 @@ const drawPolygon = async (L) => {
105
135
  // handled by rgba
106
136
  }
107
137
  }).addTo(map);
108
- map.fitBounds(polygonLayer.getBounds(), { padding: [20, 20] });
138
+ map.flyToBounds(polygonLayer.getBounds(), { padding: [20, 20], duration: 0.5 });
109
139
  const center = polygonLayer.getBounds().getCenter();
110
140
  const divIcon = L.divIcon({
111
141
  html: mapPinSvg,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pukaad-ui-lib",
3
- "version": "1.222.0",
3
+ "version": "1.224.0",
4
4
  "description": "pukaad-ui for MeMSG",
5
5
  "repository": {
6
6
  "type": "git",