Refactor carto to share more code
This commit is contained in:
parent
902184fab2
commit
febef735b8
8 changed files with 192 additions and 184 deletions
|
@ -1,16 +1,17 @@
|
|||
import { getData } from '../shared/data';
|
||||
import { initMap } from '../shared/carto';
|
||||
import {
|
||||
initMap,
|
||||
drawCadastre,
|
||||
drawQuartiersPrioritaires,
|
||||
drawUserSelection
|
||||
} from './carto/draw';
|
||||
} from '../shared/carto';
|
||||
|
||||
function initialize() {
|
||||
if (document.getElementById('map')) {
|
||||
const position = getData('carto').position;
|
||||
const map = initMap(position);
|
||||
const element = document.getElementById('map');
|
||||
|
||||
if (element) {
|
||||
const data = getData('carto');
|
||||
const map = initMap(element, data.position);
|
||||
|
||||
// draw external polygons
|
||||
drawCadastre(map, data);
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
import L from 'leaflet';
|
||||
import {
|
||||
drawLayer,
|
||||
noEditStyle,
|
||||
CADASTRE_POLYGON_STYLE,
|
||||
QP_POLYGON_STYLE
|
||||
} from '../../shared/carto';
|
||||
|
||||
export function drawCadastre(map, data) {
|
||||
drawLayer(
|
||||
map,
|
||||
data.cadastres,
|
||||
noEditStyle(CADASTRE_POLYGON_STYLE),
|
||||
'cadastres'
|
||||
);
|
||||
}
|
||||
|
||||
export function drawQuartiersPrioritaires(map, data) {
|
||||
drawLayer(
|
||||
map,
|
||||
data.quartiersPrioritaires,
|
||||
noEditStyle(QP_POLYGON_STYLE),
|
||||
'quartiersPrioritaires'
|
||||
);
|
||||
}
|
||||
|
||||
export function drawUserSelection(map, data) {
|
||||
if (data.selection.length > 0) {
|
||||
const polygon = L.polygon(data.selection, {
|
||||
color: 'red',
|
||||
zIndex: 3
|
||||
}).addTo(map);
|
||||
map.fitBounds(polygon.getBounds());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue