2015-12-10 14:33:09 +01:00
|
|
|
var LON = '2.428462';
|
|
|
|
var LAT = '46.538192';
|
|
|
|
|
2015-11-10 18:08:47 +01:00
|
|
|
function initCarto() {
|
|
|
|
OSM = L.tileLayer("http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png", {
|
2015-11-12 10:51:53 +01:00
|
|
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
2015-11-10 18:08:47 +01:00
|
|
|
});
|
|
|
|
|
2015-12-10 14:33:09 +01:00
|
|
|
position = get_position() || default_position();
|
2015-11-19 16:47:56 +01:00
|
|
|
|
2015-11-25 10:26:55 +01:00
|
|
|
map = L.map("map", {
|
2015-11-10 18:08:47 +01:00
|
|
|
center: new L.LatLng(position.lat, position.lon),
|
2015-11-19 16:47:56 +01:00
|
|
|
zoom: position.zoom,
|
2015-11-10 18:08:47 +01:00
|
|
|
layers: [OSM]
|
|
|
|
});
|
|
|
|
|
2016-01-18 14:45:08 +01:00
|
|
|
if (qp_active())
|
|
|
|
display_qp(JSON.parse($("#quartier_prioritaires").val()));
|
|
|
|
|
|
|
|
if (cadastre_active())
|
|
|
|
display_cadastre(JSON.parse($("#cadastres").val()));
|
|
|
|
|
2015-12-08 11:18:49 +01:00
|
|
|
freeDraw = new L.FreeDraw();
|
2016-01-18 14:45:08 +01:00
|
|
|
freeDraw.options.setSmoothFactor(4);
|
|
|
|
freeDraw.options.simplifyPolygon = false;
|
|
|
|
|
2015-11-10 18:08:47 +01:00
|
|
|
map.addLayer(freeDraw);
|
2015-11-12 17:34:12 +01:00
|
|
|
|
2015-11-19 16:47:56 +01:00
|
|
|
if ($("#json_latlngs").val() != '' && $("#json_latlngs").val() != '[]') {
|
2016-01-18 14:45:08 +01:00
|
|
|
map.setZoom(18);
|
|
|
|
|
2015-11-19 16:47:56 +01:00
|
|
|
$.each($.parseJSON($("#json_latlngs").val()), function (i, val) {
|
|
|
|
freeDraw.createPolygon(val);
|
|
|
|
});
|
2015-11-19 17:20:22 +01:00
|
|
|
|
|
|
|
map.fitBounds(freeDraw.polygons[0].getBounds());
|
2015-11-19 16:47:56 +01:00
|
|
|
}
|
|
|
|
else if (position.lat == LAT && position.lon == LON)
|
|
|
|
map.setView(new L.LatLng(position.lat, position.lon), 5);
|
2015-11-12 17:34:12 +01:00
|
|
|
|
2015-11-25 10:26:55 +01:00
|
|
|
add_event_freeDraw();
|
2015-11-12 17:34:12 +01:00
|
|
|
}
|
|
|
|
|
2016-01-22 14:01:02 +01:00
|
|
|
function default_position() {
|
2015-12-10 14:33:09 +01:00
|
|
|
return {lon: LON, lat: LAT, zoom: 13}
|
|
|
|
}
|
|
|
|
|
2016-01-22 14:01:02 +01:00
|
|
|
function get_external_data(latLngs) {
|
2016-01-15 11:53:00 +01:00
|
|
|
if (qp_active())
|
|
|
|
display_qp(get_qp(latLngs));
|
|
|
|
|
2016-01-22 14:01:02 +01:00
|
|
|
if (cadastre_active()) {
|
|
|
|
cadastre_list = [];
|
|
|
|
|
|
|
|
polygons = {"type": "FeatureCollection", "features": []};
|
|
|
|
|
|
|
|
for (i = 0; i < latLngs.length; i++)
|
|
|
|
polygons.features.push(feature_polygon_latLngs(latLngs[i]))
|
|
|
|
|
|
|
|
if (turf.area(polygons) < 300000)
|
|
|
|
cadastre_list = get_cadastre(latLngs);
|
|
|
|
else
|
|
|
|
cadastre_list = [{zoom_error: true}];
|
|
|
|
|
|
|
|
display_cadastre(cadastre_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function feature_polygon_latLngs(coordinates) {
|
|
|
|
return ({
|
|
|
|
"type": "Feature",
|
|
|
|
"properties": {},
|
|
|
|
"geometry": {
|
|
|
|
"type": "Polygon",
|
|
|
|
"coordinates": [
|
|
|
|
JSON.parse(L.FreeDraw.Utilities.getJsonPolygons([coordinates]))['latLngs']
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
2016-01-15 11:53:00 +01:00
|
|
|
}
|
|
|
|
|
2015-11-25 10:26:55 +01:00
|
|
|
function add_event_freeDraw() {
|
2015-11-19 16:47:56 +01:00
|
|
|
freeDraw.on('markers', function (e) {
|
2015-11-12 17:34:12 +01:00
|
|
|
$("#json_latlngs").val(JSON.stringify(e.latLngs));
|
2015-12-08 11:18:49 +01:00
|
|
|
|
2016-01-15 11:53:00 +01:00
|
|
|
get_external_data(e.latLngs);
|
2015-11-12 17:34:12 +01:00
|
|
|
});
|
|
|
|
|
2015-11-19 16:47:56 +01:00
|
|
|
$("#new").on('click', function (e) {
|
2015-11-12 17:34:12 +01:00
|
|
|
freeDraw.setMode(L.FreeDraw.MODES.CREATE);
|
|
|
|
});
|
|
|
|
|
2015-11-19 16:47:56 +01:00
|
|
|
$("#edit").on('click', function (e) {
|
2015-11-12 17:34:12 +01:00
|
|
|
freeDraw.setMode(L.FreeDraw.MODES.EDIT);
|
|
|
|
});
|
|
|
|
|
2015-11-19 16:47:56 +01:00
|
|
|
$("#delete").on('click', function (e) {
|
2015-11-12 17:34:12 +01:00
|
|
|
freeDraw.setMode(L.FreeDraw.MODES.DELETE);
|
|
|
|
});
|
2015-11-10 18:08:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_position() {
|
2015-08-10 11:05:06 +02:00
|
|
|
var position;
|
|
|
|
|
|
|
|
$.ajax({
|
2015-11-10 18:08:47 +01:00
|
|
|
url: '/users/dossiers/' + dossier_id + '/carte/position',
|
2015-08-10 11:05:06 +02:00
|
|
|
dataType: 'json',
|
|
|
|
async: false
|
|
|
|
}).done(function (data) {
|
|
|
|
position = data
|
2016-01-18 14:45:08 +01:00
|
|
|
position.zoom = default_position().zoom
|
2015-08-10 11:05:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return position;
|
2015-11-25 10:26:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function jsObject_to_array(qp_list) {
|
|
|
|
return Object.keys(qp_list).map(function (v) {
|
|
|
|
return qp_list[v];
|
|
|
|
});
|
|
|
|
}
|