Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release_3_7] Fix import data to draw tool #4082

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions assets/src/modules/Digitizing.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Vector as VectorSource } from 'ol/source.js';
import { Vector as VectorLayer } from 'ol/layer.js';
import { Feature } from 'ol';

import { Point, LineString, Polygon, Circle as CircleGeom, MultiPoint } from 'ol/geom.js';
import { Point, LineString, Polygon, Circle as CircleGeom, MultiPoint, GeometryCollection } from 'ol/geom.js';
import { circular } from 'ol/geom/Polygon.js';

import { getArea, getLength } from 'ol/sphere.js';
Expand Down Expand Up @@ -1051,22 +1051,30 @@ export default class Digitizing {

// Handle GeoJSON, GPX or KML strings
try {
const options = {
featureProjection: mainLizmap.projection
};
// Check extension for format type
if (['json', 'geojson'].includes(fileExtension)) {
OL6features = (new GeoJSON()).readFeatures(fileContent);
OL6features = (new GeoJSON()).readFeatures(fileContent, options);
} else if (fileExtension === 'gpx') {
OL6features = (new GPX()).readFeatures(fileContent);
OL6features = (new GPX()).readFeatures(fileContent, options);
} else if (fileExtension === 'kml') {
OL6features = (new KML()).readFeatures(fileContent);
OL6features = (new KML()).readFeatures(fileContent, options);
}
} catch (error) {
lizMap.addMessage(error, 'error', true)
}

if (OL6features) {
// Add imported features to map and zoom to their extent
// Add imported features to map
this._drawSource.addFeatures(OL6features);
mainLizmap.extent = this._drawSource.getExtent();
// And zoom to their bounding extent
const featuresGeometry = OL6features.map(feature => feature.getGeometry());
const featuresGeometryCollection = new GeometryCollection(featuresGeometry);
const extent = featuresGeometryCollection.getExtent();

mainLizmap.map.getView().fit(extent);
}
};
})(this);
Expand Down
Loading
Loading