Skip to content

Commit

Permalink
Clean GeometryFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
llienher committed Jul 23, 2019
1 parent 9d4d193 commit 8bbb7d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions contribs/gmf/src/editing/Snapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ exports.prototype.ensureSnapInteractionsOnTop = function() {

let item;
for (const uid in this.cache_) {
item = this.cache_[+uid];
item = this.cache_[uid];
if (item.active) {
googAsserts.assert(item.interaction);
map.removeInteraction(item.interaction);
Expand Down Expand Up @@ -298,11 +298,11 @@ exports.prototype.registerTreeCtrl_ = function(treeCtrl) {
*/
exports.prototype.unregisterAllTreeCtrl_ = function() {
for (const uid in this.cache_) {
const item = this.cache_[+uid];
const item = this.cache_[uid];
if (item) {
item.stateWatcherUnregister();
this.deactivateItem_(item);
delete this.cache_[+uid];
delete this.cache_[uid];
}
}
};
Expand Down Expand Up @@ -481,7 +481,7 @@ exports.prototype.loadAllItems_ = function() {
this.mapViewChangePromise_ = null;
let item;
for (const uid in this.cache_) {
item = this.cache_[+uid];
item = this.cache_[uid];
if (item.active) {
this.loadItemFeatures_(item);
}
Expand Down Expand Up @@ -582,7 +582,7 @@ exports.prototype.handleMapMoveEnd_ = function() {
exports.prototype.refreshSnappingSource_ = function() {
this.ngeoSnappingSource_.clear();
for (const uid in this.cache_) {
const item = this.cache_[+uid];
const item = this.cache_[uid];
if (item.active) {
this.ngeoSnappingSource_.addFeatures(item.features.getArray());
}
Expand Down
22 changes: 11 additions & 11 deletions src/interaction/MeasureLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const exports = function(format, gettextCatalog, options = /** @type {ngeox.inte

/**
* The snapping tolerance in pixels.
* @params {Number}
* @params {number}
*/
this.tolerance = options.tolerance;

Expand All @@ -73,13 +73,13 @@ olBase.inherits(exports, ngeoInteractionMeasure);
/**
* @inheritDoc
*/
exports.prototype.createDrawInteraction = function(style) {
exports.prototype.createDrawInteraction = function(style, source) {
return new olInteractionDraw({
type: /** @type {ol.geom.GeometryType} */ ('LineString'),
geometryFunction: (...args) =>
this.linestringGeometryFunction(...args),
geometryFunction: this.linestringGeometryFunction.bind(this),
condition: () => true,
style: style
style: style,
source: source,
});
};

Expand All @@ -93,7 +93,7 @@ exports.prototype.createDrawInteraction = function(style) {
* @return {LineString} Geometry.
*/
exports.prototype.linestringGeometryFunction = function(coordinates, opt_geometry) {
if (modifierPressed && this.tolerance !== undefined && this.source !== undefined) {
if (modifierPressed) {
const viewRotation = this.getMap().getView().getRotation();
const angle = Math.PI / 4;
const from = coordinates[coordinates.length - 2];
Expand All @@ -106,12 +106,12 @@ exports.prototype.linestringGeometryFunction = function(coordinates, opt_geometr
to[0] = from[0] - (length * Math.cos(rotation));
to[1] = from[1] - (length * Math.sin(rotation));

const delta = this.getMap().getView().getResolution() * this.tolerance;
const bbox = [to[0] - delta, to[1] - delta, to[0] + delta, to[1] + delta];
if (this.tolerance !== undefined && this.source !== undefined) {
const delta = this.getMap().getView().getResolution() * this.tolerance;
const bbox = [to[0] - delta, to[1] - delta, to[0] + delta, to[1] + delta];

const layerSource = this.source;
const featuresInExtent = layerSource.getFeaturesInExtent(bbox);
if (featuresInExtent.length > 0) {
const layerSource = this.source;
const featuresInExtent = layerSource.getFeaturesInExtent(bbox);
featuresInExtent.forEach((feature) => {
feature.getGeometry().forEachSegment((point1, point2) => {
// Line points are: from A to M (to B that we need to find)
Expand Down

0 comments on commit 8bbb7d3

Please sign in to comment.