ofs-object 0.1.3 → 0.1.5

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/docs/API.md CHANGED
@@ -11,14 +11,22 @@
11
11
  `OFSDataSource` ทำหน้าที่เป็น **Single Source of Truth** จัดเก็บข้อมูล Layer, Feature และสถานะการเลือก (Selection) ทั้งหมด พร้อมระบบ Event Bus แบบ Reactive
12
12
 
13
13
  ```typescript
14
+ // Buffer: ผลเป็น polygon เสมอ — ต้นทางเป็น polygon ลงเลเยอร์เดิม, เป็นเส้น/จุดลงเลเยอร์ `<id>_buffer`
15
+ // (สร้างให้ครั้งแรก) · ระบุ targetLayerId ที่ไม่ใช่ polygon → throw · คืน feature ที่เก็บแล้ว (มี id)
16
+ // ofs.dataSource.buffer('canals', 'c1', 10) → เลเยอร์ 'canals_buffer'
17
+
14
18
  // การเพิ่ม Layer
15
19
  const layer = ofs.dataSource.addLayer({
16
20
  id: 'canals',
17
21
  name: 'คลองส่งน้ำ',
18
22
  type: 'line',
19
23
  zIndex: 2,
24
+ color: '#0ea5e9', // ไม่ใส่ก็ได้ — จะได้สีที่ต่างจากเลเยอร์ที่อยู่บนแผนที่อย่างชัดเจน (สุ่ม)
20
25
  });
21
26
 
27
+ // สีที่อ่านไม่ออก เช่น 'greenish' → throw OFSError ก่อนเพิ่มเลเยอร์
28
+ // อยากได้สีเดิมทุกครั้ง (เทสต์ / screenshot): new OFSThematicEngine({ random: seededFn })
29
+
22
30
  // เพิ่ม Feature พร้อม Undo Record อัตโนมัติ
23
31
  ofs.dataSource.addFeature('canals', lineGeoJsonFeature);
24
32
 
@@ -59,6 +67,22 @@ ofs.dataSource.on('layer:updated', ({ layer }) => { ... });
59
67
 
60
68
  เครื่องมือวาดเรขาคณิตความแม่นยำสูงระดับ CAD มาพร้อมระบบช่วยจับเส้น/จุดอัตโนมัติ และระบบเลือกวัตถุ (Selection System)
61
69
 
70
+ **Event `draw:complete`** — สิ่งที่ควรรู้ก่อนผูก handler:
71
+
72
+ ```typescript
73
+ ofs.drawTools.on('draw:complete', ({ mode, feature, layerId }) => {
74
+ if (mode === 'modify') return; // ① ยิงตอนจบการแก้ด้วย grips ด้วย — กรองด้วย mode
75
+ openAttributeForm(layerId, feature.id); // ② feature คือตัวที่เก็บลง dataSource แล้ว มี id เสมอ
76
+ ofs.drawTools.setMode('polygon'); // ③ ออกจากโหมดแล้วก่อนยิง event จึงเริ่มวาดต่อในนี้ได้
77
+ });
78
+ ```
79
+
80
+ - ② ก่อน 29 ก.ย. 2026 `feature` เป็น object ก่อนเก็บ **ไม่มี `id`** — ค่าที่ `finishDrawing()`,
81
+ `drawPointByCoords` / `drawLineByCoords` / `drawPolygonByCoords`, offset แบบ copy และ `dataSource.buffer()`
82
+ คืนมาก็เป็นแบบนั้น ตอนนี้คืนตัวที่เก็บแล้วทั้งหมด
83
+ - ④ รูปที่วาด**บันทึก undo ไปแล้ว**ตอน event ยิง — ถ้า handler แก้ feature ต่อ (เช่นเติม property) จะเป็น undo อีกขั้น
84
+ ใช้ `ofs.dataSource.runTransaction()` ครอบถ้าต้องการให้ undo ทีเดียว
85
+
62
86
  ```typescript
63
87
  // เปิดโหมดการวาดและเลือกวัตถุ
64
88
  ofs.drawTools.setMode('polygon'); // 'point' | 'line' | 'polygon' | 'circle' | 'rectangle' | 'select' | 'select-box' | 'select-polygon' | 'modify'
