terra-draw
Advanced tools
Comparing version 0.0.1-alpha.31 to 0.0.1-alpha.32
@@ -5,2 +5,14 @@ # Changelog | ||
### [0.0.1-alpha.32](https://github.com/JamesLMilner/terra-draw/compare/v0.0.1-alpha.31...v0.0.1-alpha.32) (2023-06-04) | ||
### Features | ||
* add the addFeatures method to allow adding of external data ([b6e0043](https://github.com/JamesLMilner/terra-draw/commit/b6e004377f1baff78e01f9324413469677f2df5b)) | ||
### Chore | ||
* update docs ([36997cc](https://github.com/JamesLMilner/terra-draw/commit/36997cc7c7071af1af1a27ad457cab0361f3e5e9)) | ||
### [0.0.1-alpha.31](https://github.com/JamesLMilner/terra-draw/compare/v0.0.1-alpha.30...v0.0.1-alpha.31) (2023-05-22) | ||
@@ -7,0 +19,0 @@ |
@@ -32,2 +32,3 @@ import { BehaviorConfig, TerraDrawModeBehavior } from "./base.behavior"; | ||
register(config: TerraDrawModeRegisterConfig): void; | ||
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures; | ||
abstract start(): void; | ||
@@ -34,0 +35,0 @@ abstract stop(): void; |
@@ -47,3 +47,4 @@ import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColor } from "../../common"; | ||
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling; | ||
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures; | ||
} | ||
export {}; |
@@ -53,3 +53,4 @@ import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColor } from "../../common"; | ||
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling; | ||
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures; | ||
} | ||
export {}; |
@@ -56,3 +56,4 @@ import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColor } from "../../common"; | ||
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling; | ||
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures; | ||
} | ||
export {}; |
@@ -59,3 +59,4 @@ import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColor } from "../../common"; | ||
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling; | ||
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures; | ||
} | ||
export {}; |
@@ -37,3 +37,4 @@ import { TerraDrawMouseEvent, TerraDrawAdapterStyling, HexColor } from "../../common"; | ||
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling; | ||
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures; | ||
} | ||
export {}; |
@@ -62,3 +62,4 @@ import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColor } from "../../common"; | ||
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling; | ||
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures; | ||
} | ||
export {}; |
@@ -48,3 +48,4 @@ import { TerraDrawMouseEvent, TerraDrawAdapterStyling, TerraDrawKeyboardEvent, HexColor } from "../../common"; | ||
styleFeature(feature: GeoJSONStoreFeatures): TerraDrawAdapterStyling; | ||
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures; | ||
} | ||
export {}; |
import { TerraDrawAdapterStyling } from "../../common"; | ||
import { TerraDrawBaseDrawMode } from "../base.mode"; | ||
import { BehaviorConfig } from "../base.behavior"; | ||
import { GeoJSONStoreFeatures } from "../../terra-draw"; | ||
type RenderModeStylingExt<T extends TerraDrawAdapterStyling> = {}; | ||
@@ -35,3 +36,4 @@ type RenderModeStyling = RenderModeStylingExt<TerraDrawAdapterStyling>; | ||
styleFeature(): TerraDrawAdapterStyling; | ||
validateFeature(feature: unknown): feature is GeoJSONStoreFeatures; | ||
} | ||
export {}; |
@@ -14,5 +14,3 @@ import { Feature, Point, Polygon, LineString } from "geojson"; | ||
export type GeoJSONStoreConfig = { | ||
data?: GeoJSONStoreFeatures[]; | ||
tracked?: boolean; | ||
validateFeature?: (feature: unknown, tracked?: boolean) => void; | ||
}; | ||
@@ -28,3 +26,3 @@ export declare class GeoJSONStore { | ||
has(id: string): boolean; | ||
load(data: GeoJSONStoreFeatures[], featureValidation?: (feature: unknown, tracked?: boolean) => void): void; | ||
load(data: GeoJSONStoreFeatures[], featureValidation?: (feature: unknown, tracked?: boolean) => boolean): void; | ||
search(bbox: BBoxPolygon, filter?: (feature: GeoJSONStoreFeatures) => boolean): GeoJSONStoreFeatures[]; | ||
@@ -31,0 +29,0 @@ registerOnChange(onChange: StoreChangeHandler): void; |
@@ -43,3 +43,2 @@ import { TerraDrawGoogleMapsAdapter } from "./adapters/google-maps.adapter"; | ||
}; | ||
data?: GeoJSONStoreFeatures[]; | ||
}); | ||
@@ -106,2 +105,12 @@ private checkEnabled; | ||
/** | ||
* A method for adding features to the store. This method will validate the features. | ||
* Features must match one of the modes enabled in the instance. | ||
* @param mode | ||
* @param features | ||
* @returns | ||
* | ||
* @alpha | ||
*/ | ||
addFeatures(features: GeoJSONStoreFeatures[]): void; | ||
/** | ||
* A method starting Terra Draw. It put the instance into a started state, and | ||
@@ -108,0 +117,0 @@ * in registers the passed adapter giving it all the callbacks required to operate. |
@@ -201,2 +201,43 @@ # Getting Started | ||
## Common Patterns | ||
### Loading in External Data | ||
It is common pattern to want to load in data from an external source (GeoJSON file, API call, etc). This can be achieved with the `addFeatures` method on the Terra Draw instance. The method call works out which mode to add the feature based on looking at its `mode` property in the Features `properties` property. All modes have a method called `validateFeature` that ensures that a given feature is valid for the mode. For example if you wanted to add a series of points to the TerraDrawPointMode you could do this by ensuring that the points you feed in have the `mode` property set to `point`. | ||
```javascript | ||
points.forEach((point) => { | ||
point.properties.mode = "point"; | ||
}); | ||
draw.addFeatures(points); | ||
``` | ||
### Render Only Modes with TerraDrawRenderMode | ||
If you just want to render some data onto the map without it being editable, you can use `TerraDrawRenderMode` in combination with `addFeatures` like so: | ||
```javascript | ||
const draw = new TerraDraw({ | ||
adapter: new TerraDrawLeafletAdapter({ | ||
lib: L, | ||
map, | ||
coordinatePrecision: 9, | ||
}), | ||
modes: { | ||
arbitary: new TerraDrawRenderMode(), | ||
}, | ||
}); | ||
draw.start(); | ||
points.forEach((point) => { | ||
point.properties.mode = "arbitary"; | ||
}); | ||
draw.addFeatures(points); | ||
// This will add the points to hte TerraDrawRenderMode 'arbitary' rendering them to the screen | ||
``` | ||
## Other Examples | ||
@@ -203,0 +244,0 @@ |
{ | ||
"name": "terra-draw", | ||
"version": "0.0.1-alpha.31", | ||
"version": "0.0.1-alpha.32", | ||
"description": "Frictionless map drawing across mapping provider", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3593509
103
3771