Skip to content

Commit

Permalink
Import KML: Manage Empty geometry import error
Browse files Browse the repository at this point in the history
  • Loading branch information
ger-benjamin committed Jul 31, 2018
1 parent 6fc4ad1 commit 06a461e
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions contribs/gmf/src/datasource/ExternalDataSourcesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ngeoDatasourceOGC from 'ngeo/datasource/OGC.js';
import ngeoDatasourceOGCGroup from 'ngeo/datasource/OGCGroup.js';
import ngeoDatasourceWMSGroup from 'ngeo/datasource/WMSGroup.js';
import * as olBase from 'ol/index.js';
import {isEmpty} from 'ol/extent.js';
import * as olEvents from 'ol/events.js';
import olCollection from 'ol/Collection.js';
import olFormatGPX from 'ol/format/GPX.js';
Expand Down Expand Up @@ -471,29 +472,34 @@ const exports = class {
createAndAddDataSourceFromFile(file, opt_callback) {
this.getFileDataSource_(file).then(
(dataSource) => {
let success = true;
const fileGroup = this.fileGroup_;

// (1) No need to do anything if the file has already been added...
if (fileGroup.dataSources.includes(dataSource)) {
return;
}
// Look if the extent is valid (and so at least one geometry)
if (isEmpty(dataSource.extent)) {
success = false;

// (2) Okay, we need to add this data source. First, add its layer
// to the map.
this.addLayer_(dataSource.layer);
} else {
// (1) No need to do anything if the file has already been added...
if (fileGroup.dataSources.includes(dataSource)) {
return;
}

// (3) Add it to the file group
fileGroup.addDataSource(dataSource);
// (2) Okay, we need to add this data source. First, add its layer to the map.
this.addLayer_(dataSource.layer);

// (4) Recenter the map view onto its extent
this.map_.getView().fit(dataSource.extent);
// (3) Add it to the file group
fileGroup.addDataSource(dataSource);

// (5) Finally, add it to the ngeo collection
this.dataSources_.push(dataSource);
// (4) Recenter the map view onto its extent if there is at least one geometry (and so a valid extent)
this.map_.getView().fit(dataSource.extent);

// call the callback.
// (5) Finally, add it to the ngeo collection
this.dataSources_.push(dataSource);
}
// Call the callback.
if (opt_callback) {
opt_callback(true);
opt_callback(success);
}
},
(rejections) => {
Expand Down

0 comments on commit 06a461e

Please sign in to comment.