Skip to content

Commit

Permalink
Merge branch 'feature/1060-draw-radius-circle-click' of https://githu…
Browse files Browse the repository at this point in the history
…b.com/hajkmap/Hajk into feature/1060-draw-radius-circle-click
  • Loading branch information
Tolfx committed Apr 27, 2022
2 parents 40f7d0b + b4a7b5b commit 76827ce
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion new-client/src/models/DrawModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1465,27 +1465,36 @@ class DrawModel {
}
};

// Enables possibility to draw a circle with fixed radius by 'single-click'
#enableCircleInteraction = () => {
this.#map.clickLock.add("coreDrawModel");
this.#circleInteractionActive = true;
this.#map.on("singleclick", this.#createRadiusOnClick);
};

// Disables possibility to draw a circle with fixed radius by 'single-click'
#disableCircleInteraction = () => {
this.#map.clickLock.delete("coreDrawModel");
this.#map.un("singleclick", this.#createRadiusOnClick);
this.#circleInteractionActive = false;
};

// Creates a Feature with a circle geometry with fixed radius
// (If the radius is bigger than 0).
#createRadiusOnClick = (e) => {
// If the radius is zero we don't want to add a circle...
if (this.#circleRadius === 0) {
return;
}
// Create the feature
const feature = new Feature({
geometry: new CircleGeometry(e.coordinate, this.#circleRadius),
});
feature.setStyle(this.#getFeatureStyle(feature));
// Add the feature to the draw-source
this.#drawSource.addFeature(feature);
// Make sure to trigger the draw-end event so that all props etc. are
// set on the feature.
this.#handleDrawEnd({ feature });
};

// Handles the "select"-event that fires from the event-listener added when adding
Expand Down

0 comments on commit 76827ce

Please sign in to comment.