From 2c3c5a6e96acc5d54f280be8d43da166e65ab54a Mon Sep 17 00:00:00 2001 From: Laurent Lienher Date: Mon, 22 Jul 2019 13:48:00 +0200 Subject: [PATCH] Fix value update --- contribs/gmf/src/editing/Snapping.js | 10 ++++++++-- src/interaction/MeasureLength.js | 10 ++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/contribs/gmf/src/editing/Snapping.js b/contribs/gmf/src/editing/Snapping.js index 1907f8d5f84f..09f8824326cd 100644 --- a/contribs/gmf/src/editing/Snapping.js +++ b/contribs/gmf/src/editing/Snapping.js @@ -120,6 +120,12 @@ const exports = function($http, $q, $rootScope, $injector, $timeout, gmfThemes, */ this.ogcServers_ = null; + /** + * @type {ol.source.Vector | undefined} + * @private + */ + this.ngeoSnappingSource_ = this.injector_.get('ngeoSnappingSource') || undefined; + }; @@ -574,11 +580,11 @@ exports.prototype.handleMapMoveEnd_ = function() { * @private */ exports.prototype.refreshSnappingSource_ = function() { - this.injector_.get('ngeoSnappingSource').clear(); + this.ngeoSnappingSource_.clear(); for (const uid in this.cache_) { const item = this.cache_[+uid]; if (item.active) { - this.injector_.get('ngeoSnappingSource').addFeatures(item.features); + this.ngeoSnappingSource_.addFeatures(item.features.getArray()); } } }; diff --git a/src/interaction/MeasureLength.js b/src/interaction/MeasureLength.js index 54702aa48aa1..aebbc21d4d41 100644 --- a/src/interaction/MeasureLength.js +++ b/src/interaction/MeasureLength.js @@ -89,7 +89,7 @@ exports.prototype.createDrawInteraction = function(style) { * @return {LineString} Geometry. */ exports.prototype.linestringGeometryFunction = function(coordinates, opt_geometry) { - if (modifierPressed && this.tolerance !== undefined) { + if (modifierPressed && this.tolerance !== undefined && this.source !== undefined) { const viewRotation = this.getMap().getView().getRotation(); const angle = Math.PI / 4; const from = coordinates[coordinates.length - 2]; @@ -105,11 +105,9 @@ exports.prototype.linestringGeometryFunction = function(coordinates, opt_geometr const delta = this.getMap().getView().getResolution() * this.tolerance; const bbox = [to[0] - delta, to[1] - delta, to[0] + delta, to[1] + delta]; - const layers = this.getMap().getLayers().getArray(); - const vectorLayer = layers.find(layer => layer.type === 'VECTOR'); - if (vectorLayer !== undefined) { - const layerSource = vectorLayer.getSource(); - const featuresInExtent = layerSource.getFeaturesInExtent(bbox); + const layerSource = this.source; + const featuresInExtent = layerSource.getFeaturesInExtent(bbox); + if (featuresInExtent.length > 0) { featuresInExtent.forEach((feature) => { feature.getGeometry().forEachSegment((point1, point2) => { // Line points are: from A to M (to B that we need to find)