@@ -323,7 +347,7 @@ ofs.attributes.statistics('plots', 'yield'); // count, min, max, sum
323
347
 
324
348
  | กลุ่ม | ตัวอย่าง |
325
349
  |---|---|
326
- | ฟิลด์ / ข้อความ | `crop`, `"ชื่อ มีเว้นวรรค"`, `'ข้าว'` |
350
+ | ฟิลด์ / ข้อความ | `crop`, `"ชื่อ มีเว้นวรรค"`, `'ข้าว'` · ในข้อความ: `\n` ขึ้นบรรทัดใหม่, `\t`, `\\`, `\'` หรือ `''` = quote (แบบ QGIS) — backslash หน้าตัวอื่นคงไว้ตามเดิม |
327
351
  | ตัวดำเนินการ | `= <> < <= > >= + - * / % ^ \|\|` · `AND OR NOT` · `IN ('ข้าว','อ้อย')` · `LIKE 'A%'` / `ILIKE` · `IS NULL` |
328
352
  | ค่าเรขาคณิต | `$area` (ตร.ม.), `$perimeter`, `$length`, `$x`, `$y`, `$id`, `area('rai')`, `perimeter('km')` |
329
353
  | หน่วยไทย | `area('rai')`, `area('ngan')`, `area('wa')`, `rai_ngan_wa()` → `"3-2-45.5"` (1 ไร่ = 4 งาน = 400 ตร.วา = 1,600 ตร.ม.) |
@@ -345,7 +369,12 @@ ofs.attributes.statistics('plots', 'yield'); // count, min, max, sum
345
369
  // Label จากฟิลด์ หรือจากนิพจน์ (คำนวณให้ก่อนส่งเข้าแผนที่ จึงใช้ $area / rai_ngan_wa() ได้)
346
370
  ofs.legendTools.setLabel('plots', { field: 'owner', size: 13, haloColor: '#fff', minZoom: 14 });
347
371
  ofs.legendTools.setLabel('plots', { expression: "concat(owner, ' ', rai_ngan_wa())" });
372
+ ofs.legendTools.setLabel('plots', { expression: "\"owner\" || '\\n' || rai_ngan_wa()" }); // 2 บรรทัด
348
373
  ofs.legendTools.setLabel('plots', null); // เอาป้ายออก
374
+ // ฟอนต์: ไม่ระบุ → ใช้ฟอนต์เดียวกับป้ายของ basemap (มีบน glyph server ของ style นั้นแน่นอน เช่น Noto Sans
375
+ // บน OpenFreeMap) · ระบุเองด้วย { font: ['Noto Sans Bold'] } · เปลี่ยน renderer (Single/Categorized/
376
+ // Graduated) แล้ว label ไม่หาย
377
+ // เส้นช่วยขณะวาด: ofs.drawTools.setGuides({ font: ['Noto Sans Regular'] }) มีผลทันที · null = ตาม basemap
349
378
 
350
379
  // วัดระยะ / พื้นที่ / มุม (ระยะบนพื้นจริง)
351
380
  import { measureDistance, measureArea, measureAngle, formatArea } from 'ofs-object';
@@ -414,6 +443,8 @@ await mapAdapter.init('map-div', { maplibregl, center: [100.5, 13.7], zoom: 14 }
414
443
 
415
444
  // หรือสำหรับ Mapbox GL JS
416
445
  const mapAdapter = new MapboxAdapter();
446
+ // เลเยอร์ที่ ≤ 5,000 feature ส่งเฉพาะส่วนที่เปลี่ยน (Mapbox ≥ 3.4) เลเยอร์ใหญ่กว่าส่งทั้งชุด
447
+ // ปรับได้: mapAdapter.dynamicSourceMaxFeatures = 2000 (0 = ส่งทั้งชุดเสมอ)
417
448
  await mapAdapter.init('map-div', {
418
449
  mapboxgl,
419
450
  accessToken: 'YOUR_MAPBOX_TOKEN',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofs-object",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Framework-agnostic TypeScript Library for GIS Map Tools (Data Adapter, Draw Tools, Legend & Thematic Symbology, Map Adapters, Web CLI & AI Bridge)",
5
5
  "license": "MIT",
6
6
  "author": "On-Farm Solution Co.,Ltd.",