mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 11:52:38 +02:00
fix: compute length of all shapes for MultiLineString not only first
This commit is contained in:
parent
401efc037d
commit
666a92ec44
2 changed files with 53 additions and 3 deletions
|
@ -255,7 +255,10 @@ const PathMixin = {
|
||||||
if (this._map.measureTools?.enabled()) {
|
if (this._map.measureTools?.enabled()) {
|
||||||
this._map._umap.tooltip.open({ content: this.getMeasure(), anchor: this })
|
this._map._umap.tooltip.open({ content: this.getMeasure(), anchor: this })
|
||||||
} else if (this._map._umap.editEnabled && !this._map._umap.editedFeature) {
|
} else if (this._map._umap.editEnabled && !this._map._umap.editedFeature) {
|
||||||
this._map._umap.tooltip.open({ content: translate('Click to edit'), anchor: this })
|
this._map._umap.tooltip.open({
|
||||||
|
content: translate('Click to edit'),
|
||||||
|
anchor: this,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -267,7 +270,9 @@ const PathMixin = {
|
||||||
this._map.once('moveend', this.makeGeometryEditable, this)
|
this._map.once('moveend', this.makeGeometryEditable, this)
|
||||||
const pointsCount = this._parts.reduce((acc, part) => acc + part.length, 0)
|
const pointsCount = this._parts.reduce((acc, part) => acc + part.length, 0)
|
||||||
if (pointsCount > 100 && this._map.getZoom() < this._map.getMaxZoom()) {
|
if (pointsCount > 100 && this._map.getZoom() < this._map.getMaxZoom()) {
|
||||||
this._map._umap.tooltip.open({ content: L._('Please zoom in to edit the geometry') })
|
this._map._umap.tooltip.open({
|
||||||
|
content: L._('Please zoom in to edit the geometry'),
|
||||||
|
})
|
||||||
this.disableEdit()
|
this.disableEdit()
|
||||||
} else {
|
} else {
|
||||||
this.enableEdit()
|
this.enableEdit()
|
||||||
|
@ -380,8 +385,19 @@ export const LeafletPolyline = Polyline.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
getMeasure: function (shape) {
|
getMeasure: function (shape) {
|
||||||
|
let shapes
|
||||||
|
if (shape) {
|
||||||
|
shapes = [shape]
|
||||||
|
} else if (LineUtil.isFlat(this._latlngs)) {
|
||||||
|
shapes = [this._latlngs]
|
||||||
|
} else {
|
||||||
|
shapes = this._latlngs
|
||||||
|
}
|
||||||
// FIXME: compute from data in feature (with TurfJS)
|
// FIXME: compute from data in feature (with TurfJS)
|
||||||
const length = L.GeoUtil.lineLength(this._map, shape || this._defaultShape())
|
const length = shapes.reduce(
|
||||||
|
(acc, shape) => acc + L.GeoUtil.lineLength(this._map, shape),
|
||||||
|
0
|
||||||
|
)
|
||||||
return L.GeoUtil.readableDistance(length, this._map.measureTools.getMeasureUnit())
|
return L.GeoUtil.readableDistance(length, this._map.measureTools.getMeasureUnit())
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -49,3 +49,37 @@ def test_should_open_popup_on_click(live_server, map, page, bootstrap):
|
||||||
# Close popup
|
# Close popup
|
||||||
page.locator("#map").click()
|
page.locator("#map").click()
|
||||||
expect(line).to_have_attribute("stroke-opacity", "0.5")
|
expect(line).to_have_attribute("stroke-opacity", "0.5")
|
||||||
|
|
||||||
|
|
||||||
|
def test_can_use_measure_on_name(live_server, map, page):
|
||||||
|
data = {
|
||||||
|
"type": "FeatureCollection",
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"type": "Feature",
|
||||||
|
"properties": {"name": "linestring"},
|
||||||
|
"geometry": {
|
||||||
|
"type": "LineString",
|
||||||
|
"coordinates": [
|
||||||
|
[11.25, 53.585984],
|
||||||
|
[10.151367, 52.975108],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Feature",
|
||||||
|
"properties": {"name": "multilinestring"},
|
||||||
|
"geometry": {
|
||||||
|
"type": "MultiLineString",
|
||||||
|
"coordinates": [[[8, 53], [13, 52]], [[12, 51], [15, 52]]],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
map.settings["properties"]["labelKey"] = "{name} ({measure})"
|
||||||
|
map.settings["properties"]["onLoadPanel"] = "databrowser"
|
||||||
|
map.save()
|
||||||
|
DataLayerFactory(map=map, data=data)
|
||||||
|
page.goto(f"{live_server.url}{map.get_absolute_url()}#6/10/50")
|
||||||
|
expect(page.get_by_text("linestring (99.7 km)")).to_be_visible()
|
||||||
|
expect(page.get_by_text("multilinestring (592 km)")).to_be_visible()
|
||||||
|
|
Loading…
Reference in a new issue