Merge pull request #5755 from vvlladd28/maps/edit-rectangle/cut

[3.3.2] UI: Fixed incorrect work edit rectangle with cut
This commit is contained in:
Igor Kulikov 2021-12-20 18:36:45 +02:00 committed by GitHub
commit 5b4288ba4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View File

@ -775,7 +775,7 @@ export default abstract class LeafletMap {
if (coordinates.length === 1) { if (coordinates.length === 1) {
coordinates = coordinates[0]; coordinates = coordinates[0];
} }
if (e.shape === 'Rectangle') { if (e.shape === 'Rectangle' && coordinates.length === 1) {
// @ts-ignore // @ts-ignore
const bounds: L.LatLngBounds = e.layer.getBounds(); const bounds: L.LatLngBounds = e.layer.getBounds();
const boundsArray = [bounds.getNorthWest(), bounds.getNorthEast(), bounds.getSouthWest(), bounds.getSouthEast()]; const boundsArray = [bounds.getNorthWest(), bounds.getNorthEast(), bounds.getSouthWest(), bounds.getSouthEast()];

View File

@ -56,3 +56,10 @@ export function bindPopupActions(popup: L.Popup, settings: MarkerSettings | Poly
} }
}); });
} }
export function isCutPolygon(data): boolean {
if (Array.isArray(data[0]) && Array.isArray(data[0][0])) {
return true;
}
return false;
}

View File

@ -15,7 +15,7 @@
/// ///
import L, { LatLngExpression, LeafletMouseEvent } from 'leaflet'; import L, { LatLngExpression, LeafletMouseEvent } from 'leaflet';
import { createTooltip } from './maps-utils'; import { createTooltip, isCutPolygon } from './maps-utils';
import { import {
fillPattern, fillPattern,
functionValueCalculator, functionValueCalculator,
@ -39,7 +39,7 @@ export class Polygon {
const polygonColor = this.getPolygonColor(settings); const polygonColor = this.getPolygonColor(settings);
const polygonStrokeColor = this.getPolygonStrokeColor(settings); const polygonStrokeColor = this.getPolygonStrokeColor(settings);
const polyData = data[this.settings.polygonKeyName]; const polyData = data[this.settings.polygonKeyName];
const polyConstructor = polyData.length > 2 ? L.polygon : L.rectangle; const polyConstructor = isCutPolygon(polyData) || polyData.length > 2 ? L.polygon : L.rectangle;
this.leafletPoly = polyConstructor(polyData, { this.leafletPoly = polyConstructor(polyData, {
fill: true, fill: true,
fillColor: polygonColor, fillColor: polygonColor,
@ -102,7 +102,7 @@ export class Polygon {
this.data = data; this.data = data;
this.dataSources = dataSources; this.dataSources = dataSources;
const polyData = data[this.settings.polygonKeyName]; const polyData = data[this.settings.polygonKeyName];
if (polyData.length > 2) { if (isCutPolygon(polyData) || polyData.length > 2) {
if (this.leafletPoly instanceof L.Rectangle) { if (this.leafletPoly instanceof L.Rectangle) {
this.map.removeLayer(this.leafletPoly); this.map.removeLayer(this.leafletPoly);
const polygonColor = this.getPolygonColor(settings); const polygonColor = this.getPolygonColor(settings);