carto: extract draw method from old design carto
This commit is contained in:
parent
25e71634e7
commit
ad2c589e4d
1 changed files with 45 additions and 0 deletions
45
app/javascript/old_design/carto/draw.js
Normal file
45
app/javascript/old_design/carto/draw.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { EDIT, DELETE } from 'leaflet-freedraw';
|
||||
import { on } from '@utils';
|
||||
|
||||
import {
|
||||
drawLayer,
|
||||
CADASTRE_POLYGON_STYLE,
|
||||
QP_POLYGON_STYLE
|
||||
} from '../../shared/carto';
|
||||
|
||||
const SOURCES = {
|
||||
cadastres: CADASTRE_POLYGON_STYLE,
|
||||
quartiersPrioritaires: QP_POLYGON_STYLE
|
||||
};
|
||||
|
||||
export default function draw(map, freeDraw) {
|
||||
return data => {
|
||||
if (data.selection) {
|
||||
drawSelection(freeDraw, data.selection);
|
||||
}
|
||||
for (let source of Object.keys(SOURCES)) {
|
||||
if (data[source]) {
|
||||
drawLayer(map, data[source], SOURCES[source], source);
|
||||
}
|
||||
}
|
||||
addEventEdit(freeDraw);
|
||||
};
|
||||
}
|
||||
|
||||
function drawSelection(selection, freeDraw) {
|
||||
for (let polygon of selection) {
|
||||
freeDraw.createPolygon(polygon);
|
||||
}
|
||||
}
|
||||
|
||||
function addEventEdit(freeDraw) {
|
||||
document
|
||||
.querySelector('.leaflet-container svg')
|
||||
.removeAttribute('pointer-events');
|
||||
|
||||
on('.leaflet-container g path', 'click', () => {
|
||||
setTimeout(() => {
|
||||
freeDraw.mode(EDIT | DELETE);
|
||||
}, 50);
|
||||
});
|
||||
}
|
Loading…
Add table
Reference in a new issue