demarches-normaliennes/app/assets/javascripts/old_design/carte/cadastre.js

61 lines
1.5 KiB
JavaScript
Raw Normal View History

function cadastre_active() {
2017-04-04 16:15:33 +02:00
return $("#map.cadastre").length > 0
}
function get_cadastre(coordinates) {
2017-04-04 16:15:33 +02:00
if (!cadastre_active())
return;
var cadastre;
$.ajax({
method: 'post',
url: '/users/dossiers/' + dossier_id + '/carte/cadastre',
data: {coordinates: JSON.stringify(coordinates)},
dataType: 'json',
async: false
}).done(function (data) {
cadastre = data
});
return cadastre['cadastres'];
}
function display_cadastre(cadastre_array) {
2017-04-04 16:15:33 +02:00
if (!cadastre_active())
return;
$("#cadastre.list ul").html('');
new_cadastreLayer();
if (cadastre_array.length == 1 && cadastre_array[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 (cadastre_array.length > 0) {
cadastre_array.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
})
}
else
$("#cadastre.list ul").html('<li>AUCUN</li>');
}
function new_cadastreLayer() {
2017-04-04 16:15:33 +02:00
if (typeof cadastreItems != 'undefined')
map.removeLayer(cadastreItems);
2017-04-04 16:15:33 +02:00
cadastreItems = new L.GeoJSON();
cadastreItems.addTo(map);
2017-04-04 15:27:04 +02:00
}