pak-geodata 0.1.0 → 0.2.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 +458 -1
- package/dist/data/cities.d.ts.map +1 -1
- package/dist/data/cities.js +897 -0
- package/dist/data/cities.js.map +1 -1
- package/dist/geo.d.ts +20 -0
- package/dist/geo.d.ts.map +1 -1
- package/dist/geo.js +71 -3
- package/dist/geo.js.map +1 -1
- package/dist/hierarchy.cjs +6591 -0
- package/dist/hierarchy.d.ts +39 -0
- package/dist/hierarchy.d.ts.map +1 -0
- package/dist/hierarchy.js +242 -0
- package/dist/hierarchy.js.map +1 -0
- package/dist/index.cjs +1402 -157
- package/dist/index.d.ts +6 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -29
- package/dist/index.js.map +1 -1
- package/dist/search.d.ts +19 -5
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +147 -60
- package/dist/search.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/urdu.d.ts +5 -0
- package/dist/urdu.d.ts.map +1 -0
- package/dist/urdu.js +44 -0
- package/dist/urdu.js.map +1 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
`pak-geodata` is an open-source, production-grade TypeScript and JavaScript client library providing offline access to verified geographic data for Pakistan, created and maintained by [Sohaib Bin Mohsin](https://sohaibbinmohsin.com) at [The Mohsin Project Global](https://themohsinproject.org).
|
|
6
6
|
|
|
7
|
-
It covers all administrative provinces,
|
|
7
|
+
It covers all administrative provinces, 79 major and secondary cities, and 189 foundational flagship metropolitan areas (sectors, housing schemes, neighborhoods, and commercial centers).
|
|
8
8
|
|
|
9
9
|
Designed with **zero runtime dependencies**, strict geofencing, sub-millisecond lookups, and modular tree-shakeable subpath exports.
|
|
10
10
|
|
|
@@ -14,6 +14,10 @@ Designed with **zero runtime dependencies**, strict geofencing, sub-millisecond
|
|
|
14
14
|
|
|
15
15
|
- **Zero Runtime Dependencies**: Completely self-contained with 0 runtime dependencies.
|
|
16
16
|
- **Dual Module Support**: Full ESM (`import`) and CommonJS (`require`) support.
|
|
17
|
+
- **Bilingual Administrative Hierarchy (`PakLocationItem`)**: Unified administrative data structure connecting provinces, cities/districts, and areas with synchronized English and Urdu names.
|
|
18
|
+
- **Resilient O(1) Key Lookups**: Pre-indexed instant resolution via `getCityName(key, lang)` and `getAreaName(cityKey, areaKey, lang)` supporting case-insensitive slugs, title names, and colloquial aliases.
|
|
19
|
+
- **Lightweight PWA Subpath (`pak-geodata/hierarchy`)**: Code-split micro-bundle (< 5 KB gzipped) designed specifically for offline-first emergency response Progressive Web Apps.
|
|
20
|
+
- **Urdu Script & Numeral Normalization**: Robust bidirectional matching across Eastern Arabic numerals (`۳` vs `3`), Urdu letter variants (`ي` vs `ی`, `ك` vs `ک`), and diacritic stripping.
|
|
17
21
|
- **Subpath Tree-Shaking**: Import only the areas you need (e.g. `pak-geodata/areas/lahore`) to keep your bundle footprint under a few kilobytes.
|
|
18
22
|
- **Offline & Self-Contained**: All verified golden datasets are bundled with the library: no remote API calls or latency.
|
|
19
23
|
- **Strict Geofencing & Validation**: Every coordinate is rigorously validated within Pakistan territorial boundaries (`23.5 <= lat <= 37.1`, `60.8 <= lng <= 77.8`) and city district bounding boxes.
|
|
@@ -173,10 +177,463 @@ console.log(`Postal code 54000: ${area?.name} (${area?.cityId})`);
|
|
|
173
177
|
const areas = findAreasByPostalCode(54000);
|
|
174
178
|
```
|
|
175
179
|
|
|
180
|
+
### 7. Bilingual Administrative Hierarchy & O(1) Lookups
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import {
|
|
184
|
+
getCityName,
|
|
185
|
+
getAreaName,
|
|
186
|
+
getProvincesAsLocationItems,
|
|
187
|
+
getCitiesAsLocationItems,
|
|
188
|
+
getAreasAsLocationItems,
|
|
189
|
+
searchAreas
|
|
190
|
+
} from 'pak-geodata';
|
|
191
|
+
|
|
192
|
+
// 1. Instant O(1) bilingual name resolution
|
|
193
|
+
console.log(getCityName('Lahore', 'ur')); // "لاہور"
|
|
194
|
+
console.log(getCityName('lahore', 'en')); // "Lahore"
|
|
195
|
+
console.log(getAreaName('Lahore', 'Gulberg', 'ur')); // "گلبرگ ۳"
|
|
196
|
+
console.log(getAreaName('lahore', 'lahore-gulberg-iii', 'en')); // "Gulberg III"
|
|
197
|
+
|
|
198
|
+
// 2. Bilingual hierarchy traversal
|
|
199
|
+
const provinces = getProvincesAsLocationItems();
|
|
200
|
+
console.log(provinces[0]); // { id: 'punjab', nameEn: 'Punjab', nameUr: 'پنجاب', type: 'province' }
|
|
201
|
+
|
|
202
|
+
const punjabCities = getCitiesAsLocationItems('punjab');
|
|
203
|
+
console.log(`Punjab has ${punjabCities.length} verified cities/districts`);
|
|
204
|
+
|
|
205
|
+
// 3. City-scoped bilingual search (Sanctuary overload)
|
|
206
|
+
const results = searchAreas('Lahore', 'DHA 5', 'ur');
|
|
207
|
+
console.log(results[0]);
|
|
208
|
+
// { id: 'lahore-dha-phase-5', nameEn: 'DHA Phase 5', nameUr: 'ڈی ایچ اے فیز ۵', type: 'area', parentId: 'lahore', ... }
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Sanctuary Integration Guide
|
|
214
|
+
|
|
215
|
+
This guide documents the design patterns, data contracts, and implementation specifications built into `pak-geodata` for **Sanctuary**—an offline-first emergency rescue reporting and tracking Progressive Web App (PWA) operating across Pakistan.
|
|
216
|
+
|
|
217
|
+
### 1. Bilingual Administrative Hierarchy (`PakLocationItem`)
|
|
218
|
+
|
|
219
|
+
Emergency dispatching, disaster triage, and community reporting span multiple administrative tiers. Rather than handling disconnected data shapes for provinces, cities, and neighborhoods, `pak-geodata` provides a unified data contract: `PakLocationItem`.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
export type PakLocationType = 'province' | 'division' | 'district' | 'tehsil' | 'area';
|
|
223
|
+
|
|
224
|
+
export interface PakLocationItem {
|
|
225
|
+
id: string; // Canonical identifier (e.g. "punjab", "lahore", "lahore-gulberg-iii")
|
|
226
|
+
nameEn: string; // Standardized English name (e.g. "Punjab", "Lahore", "Gulberg III")
|
|
227
|
+
nameUr: string; // Native Urdu script (e.g. "پنجاب", "لاہور", "گلبرگ ۳")
|
|
228
|
+
type: PakLocationType; // Administrative level
|
|
229
|
+
parentId?: string; // Hierarchy linkage: area -> cityId -> provinceId
|
|
230
|
+
coordinates?: {
|
|
231
|
+
lat: number;
|
|
232
|
+
lng: number;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
#### Hierarchy Traversal Functions
|
|
238
|
+
|
|
239
|
+
- **`getProvincesAsLocationItems(): PakLocationItem[]`**
|
|
240
|
+
Returns all 7 provinces and federal territories (`type: 'province'`, `parentId: undefined`).
|
|
241
|
+
- **`getCitiesAsLocationItems(provinceId?: string): PakLocationItem[]`**
|
|
242
|
+
Returns all 79 verified municipal cities/districts (`type: 'district'`, `parentId: provinceId`). If `provinceId` is provided, filters cities belonging to that province.
|
|
243
|
+
- **`getAreasAsLocationItems(cityKey: string): PakLocationItem[]`**
|
|
244
|
+
Returns all verified areas in a given city (`type: 'area'`, `parentId: cityId`).
|
|
245
|
+
- **`toLocationItem(entity)`**
|
|
246
|
+
Universal converter accepting any `PakistanProvince`, `PakistanCity`, or `PakistanArea` object and mapping it to a standard `PakLocationItem`.
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import {
|
|
250
|
+
getProvincesAsLocationItems,
|
|
251
|
+
getCitiesAsLocationItems,
|
|
252
|
+
getAreasAsLocationItems
|
|
253
|
+
} from 'pak-geodata';
|
|
254
|
+
|
|
255
|
+
// Load provinces
|
|
256
|
+
const provinces = getProvincesAsLocationItems();
|
|
257
|
+
|
|
258
|
+
// Load cities in Sindh
|
|
259
|
+
const sindhCities = getCitiesAsLocationItems('sindh');
|
|
260
|
+
|
|
261
|
+
// Load areas in Karachi
|
|
262
|
+
const karachiAreas = getAreasAsLocationItems('karachi');
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
### 2. Standardized English Storage & Real-Time Localized Display
|
|
268
|
+
|
|
269
|
+
#### Architectural Rationale
|
|
270
|
+
In distributed emergency rescue architectures (PostgreSQL, SQLite, PowerSync, CouchDB), storing free-form Urdu or mixed-script strings in core database records causes severe indexing fragmentation, duplicate collation issues, and inter-agency sync friction.
|
|
271
|
+
|
|
272
|
+
**The Golden Pattern:**
|
|
273
|
+
1. **Database / Persistence Layer**: Always persist canonical, standardized English keys (`city: "Lahore"`, `location_area: "Gulberg"` or `"Gulberg III"`).
|
|
274
|
+
2. **Presentation / UI Layer**: Resolve these keys dynamically at render time into English or native Urdu Nastaliq using resilient O(1) lookup helpers.
|
|
275
|
+
|
|
276
|
+
#### Resilient O(1) Lookup Helpers
|
|
277
|
+
|
|
278
|
+
- **`getCityName(key: string, lang?: 'en' | 'ur'): string`**
|
|
279
|
+
Resolves a city slug (`"lahore"`), title-cased name (`"Lahore"`), or Urdu representation (`"لاہور"`) to the requested language.
|
|
280
|
+
- `getCityName("lahore", "ur")` $\rightarrow$ `"لاہور"`
|
|
281
|
+
- `getCityName("Lahore", "en")` $\rightarrow$ `"Lahore"`
|
|
282
|
+
- Resilient fallback: returns the raw `key` if the city is custom or unverified.
|
|
283
|
+
|
|
284
|
+
- **`getAreaName(cityKey: string, areaKey: string, lang?: 'en' | 'ur'): string`**
|
|
285
|
+
Resolves an area within a city using compound O(1) indexing (`${cityKey}:${areaKey}`). Supports:
|
|
286
|
+
- Canonical slugs: `"lahore-gulberg-iii"`
|
|
287
|
+
- Local slugs without city prefix: `"gulberg-iii"`
|
|
288
|
+
- Title names: `"Gulberg III"`
|
|
289
|
+
- Colloquial aliases: `"Gulberg"`, `"dha 5"`
|
|
290
|
+
- Urdu script queries: `"گلبرگ ۳"`
|
|
291
|
+
- Returns: `"Gulberg III"` (for `'en'`) or `"گلبرگ ۳"` (for `'ur'`).
|
|
292
|
+
- Resilient fallback: returns `areaKey` unchanged if unverified or custom-entered.
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
import { getCityName, getAreaName } from 'pak-geodata';
|
|
296
|
+
|
|
297
|
+
// Standardized DB Record:
|
|
298
|
+
const record = { city: 'Lahore', location_area: 'Gulberg' };
|
|
299
|
+
|
|
300
|
+
// English display:
|
|
301
|
+
console.log(`${getAreaName(record.city, record.location_area, 'en')}, ${getCityName(record.city, 'en')}`);
|
|
302
|
+
// "Gulberg III, Lahore"
|
|
303
|
+
|
|
304
|
+
// Urdu display:
|
|
305
|
+
console.log(`${getCityName(record.city, 'ur')}، ${getAreaName(record.city, record.location_area, 'ur')}`);
|
|
306
|
+
// "لاہور، گلبرگ ۳"
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
### 3. Autocomplete Search with Overloaded `searchAreas` & Urdu Normalization
|
|
312
|
+
|
|
313
|
+
Sanctuary requires responsive autocomplete search scoped to a chosen city, returning typed `PakLocationItem[]` results.
|
|
314
|
+
|
|
315
|
+
#### Function Overload Signatures
|
|
316
|
+
|
|
317
|
+
`pak-geodata` supports two search calling styles:
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
// 1. Sanctuary Overload (city-scoped, returns PakLocationItem[])
|
|
321
|
+
function searchAreas(cityKey: string, query: string, lang?: 'en' | 'ur'): PakLocationItem[];
|
|
322
|
+
|
|
323
|
+
// 2. Direct Named Function (same as Sanctuary overload)
|
|
324
|
+
function searchLocationItems(cityKey: string, query: string, lang?: 'en' | 'ur'): PakLocationItem[];
|
|
325
|
+
|
|
326
|
+
// 3. Classic GIS Overload (global or options-based, returns raw PakistanArea[])
|
|
327
|
+
function searchAreas(query: string, options?: SearchOptions, candidateAreas?: readonly PakistanArea[]): PakistanArea[];
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### Urdu Script & Numeral Normalization Engine
|
|
331
|
+
|
|
332
|
+
Mobile users and rescue field operators in Pakistan frequently switch between English, Urdu Nastaliq keyboards, and Arabic numeral settings. `pak-geodata` transparently pre-normalizes search terms with zero runtime performance cost:
|
|
333
|
+
- **Numeral Unification**: Eastern Arabic-Indic numerals (`۰-۹`), standard Arabic-Indic digits (`٠-٩`), and Western digits (`0-9`) match bidirectionally (`"گلبرگ ۳"` or `"گلبرگ ٣"` matches `"Gulberg 3"`).
|
|
334
|
+
- **Letter Variant Normalization**:
|
|
335
|
+
- Arabic Yeh (`ي`, U+064A) and Alef Maksura (`ى`, U+0649) map to Urdu Yeh (`ی`, U+06CC).
|
|
336
|
+
- Arabic Kaf (`ك`, U+0643) maps to Urdu Keheh (`ک`, U+06A9).
|
|
337
|
+
- Arabic Heh (`ه`, U+0647) maps to Urdu Goal Heh (`ہ`, U+06C1).
|
|
338
|
+
- **Diacritic / Tashkeel & Tatweel Stripping**: Removes Zabar, Zer, Pesh, Tanween, Tashdeed, Sukun, and Tatweel/Kashida (`[\u0640\u064B-\u065F\u0670]`).
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
import { searchAreas } from 'pak-geodata';
|
|
342
|
+
|
|
343
|
+
// Eastern numeral search returns matched PakLocationItem
|
|
344
|
+
const results = searchAreas('Lahore', 'گلبرگ ۳', 'ur');
|
|
345
|
+
console.log(results[0].nameEn); // "Gulberg III"
|
|
346
|
+
console.log(results[0].nameUr); // "گلبرگ ۳"
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
### 4. Lightweight PWA Subpath (`pak-geodata/hierarchy`)
|
|
352
|
+
|
|
353
|
+
PWAs operating in low-connectivity 2G/3G environments must minimize JavaScript bundle sizes. The `./hierarchy` subpath contains administrative boundaries and O(1) lookup engines with **zero neighborhood geospatial overhead**:
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
// ESM or CommonJS import
|
|
357
|
+
import {
|
|
358
|
+
getCityName,
|
|
359
|
+
getAreaName,
|
|
360
|
+
getProvincesAsLocationItems,
|
|
361
|
+
getCitiesAsLocationItems,
|
|
362
|
+
getAreasAsLocationItems,
|
|
363
|
+
searchLocationItems,
|
|
364
|
+
toLocationItem
|
|
365
|
+
} from 'pak-geodata/hierarchy';
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
- **Bundle footprint**: `< 15 KB` unminified, **`< 5 KB` gzipped**.
|
|
369
|
+
- Perfect for initial service worker caching, instant app shell startup, and background tracking views.
|
|
370
|
+
- City-specific areas can be dynamically loaded on demand when the user selects a city via `pak-geodata/areas/<city>`.
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
### 5. Production Implementation Examples
|
|
375
|
+
|
|
376
|
+
#### Example 1: Emergency Incident Reporting Form (`/report`)
|
|
377
|
+
|
|
378
|
+
This component demonstrates how a reporting intake form allows a user to select a city, search areas with real-time bilingual feedback, and submit standardized English keys into the database:
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
import React, { useState, useMemo } from 'react';
|
|
382
|
+
import {
|
|
383
|
+
getCitiesAsLocationItems,
|
|
384
|
+
searchAreas,
|
|
385
|
+
type PakLocationItem
|
|
386
|
+
} from 'pak-geodata';
|
|
387
|
+
|
|
388
|
+
interface IncidentReportPayload {
|
|
389
|
+
reportNumber: string;
|
|
390
|
+
city: string; // Standardized English: e.g. "Lahore"
|
|
391
|
+
location_area: string; // Standardized English: e.g. "Gulberg III"
|
|
392
|
+
coordinates?: {
|
|
393
|
+
lat: number;
|
|
394
|
+
lng: number;
|
|
395
|
+
};
|
|
396
|
+
notes: string;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
interface IncidentReportFormProps {
|
|
400
|
+
lang: 'en' | 'ur';
|
|
401
|
+
onSubmitReport: (payload: IncidentReportPayload) => Promise<void>;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export function IncidentReportForm({ lang, onSubmitReport }: IncidentReportFormProps) {
|
|
405
|
+
const [selectedCityId, setSelectedCityId] = useState<string>('lahore');
|
|
406
|
+
const [areaQuery, setAreaQuery] = useState<string>('');
|
|
407
|
+
const [selectedArea, setSelectedArea] = useState<PakLocationItem | null>(null);
|
|
408
|
+
const [notes, setNotes] = useState<string>('');
|
|
409
|
+
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
|
|
410
|
+
|
|
411
|
+
// 1. Load city options formatted for current language
|
|
412
|
+
const cities = useMemo(() => getCitiesAsLocationItems(), []);
|
|
413
|
+
|
|
414
|
+
// 2. City-scoped bilingual search: handles Urdu script, Eastern numerals ('۳'), and aliases
|
|
415
|
+
const areaSuggestions = useMemo(() => {
|
|
416
|
+
if (!areaQuery.trim() || !selectedCityId) return [];
|
|
417
|
+
// Invokes overloaded Sanctuary signature: searchAreas(cityKey, query, lang)
|
|
418
|
+
return searchAreas(selectedCityId, areaQuery, lang);
|
|
419
|
+
}, [selectedCityId, areaQuery, lang]);
|
|
420
|
+
|
|
421
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
422
|
+
e.preventDefault();
|
|
423
|
+
if (!selectedArea) return;
|
|
424
|
+
|
|
425
|
+
setIsSubmitting(true);
|
|
426
|
+
try {
|
|
427
|
+
const selectedCityObj = cities.find((c) => c.id === selectedCityId);
|
|
428
|
+
|
|
429
|
+
// 3. Persist standardized English keys to database / backend
|
|
430
|
+
const payload: IncidentReportPayload = {
|
|
431
|
+
reportNumber: `SANCTUARY-${Date.now().toString().slice(-6)}`,
|
|
432
|
+
city: selectedCityObj?.nameEn || selectedCityId, // Persist English: "Lahore"
|
|
433
|
+
location_area: selectedArea.nameEn, // Persist English: "Gulberg III"
|
|
434
|
+
coordinates: selectedArea.coordinates,
|
|
435
|
+
notes
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
await onSubmitReport(payload);
|
|
439
|
+
setAreaQuery('');
|
|
440
|
+
setSelectedArea(null);
|
|
441
|
+
setNotes('');
|
|
442
|
+
} finally {
|
|
443
|
+
setIsSubmitting(false);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
return (
|
|
448
|
+
<form className="incident-form" onSubmit={handleSubmit} dir={lang === 'ur' ? 'rtl' : 'ltr'}>
|
|
449
|
+
<h2>{lang === 'ur' ? 'ایمرجنسی رپورٹ درج کریں' : 'Submit Emergency Report'}</h2>
|
|
450
|
+
|
|
451
|
+
{/* City Dropdown */}
|
|
452
|
+
<div className="form-group">
|
|
453
|
+
<label htmlFor="city-select">
|
|
454
|
+
{lang === 'ur' ? 'شہر منتخب کریں' : 'Select City'}
|
|
455
|
+
</label>
|
|
456
|
+
<select
|
|
457
|
+
id="city-select"
|
|
458
|
+
value={selectedCityId}
|
|
459
|
+
onChange={(e) => {
|
|
460
|
+
setSelectedCityId(e.target.value);
|
|
461
|
+
setSelectedArea(null);
|
|
462
|
+
setAreaQuery('');
|
|
463
|
+
}}
|
|
464
|
+
>
|
|
465
|
+
{cities.map((city) => (
|
|
466
|
+
<option key={city.id} value={city.id}>
|
|
467
|
+
{lang === 'ur' ? city.nameUr : city.nameEn}
|
|
468
|
+
</option>
|
|
469
|
+
))}
|
|
470
|
+
</select>
|
|
471
|
+
</div>
|
|
472
|
+
|
|
473
|
+
{/* Area Search / Combobox */}
|
|
474
|
+
<div className="form-group autocomplete-container">
|
|
475
|
+
<label htmlFor="area-search">
|
|
476
|
+
{lang === 'ur' ? 'علاقہ / سیکٹر / محلہ' : 'Area / Neighborhood'}
|
|
477
|
+
</label>
|
|
478
|
+
<input
|
|
479
|
+
id="area-search"
|
|
480
|
+
type="text"
|
|
481
|
+
value={areaQuery}
|
|
482
|
+
onChange={(e) => {
|
|
483
|
+
setAreaQuery(e.target.value);
|
|
484
|
+
setSelectedArea(null);
|
|
485
|
+
}}
|
|
486
|
+
placeholder={lang === 'ur' ? 'تلاش کریں (مثلاً: گلبرگ، ڈی ایچ اے، ۳)' : 'Search (e.g. Gulberg, DHA, Phase 5)'}
|
|
487
|
+
autoComplete="off"
|
|
488
|
+
/>
|
|
489
|
+
|
|
490
|
+
{/* Suggestion Dropdown */}
|
|
491
|
+
{areaSuggestions.length > 0 && !selectedArea && (
|
|
492
|
+
<ul className="suggestions-list">
|
|
493
|
+
{areaSuggestions.map((item) => (
|
|
494
|
+
<li
|
|
495
|
+
key={item.id}
|
|
496
|
+
onClick={() => {
|
|
497
|
+
setSelectedArea(item);
|
|
498
|
+
setAreaQuery(lang === 'ur' ? item.nameUr : item.nameEn);
|
|
499
|
+
}}
|
|
500
|
+
>
|
|
501
|
+
<span className="suggestion-primary">
|
|
502
|
+
{lang === 'ur' ? item.nameUr : item.nameEn}
|
|
503
|
+
</span>
|
|
504
|
+
<span className="suggestion-secondary">
|
|
505
|
+
{lang === 'ur' ? item.nameEn : item.nameUr}
|
|
506
|
+
</span>
|
|
507
|
+
</li>
|
|
508
|
+
))}
|
|
509
|
+
</ul>
|
|
510
|
+
)}
|
|
511
|
+
</div>
|
|
512
|
+
|
|
513
|
+
{/* Additional Notes */}
|
|
514
|
+
<div className="form-group">
|
|
515
|
+
<label htmlFor="notes">
|
|
516
|
+
{lang === 'ur' ? 'واقعے کی تفصیلات' : 'Incident Details'}
|
|
517
|
+
</label>
|
|
518
|
+
<textarea
|
|
519
|
+
id="notes"
|
|
520
|
+
value={notes}
|
|
521
|
+
onChange={(e) => setNotes(e.target.value)}
|
|
522
|
+
rows={3}
|
|
523
|
+
/>
|
|
524
|
+
</div>
|
|
525
|
+
|
|
526
|
+
<button type="submit" disabled={!selectedArea || isSubmitting}>
|
|
527
|
+
{isSubmitting
|
|
528
|
+
? (lang === 'ur' ? 'رپورٹ بھیجی جا رہی ہے...' : 'Submitting...')
|
|
529
|
+
: (lang === 'ur' ? 'ایمرجنسی ٹیم طلب کریں' : 'Request Emergency Rescue')}
|
|
530
|
+
</button>
|
|
531
|
+
</form>
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
---
|
|
537
|
+
|
|
538
|
+
#### Example 2: Emergency Incident Tracking View (`/report/track/:reportNumber`)
|
|
539
|
+
|
|
540
|
+
This component demonstrates how an incident tracking view loads a database record with standardized English fields and dynamically resolves the city and area names using the lightweight `< 5 KB` `pak-geodata/hierarchy` subpath:
|
|
541
|
+
|
|
542
|
+
```typescript
|
|
543
|
+
import React from 'react';
|
|
544
|
+
import {
|
|
545
|
+
getCityName,
|
|
546
|
+
getAreaName
|
|
547
|
+
} from 'pak-geodata/hierarchy'; // Ultra-lightweight subpath (< 5 KB gzipped)
|
|
548
|
+
|
|
549
|
+
export interface RescueIncidentRecord {
|
|
550
|
+
reportNumber: string;
|
|
551
|
+
city: string; // Stored English key: e.g. "Lahore"
|
|
552
|
+
location_area: string; // Stored English key or alias: e.g. "Gulberg"
|
|
553
|
+
status: 'RECEIVED' | 'DISPATCHED' | 'EN_ROUTE' | 'ON_SCENE' | 'RESOLVED';
|
|
554
|
+
reportedAt: string;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
interface IncidentTrackingViewProps {
|
|
558
|
+
incident: RescueIncidentRecord;
|
|
559
|
+
lang: 'en' | 'ur';
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
export function IncidentTrackingView({ incident, lang }: IncidentTrackingViewProps) {
|
|
563
|
+
// O(1) Resilient Lookups: resolves slugs, English names, and aliases in O(1) time
|
|
564
|
+
// e.g. "Lahore" -> "لاہور", "Gulberg" -> "گلبرگ ۳"
|
|
565
|
+
const localizedCity = getCityName(incident.city, lang);
|
|
566
|
+
const localizedArea = getAreaName(incident.city, incident.location_area, lang);
|
|
567
|
+
|
|
568
|
+
const statusMap = {
|
|
569
|
+
RECEIVED: { en: 'Report Received', ur: 'رپورٹ موصول ہو چکی ہے', color: '#f59e0b' },
|
|
570
|
+
DISPATCHED: { en: 'Rescue Team Dispatched', ur: 'ریسکیو ٹیم روانہ ہو چکی ہے', color: '#3b82f6' },
|
|
571
|
+
EN_ROUTE: { en: 'En Route to Location', ur: 'ٹیم جائے وقوعہ کی طرف گامزن ہے', color: '#6366f1' },
|
|
572
|
+
ON_SCENE: { en: 'Team on Scene', ur: 'ٹیم جائے وقوعہ پر پہنچ چکی ہے', color: '#10b981' },
|
|
573
|
+
RESOLVED: { en: 'Incident Resolved', ur: 'ریسکیو مشن مکمل', color: '#059669' }
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
const currentStatus = statusMap[incident.status] || statusMap.RECEIVED;
|
|
577
|
+
|
|
578
|
+
return (
|
|
579
|
+
<div className="tracking-card" dir={lang === 'ur' ? 'rtl' : 'ltr'}>
|
|
580
|
+
<header className="tracking-header">
|
|
581
|
+
<span className="badge">
|
|
582
|
+
{lang === 'ur' ? 'رپورٹ نمبر:' : 'Report #:'} {incident.reportNumber}
|
|
583
|
+
</span>
|
|
584
|
+
<span className="timestamp">
|
|
585
|
+
{new Date(incident.reportedAt).toLocaleTimeString()}
|
|
586
|
+
</span>
|
|
587
|
+
</header>
|
|
588
|
+
|
|
589
|
+
{/* Localized Location Display */}
|
|
590
|
+
<div className="tracking-location-section">
|
|
591
|
+
<div className="location-pin">📍</div>
|
|
592
|
+
<div className="location-details">
|
|
593
|
+
<h3>
|
|
594
|
+
{lang === 'ur'
|
|
595
|
+
? `${localizedCity}، ${localizedArea}`
|
|
596
|
+
: `${localizedArea}, ${localizedCity}`}
|
|
597
|
+
</h3>
|
|
598
|
+
<p className="canonical-subtext">
|
|
599
|
+
{incident.location_area}, {incident.city}
|
|
600
|
+
</p>
|
|
601
|
+
</div>
|
|
602
|
+
</div>
|
|
603
|
+
|
|
604
|
+
{/* Real-time Status */}
|
|
605
|
+
<div className="tracking-status" style={{ borderColor: currentStatus.color }}>
|
|
606
|
+
<div className="status-indicator" style={{ backgroundColor: currentStatus.color }} />
|
|
607
|
+
<span className="status-label">
|
|
608
|
+
{currentStatus[lang]}
|
|
609
|
+
</span>
|
|
610
|
+
</div>
|
|
611
|
+
</div>
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
```
|
|
615
|
+
|
|
176
616
|
---
|
|
177
617
|
|
|
178
618
|
## Data Schema
|
|
179
619
|
|
|
620
|
+
### `PakLocationItem`
|
|
621
|
+
```typescript
|
|
622
|
+
type PakLocationType = 'province' | 'division' | 'district' | 'tehsil' | 'area';
|
|
623
|
+
|
|
624
|
+
interface PakLocationItem {
|
|
625
|
+
id: string; // Canonical identifier (e.g. "lahore-gulberg-iii", "lahore", "punjab")
|
|
626
|
+
nameEn: string; // Standardized English name (e.g. "Gulberg III", "Lahore", "Punjab")
|
|
627
|
+
nameUr: string; // Native Urdu script (e.g. "گلبرگ ۳", "لاہور", "پنجاب")
|
|
628
|
+
type: PakLocationType; // Administrative level classification
|
|
629
|
+
parentId?: string; // Hierarchy linkage: area -> cityId -> provinceId
|
|
630
|
+
coordinates?: {
|
|
631
|
+
lat: number; // Latitude (WGS 84)
|
|
632
|
+
lng: number; // Longitude (WGS 84)
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
```
|
|
636
|
+
|
|
180
637
|
### `PakistanArea`
|
|
181
638
|
```typescript
|
|
182
639
|
interface PakistanArea {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cities.d.ts","sourceRoot":"","sources":["../../src/data/cities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,MAAM,EAAE,SAAS,YAAY,
|
|
1
|
+
{"version":3,"file":"cities.d.ts","sourceRoot":"","sources":["../../src/data/cities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,MAAM,EAAE,SAAS,YAAY,EA0xDzC,CAAC"}
|