Skip to content

Commit

Permalink
Update polygon on draw rather than add new one
Browse files Browse the repository at this point in the history
Add an ID to the polygon created when drawing on map so that it is updated when new points are added rather than creating a new one

Issue #2180
  • Loading branch information
robyngit committed Oct 16, 2023
1 parent 516cd60 commit 7f4103b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/js/models/connectors/GeoPoints-Cesium.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ define([
*/
connect: function () {
try {
this.disconnect();

// Listen for changes to the points collection and update the layer
let geoPoints = this.get("geoPoints");
const geoPoints = this.get("geoPoints");
const events = ["update", "reset"];

events.forEach((eventName) => {
this.listenTo(geoPoints, eventName, function (...args) {
this.handleCollectionChange(eventName, ...args);
Expand Down Expand Up @@ -141,7 +144,8 @@ define([
* Stop listening for changes to the Points collection.
*/
disconnect: function () {
this.stopListening(this.get("geoPoints"));
const geoPoints = this.get("geoPoints");
if (geoPoints) this.stopListening(geoPoints);
this.set("isConnected", false);
},

Expand Down
2 changes: 2 additions & 0 deletions src/js/models/connectors/GeoPoints-CesiumPolygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ define(["cesium", "models/connectors/GeoPoints-Cesium"], function (
* the CesiumVectorData model.
*/
addPolygon: function () {
const id = this.cid;
const layer = this.get("layer") || this.setVectorLayer();
const geoPoints = this.get("geoPoints") || this.setPoints();
return layer.addEntity({
id: id, // If entity with this ID already exists, it will be updated
polygon: {
height: null, // <- clamp to ground
hierarchy: new Cesium.CallbackProperty(() => {
Expand Down

0 comments on commit 7f4103b

Please sign in to comment.