@richpods/tiny-geojson-tool 0.1.1 → 0.3.0

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 CHANGED
@@ -56,6 +56,7 @@ Both components accept:
56
56
  | `pmtilesUrl` | `string` | **(required)** | URL to a PMTiles archive for the base map |
57
57
  | `center` | `[lng, lat]` | `[0, 20]` | Initial map center |
58
58
  | `zoom` | `number` | `2` | Initial zoom level |
59
+ | `bboxPadding` | `[top, right, bottom, left]` | `[0, 0, 0, 0]` | Extra padding used when fitting to GeoJSON bounds |
59
60
 
60
61
  `GeoJsonEditor` additionally accepts:
61
62
 
@@ -65,6 +66,58 @@ Both components accept:
65
66
  | `pointRadius` | `number` | `10` | Radius of point features in pixels |
66
67
  | `l10n` | `Partial<EditorLocale>` | English | Override UI strings for localization |
67
68
 
69
+ Initial map view priority on load:
70
+
71
+ 1. If `modelValue.bbox` is present, it is used directly.
72
+ 2. Otherwise, bounds are calculated from `modelValue.features`.
73
+ 3. If no bounds can be determined (empty map), `center` and `zoom` are used.
74
+
75
+ ## Accessing the MapLibre Instance
76
+
77
+ Both components expose a `getMap()` method via template ref that returns the underlying MapLibre GL JS `Map` instance (or `null` before the map is initialized). This lets you call MapLibre methods directly — add controls, fly to coordinates, query features, etc.
78
+
79
+ ```vue
80
+ <script setup lang="ts">
81
+ import { ref } from "vue";
82
+ import { GeoJsonEditor } from "@richpods/tiny-geojson-tool";
83
+ import "@richpods/tiny-geojson-tool/styles";
84
+ import type { EditorFeatureCollection } from "@richpods/tiny-geojson-tool";
85
+
86
+ const editorRef = ref<InstanceType<typeof GeoJsonEditor> | null>(null);
87
+ const geojson = ref<EditorFeatureCollection>({
88
+ type: "FeatureCollection",
89
+ features: [],
90
+ });
91
+
92
+ function flyToVienna() {
93
+ editorRef.value?.getMap()?.flyTo({ center: [16.37, 48.21], zoom: 12 });
94
+ }
95
+ </script>
96
+
97
+ <template>
98
+ <button @click="flyToVienna">Fly to Vienna</button>
99
+ <GeoJsonEditor
100
+ ref="editorRef"
101
+ v-model="geojson"
102
+ pmtilesUrl="https://example.com/tiles.pmtiles" />
103
+ </template>
104
+ ```
105
+
106
+ The same works for `GeoJsonViewer`:
107
+
108
+ ```vue
109
+ <script setup lang="ts">
110
+ import { ref } from "vue";
111
+ import { GeoJsonViewer } from "@richpods/tiny-geojson-tool";
112
+
113
+ const viewerRef = ref<InstanceType<typeof GeoJsonViewer> | null>(null);
114
+ </script>
115
+
116
+ <template>
117
+ <GeoJsonViewer ref="viewerRef" :modelValue="geojson" pmtilesUrl="https://example.com/tiles.pmtiles" />
118
+ </template>
119
+ ```
120
+
68
121
  ## Drawing Tools
69
122
 
70
123
  The editor toolbar provides six modes:
@@ -78,20 +131,6 @@ The editor toolbar provides six modes:
78
131
 
79
132
  Right-click or press Escape to cancel drawing.
80
133
 
