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-11-19 16:47:56 +01:00
|
|
|
var LON = '2.428462';
|
|
|
|
var LAT = '46.538192';
|
|
|
|
|
|
|
|
position = get_position() || {lon: LON, lat: LAT, zoom: 13};
|
|
|
|
|
|
|
|
if (typeof position.zoom == 'undefined')
|
|
|
|
position.zoom = 13;
|
2015-11-10 18:08:47 +01:00
|
|
|
|
|
|
|
var map = L.map("map", {
|
|
|
|
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]
|
|
|
|
});
|
|
|
|
|
2015-11-12 17:34:12 +01:00
|
|
|
var freeDraw = new L.FreeDraw({
|
2015-11-19 16:47:56 +01:00
|
|
|
//mode: L.FreeDraw.MODES.CREATE
|
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() != '[]') {
|
|
|
|
$.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
|
|
|
|
|
|
|
add_event_freeDraw(freeDraw);
|
|
|
|
}
|
|
|
|
|
2015-11-19 16:47:56 +01:00
|
|
|
function add_event_freeDraw(freeDraw) {
|
|
|
|
freeDraw.on('markers', function (e) {
|
2015-11-12 17:34:12 +01:00
|
|
|
$("#json_latlngs").val(JSON.stringify(e.latLngs));
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
return position;
|
|
|
|
}
|