Refactor carto code
This commit is contained in:
parent
51127c324d
commit
37d424d671
9 changed files with 211 additions and 214 deletions
|
@ -1,39 +1,44 @@
|
|||
function cadastre_active() {
|
||||
return $("#map.cadastre").length > 0
|
||||
import L from 'leaflet';
|
||||
import $ from 'jquery';
|
||||
|
||||
export function cadastreActive() {
|
||||
return $('#map.cadastre').length > 0;
|
||||
}
|
||||
|
||||
function get_cadastre(coordinates) {
|
||||
if (!cadastre_active())
|
||||
return;
|
||||
|
||||
var cadastre;
|
||||
|
||||
$.ajax({
|
||||
export function getCadastre(dossierId, coordinates) {
|
||||
return $.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'];
|
||||
url: `/users/dossiers/${dossierId}/carte/cadastre`,
|
||||
data: { coordinates: JSON.stringify(coordinates) },
|
||||
dataType: 'json'
|
||||
}).then(({ cadastres }) => cadastres);
|
||||
}
|
||||
|
||||
function display_cadastre(cadastre_array) {
|
||||
if (!cadastre_active())
|
||||
return;
|
||||
let cadastreItems;
|
||||
|
||||
$("#cadastre.list ul").html('');
|
||||
new_cadastreLayer();
|
||||
export function displayCadastre(map, cadastres) {
|
||||
if (!cadastreActive()) return;
|
||||
|
||||
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>');
|
||||
$('#cadastre.list ul').html('');
|
||||
newCadastreLayer(map);
|
||||
|
||||
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>');
|
||||
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>'
|
||||
);
|
||||
|
||||
cadastreItems.addData(cadastre.geometry);
|
||||
});
|
||||
|
@ -45,15 +50,16 @@ function display_cadastre(cadastre_array) {
|
|||
color: 'white',
|
||||
dashArray: '3',
|
||||
fillOpacity: 0.7
|
||||
})
|
||||
});
|
||||
} else {
|
||||
$('#cadastre.list ul').html('<li>AUCUN</li>');
|
||||
}
|
||||
else
|
||||
$("#cadastre.list ul").html('<li>AUCUN</li>');
|
||||
}
|
||||
|
||||
function new_cadastreLayer() {
|
||||
if (typeof cadastreItems != 'undefined')
|
||||
function newCadastreLayer(map) {
|
||||
if (cadastreItems) {
|
||||
map.removeLayer(cadastreItems);
|
||||
}
|
||||
|
||||
cadastreItems = new L.GeoJSON();
|
||||
cadastreItems.addTo(map);
|
||||
|
|
|
@ -1,39 +1,30 @@
|
|||
function qp_active() {
|
||||
return $("#map.qp").length > 0
|
||||
import L from 'leaflet';
|
||||
import $ from 'jquery';
|
||||
|
||||
export function qpActive() {
|
||||
return $('#map.qp').length > 0;
|
||||
}
|
||||
|
||||
function get_qp(coordinates) {
|
||||
if (!qp_active())
|
||||
return;
|
||||
|
||||
var qp;
|
||||
|
||||
$.ajax({
|
||||
export function getQP(dossierId, coordinates) {
|
||||
return $.ajax({
|
||||
method: 'post',
|
||||
url: '/users/dossiers/' + dossier_id + '/carte/qp',
|
||||
data: {coordinates: JSON.stringify(coordinates)},
|
||||
dataType: 'json',
|
||||
async: false
|
||||
}).done(function (data) {
|
||||
qp = data
|
||||
});
|
||||
|
||||
return qp['quartier_prioritaires'];
|
||||
url: `/users/dossiers/${dossierId}/carte/qp`,
|
||||
data: { coordinates: JSON.stringify(coordinates) },
|
||||
dataType: 'json'
|
||||
}).done(({ quartier_prioritaires }) => values(quartier_prioritaires));
|
||||
}
|
||||
|
||||
function display_qp(qp_list) {
|
||||
if (!qp_active())
|
||||
return;
|
||||
let qpItems;
|
||||
|
||||
qp_array = jsObject_to_array(qp_list);
|
||||
export function displayQP(map, qps) {
|
||||
if (!qpActive()) return;
|
||||
|
||||
$("#qp.list ul").html('');
|
||||
$('#qp.list ul').html('');
|
||||
newQPLayer(map);
|
||||
|
||||
new_qpLayer();
|
||||
|
||||
if (qp_array.length > 0) {
|
||||
qp_array.forEach(function (qp) {
|
||||
$("#qp.list ul").append('<li>' + qp.commune + ' : ' + qp.nom + '</li>');
|
||||
if (qps.length > 0) {
|
||||
qps.forEach(function(qp) {
|
||||
$('#qp.list ul').append('<li>' + qp.commune + ' : ' + qp.nom + '</li>');
|
||||
|
||||
qpItems.addData(qp.geometry);
|
||||
});
|
||||
|
@ -45,16 +36,21 @@ function display_qp(qp_list) {
|
|||
color: 'white',
|
||||
dashArray: '3',
|
||||
fillOpacity: 0.7
|
||||
})
|
||||
});
|
||||
} else {
|
||||
$('#qp.list ul').html('<li>AUCUN</li>');
|
||||
}
|
||||
else
|
||||
$("#qp.list ul").html('<li>AUCUN</li>');
|
||||
}
|
||||
|
||||
function new_qpLayer() {
|
||||
if (typeof qpItems != 'undefined')
|
||||
function newQPLayer(map) {
|
||||
if (qpItems) {
|
||||
map.removeLayer(qpItems);
|
||||
}
|
||||
|
||||
qpItems = new L.GeoJSON();
|
||||
qpItems.addTo(map);
|
||||
}
|
||||
|
||||
function values(obj) {
|
||||
return Object.keys(obj).map(v => obj[v]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue