Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
feat: support multi feature for geojson (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 committed Dec 19, 2022
1 parent 67bc52a commit d1ee59b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/core/mantle/data/geojson.ts
Expand Up @@ -16,6 +16,40 @@ export function processGeoJSON(geojson: GeoJSON, range?: DataRange): Feature[] {

if (geojson.type === "Feature") {
const geo = geojson.geometry;
if (geo.type === "MultiPoint") {
return geo.coordinates.flatMap(coord => {
return processGeoJSON({
...geojson,
geometry: {
type: "Point",
coordinates: coord,
},
});
});
}
if (geo.type === "MultiLineString") {
return geo.coordinates.flatMap(coord => {
return processGeoJSON({
...geojson,
geometry: {
type: "LineString",
coordinates: coord,
},
});
});
}
if (geo.type === "MultiPolygon") {
return geo.coordinates.flatMap(coord => {
return processGeoJSON({
...geojson,
geometry: {
type: "Polygon",
coordinates: coord,
},
});
});
}

return [
{
id: (geojson.id && String(geojson.id)) || generateRandomString(12),
Expand Down
11 changes: 9 additions & 2 deletions src/core/mantle/types/index.ts
@@ -1,4 +1,11 @@
import type { LineString, Point, Polygon } from "geojson";
import type {
LineString,
Point,
Polygon,
MultiPoint,
MultiLineString,
MultiPolygon,
} from "geojson";

import type { Infobox, Block, Tag } from "../compat/types";

Expand Down Expand Up @@ -71,7 +78,7 @@ export type Feature = {
range?: DataRange;
};

export type Geometry = Point | LineString | Polygon;
export type Geometry = Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon;

export type ComputedLayerStatus = "fetching" | "ready";

Expand Down

0 comments on commit d1ee59b

Please sign in to comment.