ofs-object 0.1.1 → 0.1.4

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/README.md CHANGED
@@ -47,6 +47,38 @@ npm install mapbox-gl
47
47
 
48
48
  > MapLibre v6 เป็น ES module ล้วน (ไม่มี CommonJS) ถ้าจะใช้ `require()` ใน Node ต้องใช้ MapLibre v5 หรือใช้ Mapbox แทน — ผ่าน bundler (Angular, Vite, webpack) ใช้ได้ตามปกติ
49
49
 
50
+ #### ⚠️ ต้องส่ง Map Engine เข้ามาเอง
51
+
52
+ **ไลบรารีนี้ไม่ `import` map engine ตัวไหนเลย** — เพราะถ้า import ตัวใดตัวหนึ่งไว้ มันจะกลายเป็น
53
+ dependency บังคับของทุกคน คนที่ใช้ Mapbox และไม่ได้ลง `maplibre-gl` จะ build ไม่ผ่านด้วย
54
+ `Can't resolve 'maplibre-gl'` ตั้งแต่ยังไม่ได้รันโค้ด
55
+
56
+ ดังนั้นตอนให้ `init()` สร้างแผนที่ ต้องส่ง library เข้ามาด้วย:
57
+
58
+ ```typescript
59
+ // MapLibre v6 ไม่มี default export → ใช้ namespace import
60
+ import * as maplibregl from 'maplibre-gl';
61
+
62
+ const ofs = new OFSObject({ mapOptions: { maplibregl } });
63
+ await ofs.init('map', { center: [100.5, 13.7], zoom: 12 });
64
+ ```
65
+
66
+ ```typescript
67
+ // Mapbox
68
+ import mapboxgl from 'mapbox-gl';
69
+
70
+ const ofs = new OFSObject({
71
+ mapAdapter: new MapboxAdapter(),
72
+ mapOptions: { mapboxgl, accessToken: 'pk....' },
73
+ });
74
+ await ofs.init('map');
75
+ ```
76
+
77
+ หรือโหลดจาก `<script>` tag ก็ได้ ไลบรารีจะอ่านจาก `window.maplibregl` / `window.mapboxgl` ให้เอง
78
+
79
+ > **ถ้าแอปสร้าง Map เอง** (แนะนำสำหรับ Angular/React/Vue — ดูหัวข้อด้านล่าง) แล้วส่งเข้ามาทาง
80
+ > `new OFSObject({ map })` **ไม่ต้องส่ง engine เลย** เพราะไลบรารีไม่ต้องสร้างแผนที่
81
+
50
82
  ### Stylesheet
51
83
 
52
84
  Widget ที่ไลบรารี mount ให้ (Command Console, Legend, แผง Symbology, ตาราง Attribute, แผง Topology) ต้องการไฟล์ CSS หนึ่งไฟล์:
@@ -95,12 +127,15 @@ npm install git+ssh://git@github.com/<user>/OnFarmObject.git#main
95
127
 
96
128
  ```typescript
97
129
  import { OFSObject, MapLibreAdapter, LegendWidget } from 'ofs-object';
130
+ import * as maplibregl from 'maplibre-gl';
98
131
  import 'maplibre-gl/dist/maplibre-gl.css';
99
132
 
100
133
  async function initMap() {
101
134
  // 1. สร้าง Instance หลักของ OFSObject (ใช้ MapLibre เป็นค่าเริ่มต้น)
135
+ // ต้องส่ง maplibregl เข้ามา เพราะไลบรารีไม่ import map engine เอง
102
136
  const ofs = new OFSObject({
103
137
  mapAdapter: new MapLibreAdapter(),
138
+ mapOptions: { maplibregl },
104
139
  });
105
140
 
106
141
  // 2. กำหนดแผนที่ลงบน HTML Container Element id="map"
@@ -259,8 +294,9 @@ initMap();
259
294
 
260
295
  <script type="module">
261
296
  import { OFSObject } from 'ofs-object';
297
+ import * as maplibregl from 'maplibre-gl';
262
298
 
263
- const ofs = new OFSObject();
299
+ const ofs = new OFSObject({ mapOptions: { maplibregl } });
264
300
  await ofs.init('map');
265
301
  ofs.consoleWidget.mount('console-mount');
266
302
  </script>
@@ -273,6 +309,7 @@ initMap();
273
309
  ```tsx
274
310
  import React, { useEffect, useRef } from 'react';
275
311
  import { OFSObject, LegendWidget } from 'ofs-object';
312
+ import * as maplibregl from 'maplibre-gl';
276
313
  import 'maplibre-gl/dist/maplibre-gl.css';
277
314
 
278
315
  export const MapView: React.FC = () => {
@@ -283,7 +320,7 @@ export const MapView: React.FC = () => {
283
320
  useEffect(() => {
284
321
  if (!mapContainerRef.current) return;
285
322
 
286
- const ofs = new OFSObject();
323
+ const ofs = new OFSObject({ mapOptions: { maplibregl } });
287
324
  ofsRef.current = ofs;
288
325
 
289
326
  ofs.init(mapContainerRef.current, {
@@ -339,7 +376,7 @@ export class MapViewComponent implements OnInit, OnDestroy {
339
376
  private ofs!: OFSObject;
340
377
 
341
378
  async ngOnInit() {
342
- this.ofs = new OFSObject();
379
+ this.ofs = new OFSObject({ mapOptions: { maplibregl } });
343
380
  await this.ofs.init(this.mapContainer.nativeElement, {
344
381
  center: [100.5, 13.7],
345
382
  zoom: 13,
@@ -455,6 +492,7 @@ const ofs = new OFSObject({ map, console: myAngularConsole });
455
492
  <script setup lang="ts">
456
493
  import { onMounted, onUnmounted, ref } from 'vue';
457
494
  import { OFSObject, LegendWidget } from 'ofs-object';
495
+ import * as maplibregl from 'maplibre-gl';
458
496
  import 'maplibre-gl/dist/maplibre-gl.css';
459
497
 
460
498
  const mapContainer = ref<HTMLDivElement | null>(null);
@@ -464,7 +502,7 @@ let ofs: OFSObject | null = null;
464
502
  onMounted(async () => {
465
503
  if (!mapContainer.value) return;
466
504
 
467
- ofs = new OFSObject();
505
+ ofs = new OFSObject({ mapOptions: { maplibregl } });
468
506
  await ofs.init(mapContainer.value, {
469
507
  center: [100.5, 13.7],
470
508
  zoom: 12,