Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions packages/plugin-map/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ export to iterate over — the import *is* the registration.

```ts
import '@object-ui/plugin-map';
import type { ObjectMapSchema } from '@object-ui/types';

// Object-bound: the markers are the records the query returns.
const schema = {
const schema: ObjectMapSchema = {
type: 'object-map',
objectName: 'stores',
map: {
Expand All @@ -69,7 +70,9 @@ const schema = {
A literal record array instead of a query, with the same `map` block:

```ts
const schema = {
import type { ObjectMapSchema } from '@object-ui/types';

const schema: ObjectMapSchema = {
type: 'object-map',
staticData: [
{ id: 1, name: 'San Francisco HQ', lat: 37.7749, lng: -122.4194 },
Expand Down Expand Up @@ -130,17 +133,25 @@ and it does not cost the view its fit.

## Coordinate formats

`locationField` reads any of:
`locationField` names one record field, and the value in it is read at RUNTIME:
`extractCoordinates()` in `packages/plugin-map/src/ObjectMap.tsx` tests the value's
shape per record and takes the first of these three that answers. So this is a
reference read of what that parser accepts, not a value you author — which is why
it is a table rather than a snippet:

```ts
{ location: { lat: 37.7749, lng: -122.4194 } } // also latitude/longitude, lon
{ location: '37.7749,-122.4194' } // "lat,lng"
{ location: [37.7749, -122.4194] } // [lat, lng]
```
| Shape of `record[locationField]` | Example value | What the parser accepts |
| --- | --- | --- |
| Object | `{ lat: 37.7749, lng: -122.4194 }` | `lat` or `latitude` for the latitude; `lng`, `lon` or `longitude` for the longitude. Both must already be numbers — an object form is not string-parsed. |
| String | `'37.7749,-122.4194'` | `"lat,lng"`: split on the comma, each half trimmed and `parseFloat`-ed. |
| Array | `[37.7749, -122.4194]` | `[lat, lng]`, exactly two elements, each `parseFloat`-ed. |

The lat/lng PAIR (`latitudeField` + `longitudeField`) is tried first and is
stricter: both values must already be numbers, with no parsing step at all.

A record whose coordinates are missing, unparseable, or out of range (latitude
beyond ±90, longitude beyond ±180) is left off the map and counted in a notice
above it, rather than being silently dropped or rescued.
above it, rather than being silently dropped or rescued. The range test and the
notice live in that same file, alongside the parser.

## What this component does not read

Expand All @@ -159,7 +170,9 @@ host that registers types itself) and the `ObjectMapProps` type are the package'
exports:

```tsx
import { ObjectMap } from '@object-ui/plugin-map';
import { ObjectMap, type ObjectMapProps } from '@object-ui/plugin-map';

declare const dataSource: ObjectMapProps['dataSource'];

<ObjectMap
schema={{ type: 'object-map', objectName: 'stores', map: { latitudeField: 'lat', longitudeField: 'lng' } }}
Expand Down
2 changes: 0 additions & 2 deletions scripts/check-doc-snippet-types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,6 @@ const UNGATED_DOCS = {
'what is left is fragment shape, and no gate reads this page\'s import names.',
'packages/fields/README.md':
'2 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines; 1 unresolved-module diagnostic(s)',
'packages/plugin-map/README.md':
'1 parse diagnostic(s) — blocks fenced `ts` that are bare object literals or elided bodies; 1 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines; plus TS2322x1 — candidate real defects, un-triaged',
};

// ── Fence scanning ───────────────────────────────────────────────────────────
Expand Down
Loading