Я пытаюсь обработать самопересечение на редактируемом многоугольнике, но когда я пытаюсь установить предыдущие значения (до пересечения), это работает только для векторного слоя, а не для маркеров. allowIntersection: false
также не работает. Что я делаю не так?
import { Path, withLeaflet } from 'react-leaflet';
import L, { Polygon as LeafletPolygon } from 'leaflet';
import kinks from '@turf/kinks';
import { polygon } from '@turf/helpers';
import 'leaflet-draw';
import type { EditablePolygonCmpProps } from './flow';
class EditablePolygonCmp extends Path<LeafletPolygon, EditablePolygonCmpProps> {
static defaultProps: * = {
options: {},
};
constructor(props: EditablePolygonCmpProps) {
super(props);
props.editStart();
L.Edit.PolyVerticesEdit = L.Edit.PolyVerticesEdit.mergeOptions({
allowIntersection: false,
drawError: {
color: '#b00b00',
timeout: 2500,
},
icon: new L.DivIcon({
iconSize: new L.Point(8, 8),
className: 'leaflet-div-icon leaflet-editing-icon',
}),
touchIcon: new L.DivIcon({
iconSize: new L.Point(10, 10),
className: 'leaflet-div-icon leaflet-editing-icon leaflet-touch-icon',
}),
guidelineDistance: 20,
maxGuideLineLength: 4000,
metric: true,
showLength: true,
zIndexOffset: 2000,
});
}
componentDidMount() {
super.componentDidMount();
this.leafletElement.editing.enable();
this.leafletElement.setStyle(this.props.options);
}
componentWillUnmount() {
super.componentWillUnmount();
this.props.editStop();
}
createLeafletElement(props: EditablePolygonCmpProps): LeafletPolygon {
return new LeafletPolygon(props.positions, this.getOptions(props.options));
}
updateLeafletElement(fromProps: EditablePolygonCmpProps, toProps: EditablePolygonCmpProps) {
if (toProps.positions !== fromProps.positions) {
const geoJSON = this.leafletElement.toGeoJSON();
const poly = polygon(geoJSON.geometry.coordinates);
if (kinks(poly).features.length) {
this.leafletElement.setLatLngs(fromProps.positions);
} else {
this.leafletElement.setLatLngs(toProps.positions);
}
}
this.setStyleIfChanged(fromProps.options, toProps.options);
}
}
export default withLeaflet(EditablePolygonCmpProps);
![No matching markers](https://i.stack.imgur.com/V6iBm.png)