81
- ## Bounding Box
82
-
83
- The GeoJSON `bbox` member ([RFC 7946 §5](https://datatracker.ietf.org/doc/html/rfc7946#section-5)) can be used to store and restore a map view. `GeoJsonEditor` exposes a `saveBbox` method via template ref, and both components respect an existing `bbox` on load.
84
-
85
- ```javascript
86
- // Save the current map view as bbox
87
- editorRef.value.saveBbox();
88
-
89
- // Or provide a custom bbox [west, south, east, north]
90
- editorRef.value.saveBbox([-74.1, 40.6, -73.8, 40.9]);
91
- ```
92
-
93
- When a `bbox` is present on the feature collection, both `GeoJsonEditor` and `GeoJsonViewer` will fit the map to that bounding box on load (instead of auto-fitting to features). Explicit `center`/`zoom` props still take priority over `bbox`.
94
-
95
134
  ## Style Properties
96
135
 
97
136
  Features support [simplestyle-spec 1.1.0](https://github.com/mapbox/simplestyle-spec) properties:
@@ -143,20 +182,6 @@ See `EditorLocale` for the full list of keys and `DEFAULT_LOCALE` for the Englis
143
182
 
144
183
  All styles use CSS custom properties prefixed with `--tge-`. Override them to customize the look.
145
184
 
146
- ## Utilities
147
-
148
- The library exports helper functions for working with GeoJSON data outside of the components.
149
-
150
- | Function | Description |
151
- |----------|-------------|
152
- | `computeBbox(fc)` | Compute a `BBox` (`[west, south, east, north]`) from a feature collection. Returns `undefined` if there are no features. |
153
-
154
- ```ts
155
- import { computeBbox } from "@richpods/tiny-geojson-tool";
156
-
157
- const bbox = computeBbox(geojson.value);
158
- ```
159
-
160
185
  ## Base Map
161
186
 
162
187
  The base map expects vector tiles served from a PMTiles archive. We recommend the [Shortbread](https://shortbread-tiles.org/) schema for your tiles. You must provide the `pmtilesUrl` prop pointing to your own tile source.
@@ -1,4 +1,5 @@
1
- import type { BBox, EditorFeatureCollection, EditorFeature, Position, ToolMode } from "../types";
1
+ import { type Map as MaplibreMap } from "maplibre-gl";
2
+ import type { EditorFeatureCollection, EditorFeature, Position, ToolMode, BboxPadding } from "../types";
2
3
  type __VLS_Props = {
3
4
  modelValue: EditorFeatureCollection;
4
5
  activeTool: ToolMode;
@@ -6,22 +7,21 @@ type __VLS_Props = {
6
7
  pointRadius?: number;
7
8
  center?: Position;
8
9
  zoom?: number;
10
+ bboxPadding?: BboxPadding;
9
11
  };
10
- declare function saveBbox(bbox?: BBox): void;
12
+ declare function getMap(): MaplibreMap | null;
11
13
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
12
- saveBbox: typeof saveBbox;
14
+ getMap: typeof getMap;
13
15
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
14
16
  "update:modelValue": (value: EditorFeatureCollection) => any;
15
17
  featureClick: (feature: EditorFeature | null) => any;
16
18
  featureDelete: (id: string) => any;
17
19
  toolDone: (featureId: string) => any;
18
- moveend: () => any;
19
20
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
20
21
  "onUpdate:modelValue"?: ((value: EditorFeatureCollection) => any) | undefined;
21
22
  onFeatureClick?: ((feature: EditorFeature | null) => any) | undefined;
22
23
  onFeatureDelete?: ((id: string) => any) | undefined;
23
24
  onToolDone?: ((featureId: string) => any) | undefined;
24
- onMoveend?: (() => any) | undefined;
25
25
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
26
26
  declare const _default: typeof __VLS_export;
27
27
  export default _default;
@@ -1,28 +1,28 @@
1
- import type { BBox, EditorFeatureCollection, Position } from "../types";
1
+ import type { Map as MaplibreMap } from "maplibre-gl";
2
+ import type { EditorFeatureCollection, Position, BboxPadding } from "../types";
2
3
  import type { EditorLocale } from "../l10n";
3
4
  type __VLS_Props = {
4
5
  pmtilesUrl: string;
5
6
  pointRadius?: number;
6
7
  center?: Position;
7
8
  zoom?: number;
9
+ bboxPadding?: BboxPadding;
8
10
  l10n?: Partial<EditorLocale>;
9
11
  };
10
- declare function saveBbox(bbox?: BBox): void;
12
+ declare function getMap(): MaplibreMap | null;
11
13
  type __VLS_ModelProps = {
12
14
  modelValue?: EditorFeatureCollection;
13
15
  };
14
16
  type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
15
17
  declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {
16
- saveBbox: typeof saveBbox;
18
+ getMap: typeof getMap;
17
19
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
18
20
  "update:modelValue": (value: EditorFeatureCollection) => any;
19
- } & {
20
- moveend: () => any;
21
21
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
22
22
  "onUpdate:modelValue"?: ((value: EditorFeatureCollection) => any) | undefined;
23
- onMoveend?: (() => any) | undefined;
24
23
  }>, {
25
24
  pointRadius: number;
25
+ bboxPadding: BboxPadding;
26
26
  l10n: Partial<EditorLocale>;
27
27
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
28
28
  declare const _default: typeof __VLS_export;
@@ -1,12 +1,18 @@
1
- import type { EditorFeatureCollection, Position } from "../types";
1
+ import { type Map as MaplibreMap } from "maplibre-gl";
2
+ import type { EditorFeatureCollection, Position, BboxPadding } from "../types";
2
3
  type __VLS_Props = {
3
4
  modelValue?: EditorFeatureCollection;
4
5
  pmtilesUrl: string;
5
6
  center?: Position;
6
7
  zoom?: number;
8
+ bboxPadding?: BboxPadding;
7
9
  };
8
- declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
10
+ declare function getMap(): MaplibreMap | null;
11
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
12
+ getMap: typeof getMap;
13
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
9
14
  modelValue: EditorFeatureCollection;
15
+ bboxPadding: BboxPadding;
10
16
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
17
  declare const _default: typeof __VLS_export;
12
18
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import type { ToolMode, Position } from "../types";
2
2
  export declare function useDrawing(): {
3
3
  activeTool: import("vue").Ref<ToolMode, ToolMode>;
4
- drawingCoords: import("vue").Ref<[number, number][], [number, number][] | Position[]>;
4
+ drawingCoords: import("vue").Ref<[number, number][], Position[] | [number, number][]>;
5
5
  selectedFeatureId: import("vue").Ref<string | null, string | null>;
6
6
  isDrawing: import("vue").ComputedRef<boolean>;
7
7
  setTool: (tool: ToolMode) => void;
package/dist/index.d.ts CHANGED
@@ -9,8 +9,7 @@ export { useMapStyle } from "./composables/useMapStyle";
9
9
  export { getFeatureLayers, getFeatureLayerIds, getQueryableLayerIds, getVerticesLayer, reconcileFeatureLayers, getDrawingLayers, } from "./utils/layers";
10
10
  export type { GeomType, FeatureSummary } from "./utils/layers";
11
11
  export { loadIcon, loadIconsForFeatures, getIconUrl, COMMON_ICONS } from "./utils/icons";
12
- export { computeBbox } from "./utils/mapView";
13
12
  export { DEFAULT_LOCALE } from "./l10n";
14
13
  export type { EditorLocale } from "./l10n";
15
14
  export { SOURCE_ID, LAYER_IDS, DEFAULTS, MARKER_SIZE_SCALE } from "./constants";
16
- export type { EditorFeatureCollection, EditorFeature, EditorPolygonFeature, EditorLineStringFeature, EditorPointFeature, EditorMarkerFeature, EditorProperties, BaseProperties, FillStyleProperties, StrokeStyleProperties, MarkerStyleProperties, PointStyleProperties, LabelProperties, BBox, Position, ToolMode, EditorProps, ViewerProps, } from "./types";
15
+ export type { EditorFeatureCollection, EditorFeature, EditorPolygonFeature, EditorLineStringFeature, EditorPointFeature, EditorMarkerFeature, EditorProperties, BaseProperties, FillStyleProperties, StrokeStyleProperties, MarkerStyleProperties, PointStyleProperties, LabelProperties, Position, GeoJsonBbox, BboxPadding, ToolMode, EditorProps, ViewerProps, } from "./types";