demarches-normaliennes/app/javascript/old_design/carto/cadastre.js

67 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-10-03 10:39:35 +02:00
import L from 'leaflet';
import $ from 'jquery';
2017-04-04 16:15:33 +02:00
2018-10-03 10:39:35 +02:00
export function cadastreActive() {
return $('#map.cadastre').length > 0;
}
2017-04-04 16:15:33 +02:00
2018-10-03 10:39:35 +02:00
export function getCadastre(dossierId, coordinates) {
return $.ajax({
2017-04-04 16:15:33 +02:00
method: 'post',
2018-10-03 10:39:35 +02:00
url: `/users/dossiers/${dossierId}/carte/cadastre`,
data: { coordinates: JSON.stringify(coordinates) },
dataType: 'json'
}).then(({ cadastres }) => cadastres);
}
2018-10-03 10:39:35 +02:00
let cadastreItems;
2017-04-04 16:15:33 +02:00
2018-10-03 10:39:35 +02:00
export function displayCadastre(map, cadastres) {
if (!cadastreActive()) return;
2017-04-04 16:15:33 +02:00
2018-10-03 10:39:35 +02:00
$('#cadastre.list ul').html('');
newCadastreLayer(map);
2017-04-04 16:15:33 +02:00
2018-10-03 10:39:35 +02:00
if (cadastres.length == 1 && cadastres[0]['zoom_error']) {
$('#cadastre.list ul').html(
'<li><b>Merci de dessiner une surface plus petite afin de récupérer les parcelles cadastrales.</b></li>'
);
} else if (cadastres.length > 0) {
cadastres.forEach(function(cadastre) {
$('#cadastre.list ul').append(
'<li> Parcelle nº ' +
cadastre.numero +
' - Feuille ' +
cadastre.code_arr +
' ' +
cadastre.section +
' ' +
cadastre.feuille +
'</li>'
);
2017-04-04 16:15:33 +02:00
cadastreItems.addData(cadastre.geometry);
});
cadastreItems.setStyle({
fillColor: '#8a6d3b',
weight: 2,
opacity: 0.3,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
2018-10-03 10:39:35 +02:00
});
} else {
$('#cadastre.list ul').html('<li>AUCUN</li>');
2017-04-04 16:15:33 +02:00
}
}
2018-10-03 10:39:35 +02:00
function newCadastreLayer(map) {
if (cadastreItems) {
2017-04-04 16:15:33 +02:00
map.removeLayer(cadastreItems);
2018-10-03 10:39:35 +02:00
}
2017-04-04 16:15:33 +02:00
cadastreItems = new L.GeoJSON();
cadastreItems.addTo(map);
2017-04-04 15:27:04 +02:00
}