ofs-object 0.1.4 → 0.1.6

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,6 +11,10 @@
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',
@@ -63,6 +67,22 @@ ofs.dataSource.on('layer:updated', ({ layer }) => { ... });
63
67
 
64
68
  เครื่องมือวาดเรขาคณิตความแม่นยำสูงระดับ CAD มาพร้อมระบบช่วยจับเส้น/จุดอัตโนมัติ และระบบเลือกวัตถุ (Selection System)
65
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
+
66
86
  ```typescript
67
87
  // เปิดโหมดการวาดและเลือกวัตถุ
68
88
  ofs.drawTools.setMode('polygon'); // 'point' | 'line' | 'polygon' | 'circle' | 'rectangle' | 'select' | 'select-box' | 'select-polygon' | 'modify'
@@ -178,6 +198,8 @@ ofs.legendTools.setThematicSimple('parcels', '#0284c7');
178
198
  // 2. จำแนกข้อมูลแบบกลุ่มข้อความ (Categorical / Unique Values)
179
199
  // เหมาะสำหรับประเภทพืช, พันธุ์ข้าว, ชนิดดิน
180
200
  ofs.legendTools.setThematicCategorical('parcels', 'crop', 'category10');
201
+ // ตารางสีตายตัว: เก็บหมวดที่ยังไม่มีข้อมูลไว้ตอน reclassify (สีเดิม, count 0) แทนการลบทิ้ง
202
+ ofs.legendTools.setThematicCategorical('parcels', 'crop', 'category10', { keepEmptyCategories: true });
181
203
 
182
204
  // 3. จำแนกข้อมูลแบบชั้นปริมาณ (Graduated / Choropleth)
183
205
  // เหมาะสำหรับค่า NDVI, ผลผลิต (kg/ไร่), ความชื้น
@@ -327,7 +349,7 @@ ofs.attributes.statistics('plots', 'yield'); // count, min, max, sum
327
349
 
328
350
  | กลุ่ม | ตัวอย่าง |
329
351
  |---|---|
330
- | ฟิลด์ / ข้อความ | `crop`, `"ชื่อ มีเว้นวรรค"`, `'ข้าว'` |
352
+ | ฟิลด์ / ข้อความ | `crop`, `"ชื่อ มีเว้นวรรค"`, `'ข้าว'` · ในข้อความ: `\n` ขึ้นบรรทัดใหม่, `\t`, `\\`, `\'` หรือ `''` = quote (แบบ QGIS) — backslash หน้าตัวอื่นคงไว้ตามเดิม |
331
353
  | ตัวดำเนินการ | `= <> < <= > >= + - * / % ^ \|\|` · `AND OR NOT` · `IN ('ข้าว','อ้อย')` · `LIKE 'A%'` / `ILIKE` · `IS NULL` |
332
354
  | ค่าเรขาคณิต | `$area` (ตร.ม.), `$perimeter`, `$length`, `$x`, `$y`, `$id`, `area('rai')`, `perimeter('km')` |
333
355
  | หน่วยไทย | `area('rai')`, `area('ngan')`, `area('wa')`, `rai_ngan_wa()` → `"3-2-45.5"` (1 ไร่ = 4 งาน = 400 ตร.วา = 1,600 ตร.ม.) |
@@ -349,7 +371,15 @@ ofs.attributes.statistics('plots', 'yield'); // count, min, max, sum
349
371
  // Label จากฟิลด์ หรือจากนิพจน์ (คำนวณให้ก่อนส่งเข้าแผนที่ จึงใช้ $area / rai_ngan_wa() ได้)
350
372
  ofs.legendTools.setLabel('plots', { field: 'owner', size: 13, haloColor: '#fff', minZoom: 14 });
351
373
  ofs.legendTools.setLabel('plots', { expression: "concat(owner, ' ', rai_ngan_wa())" });
374
+ ofs.legendTools.setLabel('plots', { expression: "\"owner\" || '\\n' || rai_ngan_wa()" }); // 2 บรรทัด
352
375
  ofs.legendTools.setLabel('plots', null); // เอาป้ายออก
376
+ // ฟอนต์: ไม่ระบุ → ใช้ฟอนต์เดียวกับป้ายของ basemap (มีบน glyph server ของ style นั้นแน่นอน เช่น Noto Sans
377
+ // บน OpenFreeMap) · ระบุเองด้วย { font: ['Noto Sans Bold'] } · เปลี่ยน renderer (Single/Categorized/
378
+ // Graduated) แล้ว label ไม่หาย
379
+ // เส้นช่วยขณะวาด: ofs.drawTools.setGuides({ font: ['Noto Sans Regular'] }) มีผลทันที · null = ตาม basemap
380
+ // basemap แบบ raster (ดาวเทียม, OSM) ไม่มีป้ายให้อ่านฟอนต์ → กำหนดฟอนต์สำรองที่ glyph server มีจริง:
381
+ // new OFSObject({ fallbackFont: ['Noto Sans Regular'] }) หรือ ofs.mapAdapter.setFallbackFont([...])
382
+ // ลำดับ: ฟอนต์ที่ระบุเอง → ฟอนต์ป้ายของ basemap → fallbackFont → ค่า default ของ engine
353
383
 
354
384
  // วัดระยะ / พื้นที่ / มุม (ระยะบนพื้นจริง)
355
385
  import { measureDistance, measureArea, measureAngle, formatArea } from 'ofs-object';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofs-object",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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.",