Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function transformJSTSGeometry(jstsGeometry, fromSrs, toSrs) {
// This all seems excessive, however jsts ol3Parser wasn't working with versions
// "jsts": "~1.4.0" and "openlayers": "~3.19.1", worth revisting in the future.
const writer = new GeoJSONWriter();
const geojsonReader = new Reader();
const ol3GeoJSON = new GeoJSON();
const geom = (new GeoJSON())
.readGeometry(writer.write(jstsGeometry)).transform(fromSrs, toSrs);
return geojsonReader.read(ol3GeoJSON.writeGeometry(geom));
}
this._replacePolyline = options.replacePolylines;
this._separateBuffer = options.separateBuffer;
this._bufferStyle = options.bufferStyle;
if (!(this._featureGroup instanceof L.FeatureGroup)) {
throw new Error('options.featureGroup must be a L.FeatureGroup');
}
this._unbufferedLayerProps = {};
// Save the type so super can fire,
// need to do this as cannot do this.TYPE :(
this.type = L.EditToolbar.Buffer.TYPE;
this.geoReader = new GeoJSONReader();
this.geoWriter = new GeoJSONWriter();
},
export function jstsGeomToOlGeom(jstsGeom) {
const writer = new GeoJSONWriter();
const olReader = new GeoJSON();
const olGeom = olReader.readGeometry(writer.write(jstsGeom)).transform('EPSG:4326', 'EPSG:3857');
return olGeom;
}
export function jstsToFeatureCollection(jsts) {
const writer = new GeoJSONWriter();
const geom = writer.write((jsts));
if (geom.coordinates) {
return {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {},
geometry: geom,
},
],
};
}
return null;
}
export function bufferGeojson(featureCollection, bufferSize, bufferPolys) {
const geojsonReader = new Reader();
const jstsGeoJSON = geojsonReader.read(featureCollection);
const { features } = jstsGeoJSON;
const writer = new GeoJSONWriter();
const bufferedFeatures = [];
features.forEach((feat) => {
const size = bufferSize || 1;
const geom = bufferGeometry(feat.geometry, size, bufferPolys);
let geojsonGeom;
if (geom.getArea() !== 0) {
geojsonGeom = writer.write(geom);
bufferedFeatures.push({
type: 'Feature',
properties: feat.properties || {},
geometry: { ...geojsonGeom },
});
}
});
const bufferedFeatureCollection = {
type: 'FeatureCollection',
function makeFeatureCollectionFromArray(wkts: string[], properties?: any) {
const reader: any = new WKTReader()
const writer: any = new GeoJSONWriter()
const geometries = wkts.map(wkt => writer.write(reader.read(wkt)))
const features = geometries.map(geometry => ({ type: 'Feature', geometry } as IGeoJsonFeature))
if (properties)
features.forEach(f => f.properties = properties)
return {
type: 'FeatureCollection',
features,
}
}