demarches-normaliennes/app/assets/javascripts/carte.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

function initCarto() {
OSM = L.tileLayer("http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png", {
2015-11-12 10:51:53 +01:00
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
position = get_position();
var map = L.map("map", {
center: new L.LatLng(position.lat, position.lon),
zoom: 13,
layers: [OSM]
});
var freeDraw = new L.FreeDraw({
mode: L.FreeDraw.MODES.CREATE
});
map.addLayer(freeDraw);
$.each($.parseJSON($("#json_latlngs").val()), function(i, val){
freeDraw.createPolygon(val);
});
add_event_freeDraw(freeDraw);
}
function add_event_freeDraw(freeDraw){
freeDraw.on('markers', function (e){
$("#json_latlngs").val(JSON.stringify(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() {
2015-08-10 11:05:06 +02:00
var position;
$.ajax({
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;
}