Skip to content

Commit

Permalink
added function for expanding collections
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterprovoost committed Nov 5, 2023
1 parent f112722 commit b3b9e81
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# wktmap

Code for <https://wktmap.com>.

This page parses and visualizes [WKT](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) (ISO 13249) as well as [geo:wktLiteral](https://opengeospatial.github.io/ogc-geosparql/geosparql11/spec.html#_rdfs_datatype_geowktliteral) strings in a variety of coordinate reference systems. Built with [OpenLayers](https://openlayers.org/), [Leaflet](https://leafletjs.com/), [Proj4js](https://trac.osgeo.org/proj4js), and [epsg.io](https://epsg.io/).
6 changes: 3 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import CRC32 from "crc-32";
import { EditControl } from "react-leaflet-draw";
import { geojsonToWKT } from "@terraformer/wkt";
import ReactGA from "react-ga4";
import { transformInput, ValueError } from "./wkt";
import { transformInput, ValueError, expandCollections } from "./wkt";

const DEFAULT_EPSG = "4326";

Expand Down Expand Up @@ -141,7 +141,7 @@ function App() {
}, [map]); // eslint-disable-line react-hooks/exhaustive-deps

function handleDrawStop() {
const geometries = [];
let geometries = [];
groupRef.current.eachLayer(function(layer) {
const geo = layer.toGeoJSON();
if (geo.type === "Feature") {
Expand All @@ -153,10 +153,10 @@ function App() {
}
});
let wkt;
geometries = expandCollections(geometries);
if (geometries.length === 1) {
wkt = geometries[0];
} else if (geometries.length > 1) {
// TODO: fix for existing GEOMETRYCOLLECTION (should not be nested)
wkt = "GEOMETRYCOLLECTION(" + geometries.join(", ") + ")";
}
setEpsg(4326);
Expand Down
11 changes: 10 additions & 1 deletion src/wkt.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,13 @@ async function transformInput(input) {

}

export { parseWkt, transformInput, ValueError, fetchProj, extractAndParseCrs };
function expandCollections(geometries) {
// TODO: fix for existing GEOMETRYCOLLECTION (should not be nested)
geometries.reduce(function(acc, current) {
acc.push(current);
return acc;
}, []);
return geometries;
}

export { parseWkt, transformInput, ValueError, fetchProj, extractAndParseCrs, expandCollections };

0 comments on commit b3b9e81

Please sign in to comment.