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() {
|
2017-10-11 14:42:27 +02:00
|
|
|
OSM = L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
2017-04-04 16:15:33 +02:00
|
|
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
|
|
|
});
|
2015-11-10 18:08:47 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
position = get_position() || default_gestionnaire_position();
|
2015-11-19 16:47:56 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
map = L.map("map", {
|
|
|
|
center: new L.LatLng(position.lat, position.lon),
|
|
|
|
zoom: position.zoom,
|
|
|
|
layers: [OSM],
|
|
|
|
scrollWheelZoom: false
|
|
|
|
});
|
2015-11-10 18:08:47 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
icon = L.icon({
|
|
|
|
iconUrl: '/assets/marker-icon.png',
|
|
|
|
//shadowUrl: 'leaf-shadow.png',
|
2016-06-09 16:28:44 +02:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
iconSize: [34.48, 40], // size of the icon
|
|
|
|
//shadowSize: [50, 64], // size of the shadow
|
|
|
|
iconAnchor: [20, 20] // point of the icon which will correspond to marker's location
|
|
|
|
//shadowAnchor: [4, 62], // the same for the shadow
|
|
|
|
//popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
|
|
|
|
});
|
2016-06-09 16:28:44 +02:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
if (qp_active())
|
|
|
|
display_qp(JSON.parse($("#quartier_prioritaires").val()));
|
2016-01-18 14:45:08 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
if (cadastre_active())
|
|
|
|
display_cadastre(JSON.parse($("#cadastres").val()));
|
2016-01-18 14:45:08 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
freeDraw = new L.FreeDraw();
|
|
|
|
freeDraw.options.setSmoothFactor(4);
|
|
|
|
freeDraw.options.simplifyPolygon = false;
|
2016-01-18 14:45:08 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
map.addLayer(freeDraw);
|
2015-11-12 17:34:12 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
if ($("#json_latlngs").val() != '' && $("#json_latlngs").val() != '[]') {
|
|
|
|
map.setZoom(18);
|
2016-01-18 14:45:08 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
$.each($.parseJSON($("#json_latlngs").val()), function (i, val) {
|
|
|
|
freeDraw.createPolygon(val);
|
|
|
|
});
|
2015-11-19 17:20:22 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
map.fitBounds(freeDraw.polygons[0].getBounds());
|
|
|
|
}
|
|
|
|
else if (position.lat == LAT && position.lon == LON)
|
|
|
|
map.setView(new L.LatLng(position.lat, position.lon), position.zoom);
|
2015-11-12 17:34:12 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
add_event_freeDraw();
|
|
|
|
add_event_search_address();
|
2015-11-12 17:34:12 +01:00
|
|
|
}
|
|
|
|
|
2016-01-27 15:48:27 +01:00
|
|
|
function default_gestionnaire_position() {
|
2017-04-04 16:15:33 +02:00
|
|
|
return {lon: LON, lat: LAT, zoom: 5}
|
2015-12-10 14:33:09 +01:00
|
|
|
}
|
|
|
|
|
2016-01-22 14:01:02 +01:00
|
|
|
function get_external_data(latLngs) {
|
2017-04-04 16:15:33 +02:00
|
|
|
if (qp_active())
|
|
|
|
display_qp(get_qp(latLngs));
|
2016-01-15 11:53:00 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
if (cadastre_active()) {
|
|
|
|
polygons = {"type": "FeatureCollection", "features": []};
|
2016-01-22 14:01:02 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
for (i = 0; i < latLngs.length; i++)
|
|
|
|
polygons.features.push(feature_polygon_latLngs(latLngs[i]))
|
2016-01-22 14:01:02 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
cadastre_list = [{zoom_error: true}];
|
2016-01-27 15:48:27 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
if (turf_area(polygons) < 300000)
|
|
|
|
cadastre_list = get_cadastre(latLngs);
|
2016-01-22 14:01:02 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
display_cadastre(cadastre_list);
|
|
|
|
}
|
2016-01-22 14:01:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function feature_polygon_latLngs(coordinates) {
|
2017-04-04 16:15:33 +02:00
|
|
|
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() {
|
2017-04-04 16:15:33 +02:00
|
|
|
freeDraw.on('markers', function (e) {
|
|
|
|
$("#json_latlngs").val(JSON.stringify(e.latLngs));
|
2015-12-08 11:18:49 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
add_event_edit();
|
2016-06-14 11:00:57 +02:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
get_external_data(e.latLngs);
|
|
|
|
});
|
2015-11-12 17:34:12 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
$("#map").on('click', function(){
|
|
|
|
freeDraw.setMode(L.FreeDraw.MODES.VIEW);
|
|
|
|
});
|
2015-11-12 17:34:12 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
$("#new").on('click', function (e) {
|
|
|
|
freeDraw.setMode(L.FreeDraw.MODES.CREATE);
|
|
|
|
});
|
2015-11-12 17:34:12 +01:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
$("#delete").on('click', function (e) {
|
|
|
|
freeDraw.setMode(L.FreeDraw.MODES.DELETE);
|
|
|
|
});
|
2015-11-10 18:08:47 +01:00
|
|
|
}
|
|
|
|
|
2016-06-14 11:00:57 +02:00
|
|
|
function add_event_edit (){
|
2017-04-04 16:15:33 +02:00
|
|
|
$(".leaflet-container g path").on('click', function (e) {
|
|
|
|
setTimeout(function(){freeDraw.setMode(L.FreeDraw.MODES.EDIT | L.FreeDraw.MODES.DELETE)}, 50);
|
|
|
|
});
|
2016-06-14 11:00:57 +02:00
|
|
|
}
|
|
|
|
|
2015-11-10 18:08:47 +01:00
|
|
|
function get_position() {
|
2017-04-04 16:15:33 +02:00
|
|
|
var position;
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2017-04-04 16:15:33 +02:00
|
|
|
$.ajax({
|
|
|
|
url: '/users/dossiers/' + dossier_id + '/carte/position',
|
|
|
|
dataType: 'json',
|
|
|
|
async: false
|
|
|
|
}).done(function (data) {
|
|
|
|
position = data
|
|
|
|
});
|
|
|
|
|
|
|
|
return position;
|
2015-11-25 10:26:55 +01:00
|
|
|
}
|
|
|
|
|
2016-06-09 16:28:44 +02:00
|
|
|
function get_address_point(request) {
|
2017-12-06 16:15:28 +01:00
|
|
|
$.get('/ban/address_point', { request: request })
|
|
|
|
.done(function (data) {
|
|
|
|
if (data.lat !== null) {
|
|
|
|
map.setView(new L.LatLng(data.lat, data.lon), data.zoom);
|
|
|
|
}
|
|
|
|
});
|
2016-06-09 16:28:44 +02:00
|
|
|
}
|
|
|
|
|
2015-11-25 10:26:55 +01:00
|
|
|
function jsObject_to_array(qp_list) {
|
2017-04-04 16:15:33 +02:00
|
|
|
return Object.keys(qp_list).map(function (v) {
|
|
|
|
return qp_list[v];
|
|
|
|
});
|
2015-11-25 10:26:55 +01:00
|
|
|
}
|
2016-06-09 16:28:44 +02:00
|
|
|
|
|
|
|
function add_event_search_address() {
|
2017-04-12 11:12:05 +02:00
|
|
|
$("#search-by-address input[type='address']").bind('typeahead:select', function (ev, seggestion) {
|
2017-04-04 16:15:33 +02:00
|
|
|
get_address_point(seggestion['label']);
|
|
|
|
});
|
|
|
|
|
2017-04-12 11:12:05 +02:00
|
|
|
$("#search-by-address input[type='address']").keypress(function (e) {
|
2017-04-04 16:15:33 +02:00
|
|
|
if (e.keyCode == 13)
|
|
|
|
get_address_point($(this).val());
|
|
|
|
});
|
2017-02-01 10:31:32 +01:00
|
|
|
}
|