@aapicoits/powermap-web-sdk 1.1.0 → 1.1.1
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 +44 -6
- package/dist/index.d.ts +13 -2
- package/dist/powermap-web-sdk.cjs.cjs +12 -12
- package/dist/powermap-web-sdk.js +410 -377
- package/dist/powermap-web-sdk.umd.cjs +14 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -695,22 +695,60 @@ const map = new PowerMap({
|
|
|
695
695
|
|
|
696
696
|
## 12. 🔍 Search & Geocoding
|
|
697
697
|
|
|
698
|
-
The Web SDK provides built-in search capabilities using the PowerMap Search API.
|
|
698
|
+
The Web SDK provides built-in search capabilities using the PowerMap Search API with automatic script detection, smart field fallbacks, and cross-endpoint query handling.
|
|
699
699
|
|
|
700
700
|
### `search(query, options)`
|
|
701
701
|
|
|
702
702
|
Available options:
|
|
703
703
|
|
|
704
|
-
|
|
705
|
-
|
|
704
|
+
| Option | Type | Default | Description |
|
|
705
|
+
| :--- | :--- | :--- | :--- |
|
|
706
|
+
| `lang` | `string` | `'auto'` | Language mode: `'auto'`, `'th'`, or `'en'`. In `'auto'` mode, script type is detected automatically from Unicode ranges. |
|
|
707
|
+
| `location` | `[lat, lng]` | `-` | `[latitude, longitude]` coordinate pair to prioritize nearby search results. |
|
|
708
|
+
|
|
709
|
+
#### Automatic Script Detection & Fallbacks
|
|
710
|
+
- **`lang: 'auto'`**: Automatically inspects query characters. Thai queries (`[\u0E00-\u0E7F]`) select Thai search services, while English/Latin queries (`[a-zA-Z]`) select English search services.
|
|
711
|
+
- **Mixed Script Handling**: For mixed search terms (e.g. `"Central บางนา"` or `"BTS อโศก"`), if primary search yields no results or contains mixed scripts, the SDK automatically executes a cross-endpoint fallback search and merges unique results.
|
|
712
|
+
- **Smart Field Mapping**: `name` and `address` automatically default to the preferred query language with automatic fallback (`nameEn` -> `nameTh` -> `name` or `nameTh` -> `nameEn` -> `name`), ensuring titles and addresses are never returned as empty strings.
|
|
713
|
+
|
|
714
|
+
#### Returned `SearchResult` Properties
|
|
715
|
+
|
|
716
|
+
Each item in the returned array contains:
|
|
717
|
+
|
|
718
|
+
| Field | Type | Description |
|
|
719
|
+
| :--- | :--- | :--- |
|
|
720
|
+
| `id` / `gid` | `string` | Unique identifier for the POI. |
|
|
721
|
+
| `name` | `string` | Display name in the preferred language with automatic fallback. |
|
|
722
|
+
| `nameEn` | `string` | English name of the place (with Thai fallback). |
|
|
723
|
+
| `nameTh` | `string` | Thai name of the place (with English fallback). |
|
|
724
|
+
| `address` | `string` | Formatted address in the preferred language with fallback. |
|
|
725
|
+
| `addressEn` | `string` | Formatted English address string. |
|
|
726
|
+
| `addressTh` | `string` | Formatted Thai address string. |
|
|
727
|
+
| `position` | `[lat, lng]` | Coordinate pair `[latitude, longitude]` (compatible with Mobile SDK). |
|
|
728
|
+
| `positionLngLat` | `[lng, lat]` | Coordinate pair `[longitude, latitude]` for Web map view manipulation. |
|
|
729
|
+
| `province` / `amphoe` / `tambon` | `string` | Administrative boundary details. |
|
|
730
|
+
| `postCode` | `string` | Postal code if available. |
|
|
731
|
+
| `rawData` | `Object` | Raw Elasticsearch GeoJSON source payload. |
|
|
732
|
+
|
|
733
|
+
### Search Examples
|
|
706
734
|
|
|
707
735
|
```javascript
|
|
708
|
-
|
|
736
|
+
// 1. Auto language detection (Recommended)
|
|
737
|
+
const results = await map.search("Central World");
|
|
709
738
|
|
|
710
739
|
results.forEach(item => {
|
|
711
|
-
console.log(`${item.name}: ${item.address}`);
|
|
712
|
-
console.log(`Position
|
|
740
|
+
console.log(`${item.name} (${item.nameTh}): ${item.address}`);
|
|
741
|
+
console.log(`Position [lat, lng]:`, item.position);
|
|
713
742
|
});
|
|
743
|
+
|
|
744
|
+
// 2. Explicit English search with location prioritization
|
|
745
|
+
const enResults = await map.search("Siam Paragon", {
|
|
746
|
+
lang: 'en',
|
|
747
|
+
location: [13.746, 100.534] // [lat, lng]
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
// 3. Mixed query (Thai + English)
|
|
751
|
+
const mixedResults = await map.search("BTS อโศก", { lang: 'auto' });
|
|
714
752
|
```
|
|
715
753
|
|
|
716
754
|
---
|
package/dist/index.d.ts
CHANGED
|
@@ -88,16 +88,27 @@ export interface RouteSummary {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
export interface SearchResult {
|
|
91
|
-
id
|
|
91
|
+
id?: string;
|
|
92
|
+
gid?: string;
|
|
92
93
|
name: string;
|
|
94
|
+
nameEn?: string;
|
|
95
|
+
nameTh?: string;
|
|
93
96
|
address?: string;
|
|
97
|
+
addressEn?: string;
|
|
98
|
+
addressTh?: string;
|
|
94
99
|
position: [number, number];
|
|
100
|
+
positionLngLat?: [number, number];
|
|
101
|
+
province?: string;
|
|
102
|
+
amphoe?: string;
|
|
103
|
+
tambon?: string;
|
|
104
|
+
postCode?: string;
|
|
105
|
+
rawData?: Record<string, unknown>;
|
|
95
106
|
[key: string]: unknown;
|
|
96
107
|
}
|
|
97
108
|
|
|
98
109
|
export interface SearchOptions {
|
|
99
110
|
location?: [number, number];
|
|
100
|
-
lang?: string;
|
|
111
|
+
lang?: 'th' | 'en' | 'auto' | string;
|
|
101
112
|
[key: string]: unknown;
|
|
102
113
|
}
|
|
103
114
|
|