Add get_cadastre on TPS carte page and display on leaflet map
This commit is contained in:
parent
6d4b29cf36
commit
2ce8e4734b
14 changed files with 283 additions and 91 deletions
61
app/assets/javascripts/carte/cadastre.js
Normal file
61
app/assets/javascripts/carte/cadastre.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
function cadastre_active() {
|
||||
return $("#map.cadastre").length > 0
|
||||
}
|
||||
|
||||
function get_cadastre(coordinates) {
|
||||
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_list) {
|
||||
if (!cadastre_active())
|
||||
return;
|
||||
|
||||
cadastre_array = cadastre_list;
|
||||
|
||||
$("#cadastre.list ul").html('');
|
||||
|
||||
new_cadastreLayer();
|
||||
|
||||
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>');
|
||||
|
||||
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() {
|
||||
if (typeof cadastreItems != 'undefined')
|
||||
map.removeLayer(cadastreItems);
|
||||
|
||||
cadastreItems = new L.GeoJSON();
|
||||
|
||||
cadastreItems.addTo(map);
|
||||
}
|
93
app/assets/javascripts/carte/carte.js
Normal file
93
app/assets/javascripts/carte/carte.js
Normal file
|
@ -0,0 +1,93 @@
|
|||
var LON = '2.428462';
|
||||
var LAT = '46.538192';
|
||||
|
||||
function initCarto() {
|
||||
OSM = L.tileLayer("http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png", {
|
||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
||||
});
|
||||
|
||||
position = get_position() || default_position();
|
||||
|
||||
if (position.lon == "0" && position.lat == "0")
|
||||
position = default_position();
|
||||
|
||||
if (typeof position.zoom == 'undefined')
|
||||
position.zoom = 13;
|
||||
|
||||
map = L.map("map", {
|
||||
center: new L.LatLng(position.lat, position.lon),
|
||||
zoom: position.zoom,
|
||||
layers: [OSM]
|
||||
});
|
||||
|
||||
freeDraw = new L.FreeDraw();
|
||||
map.addLayer(freeDraw);
|
||||
|
||||
if ($("#json_latlngs").val() != '' && $("#json_latlngs").val() != '[]') {
|
||||
$.each($.parseJSON($("#json_latlngs").val()), function (i, val) {
|
||||
freeDraw.createPolygon(val);
|
||||
});
|
||||
|
||||
map.fitBounds(freeDraw.polygons[0].getBounds());
|
||||
}
|
||||
else if (position.lat == LAT && position.lon == LON)
|
||||
map.setView(new L.LatLng(position.lat, position.lon), 5);
|
||||
|
||||
add_event_freeDraw();
|
||||
|
||||
if (qp_active())
|
||||
display_qp(JSON.parse($("#quartier_prioritaires").val()));
|
||||
}
|
||||
|
||||
function default_position (){
|
||||
return {lon: LON, lat: LAT, zoom: 13}
|
||||
}
|
||||
|
||||
function get_external_data (latLngs){
|
||||
|
||||
if (qp_active())
|
||||
display_qp(get_qp(latLngs));
|
||||
|
||||
if (cadastre_active())
|
||||
display_cadastre(get_cadastre(latLngs));
|
||||
}
|
||||
|
||||
function add_event_freeDraw() {
|
||||
freeDraw.on('markers', function (e) {
|
||||
$("#json_latlngs").val(JSON.stringify(e.latLngs));
|
||||
|
||||
get_external_data(e.latLngs);
|
||||
});
|
||||
|
||||
$("#new").on('click', function (e) {
|
||||
freeDraw.setMode(L.FreeDraw.MODES.CREATE);
|
||||
});
|
||||
|
||||
$("#edit").on('click', function (e) {
|
||||
freeDraw.setMode(L.FreeDraw.MODES.EDIT);
|
||||
});
|
||||
|
||||
$("#delete").on('click', function (e) {
|
||||
freeDraw.setMode(L.FreeDraw.MODES.DELETE);
|
||||
});
|
||||
}
|
||||
|
||||
function get_position() {
|
||||
var position;
|
||||
|
||||
$.ajax({
|
||||
url: '/users/dossiers/' + dossier_id + '/carte/position',
|
||||
dataType: 'json',
|
||||
async: false
|
||||
}).done(function (data) {
|
||||
position = data
|
||||
});
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
function jsObject_to_array(qp_list) {
|
||||
return Object.keys(qp_list).map(function (v) {
|
||||
return qp_list[v];
|
||||
});
|
||||
}
|
60
app/assets/javascripts/carte/qp.js
Normal file
60
app/assets/javascripts/carte/qp.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
function qp_active() {
|
||||
return $("#map.qp").length > 0
|
||||
}
|
||||
|
||||
function get_qp(coordinates) {
|
||||
if (!qp_active())
|
||||
return;
|
||||
|
||||
var qp;
|
||||
|
||||
$.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'];
|
||||
}
|
||||
|
||||
function display_qp(qp_list) {
|
||||
if (!qp_active())
|
||||
return;
|
||||
|
||||
qp_array = jsObject_to_array(qp_list);
|
||||
|
||||
$("#qp.list ul").html('');
|
||||
|
||||
new_qpLayer();
|
||||
|
||||
if (qp_array.length > 0) {
|
||||
qp_array.forEach(function (qp) {
|
||||
$("#qp.list ul").append('<li>' + qp.commune + ' : ' + qp.nom + '</li>');
|
||||
|
||||
qpItems.addData(qp.geometry);
|
||||
});
|
||||
|
||||
qpItems.setStyle({
|
||||
fillColor: '#31708f',
|
||||
weight: 2,
|
||||
opacity: 0.3,
|
||||
color: 'white',
|
||||
dashArray: '3',
|
||||
fillOpacity: 0.7
|
||||
})
|
||||
}
|
||||
else
|
||||
$("#qp.list ul").html('<li>AUCUN</li>');
|
||||
}
|
||||
|
||||
function new_qpLayer() {
|
||||
if (typeof qpItems != 'undefined')
|
||||
map.removeLayer(qpItems);
|
||||
|
||||
qpItems = new L.GeoJSON();
|
||||
qpItems.addTo(map);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue