Skip to content

Commit

Permalink
fix: do not fail when trying to edit a circlemarker
Browse files Browse the repository at this point in the history
And for now open the properties panel (geometry/position may be
edited later, when Leaflet.Editable knows about CircleMarker)
  • Loading branch information
yohanboniface committed Sep 4, 2024
1 parent 185cc65 commit 5409537
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
12 changes: 1 addition & 11 deletions umap/static/umap/js/modules/data/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class Feature {
builder.helpers['properties.name'].input.focus()
})
this.map.editedFeature = this
if (!this.isOnScreen()) this.zoomTo(event)
if (!this.ui.isOnScreen()) this.zoomTo(event)
}

getAdvancedEditActions(container) {
Expand Down Expand Up @@ -661,11 +661,6 @@ export class Point extends Feature {
super.zoomTo(event)
}
}

isOnScreen(bounds) {
bounds = bounds || this.map.getBounds()
return bounds.contains(this.toLatLngs())
}
}

class Path extends Feature {
Expand Down Expand Up @@ -753,11 +748,6 @@ class Path extends Feature {
return items
}

isOnScreen(bounds) {
bounds = bounds || this.map.getBounds()
return bounds.overlaps(this.bounds)
}

zoomTo({ easing, callback }) {
// Use bounds instead of centroid for paths.
easing = easing || this.map.getOption('easing')
Expand Down
20 changes: 18 additions & 2 deletions umap/static/umap/js/modules/rendering/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,16 @@ const FeatureMixin = {
getPopupToolbarAnchor: () => [0, 0],
}

const PointMixin = {
isOnScreen: function (bounds) {
bounds = bounds || this._map.getBounds()
return bounds.contains(this.getCenter())
},
}

export const LeafletMarker = Marker.extend({
parentClass: Marker,
includes: [FeatureMixin],
includes: [FeatureMixin, PointMixin],

initialize: function (feature, latlng) {
FeatureMixin.initialize.call(this, feature, latlng)
Expand Down Expand Up @@ -411,6 +418,11 @@ const PathMixin = {
'dashArray',
'interactive',
],

isOnScreen: function (bounds) {
bounds = bounds || this._map.getBounds()
return bounds.overlaps(this.getBounds())
},
}

export const LeafletPolyline = Polyline.extend({
Expand Down Expand Up @@ -552,7 +564,7 @@ export const MaskPolygon = LeafletPolygon.extend({

export const CircleMarker = BaseCircleMarker.extend({
parentClass: BaseCircleMarker,
includes: [FeatureMixin, PathMixin],
includes: [FeatureMixin, PathMixin, PointMixin],
initialize: function (feature, latlng) {
if (Array.isArray(latlng) && !(latlng[0] instanceof Number)) {
// Must be a line or polygon
Expand All @@ -570,4 +582,8 @@ export const CircleMarker = BaseCircleMarker.extend({
getCenter: function () {
return this._latlng
},
// FIXME when Leaflet.Editable knows about CircleMarker
editEnabled: () => false,
enableEdit: () => {}, // No-op
disableEdit: () => {}, // No-op
})

0 comments on commit 5409537

Please sign in to comment.