diff --git a/contribs/gmf/src/datasource/ExternalDataSourcesManager.js b/contribs/gmf/src/datasource/ExternalDataSourcesManager.js index 7d6a01b3b14b..b7cd4cfaec91 100644 --- a/contribs/gmf/src/datasource/ExternalDataSourcesManager.js +++ b/contribs/gmf/src/datasource/ExternalDataSourcesManager.js @@ -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'; @@ -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) => {