Merge pull request #2102 from umap-project/edit-circlemarker-properties

fix: do not fail when trying to edit a circlemarker
This commit is contained in:
Yohan Boniface 2024-09-04 16:00:55 +02:00 committed by GitHub
commit ff014429b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 13 deletions

View file

@ -98,6 +98,10 @@ class Feature {
this.pushGeometry()
}
isOnScreen() {
return this.ui?.isOnScreen()
}
pushGeometry() {
this.ui.setLatLngs(this.toLatLngs())
}
@ -257,7 +261,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) {
@ -661,11 +665,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 {
@ -753,11 +752,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')

View file

@ -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)
@ -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({
@ -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
@ -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
})