Skip to content

Commit

Permalink
feat: format handler for multiple geometry types and formats (#1276)
Browse files Browse the repository at this point in the history
* feat: added initial bounding box format handler for jsonform

* feat: add polygons and editors

* chore: cleanup

* feat: selection input + adjusted returned values accordingly

* fix: feature selection story & renamed drawtool to bbox

* chore: format

* fix: lint & tests

* fix: spread features

* feat: type spatial custom validator

* chore: update collection schema

* test: render drawtools on type spatial

* feat: add projection option

* test: projection

* fix: auto start drawing

* fix: remove `*-editor` formats

* fix: update editors types & adapt the validator and stories

* feat: support format point/points

* feat: support wkt and geojson types and handle their validations

* chore: update stories and clean up

* test: adjust tests

* fix: return a feature for single formats and feature collection for plural

* feat: support line/lines format

* fix: discard drawing on destroy

* fix: adjust collection schema and format

---------

Co-authored-by: A-Behairi <[email protected]>
  • Loading branch information
santilland and A-Behairi authored Dec 12, 2024
1 parent 7242b4c commit 0285b72
Show file tree
Hide file tree
Showing 30 changed files with 1,376 additions and 5 deletions.
147 changes: 147 additions & 0 deletions elements/jsonform/src/custom-inputs/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { JSONEditor } from "@json-editor/json-editor/src/core.js";
import { MinMaxEditor } from "./minmax";
import { SpatialEditor, spatialValidatorCreator } from "./spatial";

// Define custom input types
const inputs = [
Expand All @@ -8,6 +9,145 @@ const inputs = [
format: "minmax",
func: MinMaxEditor,
},
{
type: "array",
format: "bounding-boxes",
func: SpatialEditor,
},
{
type: "wkt",
format: "bounding-boxes",
func: SpatialEditor,
},
{
type: "geojson",
format: "bounding-boxes",
func: SpatialEditor,
},
{
type: "array",
format: "bounding-box",
func: SpatialEditor,
},
{
type: "wkt",
format: "bounding-box",
func: SpatialEditor,
},
{
type: "geojson",
format: "bounding-box",
func: SpatialEditor,
},
{
type: "array",
format: "polygons",
func: SpatialEditor,
},
{
type: "wkt",
format: "polygons",
func: SpatialEditor,
},
{
type: "geojson",
format: "polygons",
func: SpatialEditor,
},
{
type: "object",
format: "polygon",
func: SpatialEditor,
},
{
type: "wkt",
format: "polygon",
func: SpatialEditor,
},
{
type: "geojson",
format: "polygon",
func: SpatialEditor,
},
{
type: "array",
format: "points",
func: SpatialEditor,
},
{
type: "wkt",
format: "points",
func: SpatialEditor,
},
{
type: "geojson",
format: "points",
func: SpatialEditor,
},
{
type: "array",
format: "point",
func: SpatialEditor,
},
{
type: "wkt",
format: "point",
func: SpatialEditor,
},
{
type: "geojson",
format: "point",
func: SpatialEditor,
},
{
format: "feature",
func: SpatialEditor,
},
{
type: "array",
format: "features",
func: SpatialEditor,
},
{
type: "wkt",
format: "features",
func: SpatialEditor,
},
{
type: "geojson",
format: "features",
func: SpatialEditor,
},
{
type: "array",
format: "line",
func: SpatialEditor,
},
{
type: "wkt",
format: "line",
func: SpatialEditor,
},
{
type: "geojson",
format: "line",
func: SpatialEditor,
},
{
type: "array",
format: "lines",
func: SpatialEditor,
},
{
type: "wkt",
format: "lines",
func: SpatialEditor,
},
{
type: "geojson",
format: "lines",
func: SpatialEditor,
},
];

/**
Expand All @@ -16,6 +156,11 @@ const inputs = [
* @param {{[key: string]: any}} startVals - Initial values for the custom inputs
*/
export const addCustomInputs = (startVals) => {
// Add custom validators for spatial inputs
JSONEditor.defaults["custom_validators"].push(
spatialValidatorCreator(inputs),
);

// Iterate over each custom input definition
inputs.map(({ type, format, func }) => {
JSONEditor.defaults["startVals"] = startVals;
Expand All @@ -24,6 +169,8 @@ export const addCustomInputs = (startVals) => {
// Add a resolver to determine which format to use based on the schema
JSONEditor.defaults.resolvers.unshift((schema) => {
if (schema.type === type && schema.format === format) return format;
// If the schema format is "feature" use the SpatialEditor for all types
if (schema.format === "feature") return format;
});
});
};
Expand Down
Loading

0 comments on commit 0285b72

Please sign in to comment.