forked from farmOS/farmOS-map
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Import formats. | ||
import GeoJSON from 'ol/format/GeoJSON'; | ||
import WKT from 'ol/format/WKT'; | ||
|
||
// Import the default projection configuration | ||
import projection from '../../projection'; | ||
|
||
// Read features from Well Known Text (WKT). | ||
function readFeaturesWKT(wkt) { | ||
const isMultipart = wkt.includes('MULTIPOINT') | ||
|| wkt.includes('MULTILINESTRING') | ||
|| wkt.includes('MULTIPOLYGON') | ||
|| wkt.includes('GEOMETRYCOLLECTION'); | ||
return isMultipart | ||
? new WKT({ splitCollection: true }).readFeatures(wkt, projection) | ||
: [new WKT().readFeature(wkt, projection)]; | ||
} | ||
|
||
// Read features from GeoJSON. | ||
function readFeaturesGeoJSON(geojson) { | ||
return (new GeoJSON()).readFeatures(geojson, projection); | ||
} | ||
|
||
// Read features from various formats. | ||
export default function readFeatures(type, input) { | ||
let features; | ||
if (type.toLowerCase() === 'geojson') { | ||
features = readFeaturesGeoJSON(input); | ||
} | ||
if (type.toLowerCase() === 'wkt') { | ||
features = readFeaturesWKT(input); | ||
} | ||
return features; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters