Move old carto code to webpacker

This commit is contained in:
Paul Chavard 2018-10-03 10:37:36 +02:00
parent 6ed4bb538c
commit 51127c324d
3 changed files with 0 additions and 0 deletions

View file

@ -1,60 +0,0 @@
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_array) {
if (!cadastre_active())
return;
$("#cadastre.list ul").html('');
new_cadastreLayer();
if (cadastre_array.length == 1 && cadastre_array[0]['zoom_error'])
$("#cadastre.list ul").html('<li><b>Merci de dessiner une surface plus petite afin de récupérer les parcelles cadastrales.</b></li>');
else 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);
}

View file

@ -1,159 +0,0 @@
var LON = '2.428462';
var LAT = '46.538192';
function initCarto() {
OSM = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
position = get_position() || default_gestionnaire_position();
map = L.map("map", {
center: new L.LatLng(position.lat, position.lon),
zoom: position.zoom,
layers: [OSM],
scrollWheelZoom: false
});
icon = L.icon({
iconUrl: '/assets/marker-icon.png',
//shadowUrl: 'leaf-shadow.png',
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
});
if (qp_active())
display_qp(JSON.parse($("#quartier_prioritaires").val()));
if (cadastre_active())
display_cadastre(JSON.parse($("#cadastres").val()));
freeDraw = new L.FreeDraw();
freeDraw.options.setSmoothFactor(4);
freeDraw.options.simplifyPolygon = false;
map.addLayer(freeDraw);
if ($("#json_latlngs").val() != '' && $("#json_latlngs").val() != '[]') {
map.setZoom(18);
$.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), position.zoom);
add_event_freeDraw();
add_event_search_address();
}
function default_gestionnaire_position() {
return {lon: LON, lat: LAT, zoom: 5}
}
function get_external_data(latLngs) {
if (qp_active())
display_qp(get_qp(latLngs));
if (cadastre_active()) {
polygons = {"type": "FeatureCollection", "features": []};
for (i = 0; i < latLngs.length; i++)
polygons.features.push(feature_polygon_latLngs(latLngs[i]))
cadastre_list = [{zoom_error: true}];
if (turf_area(polygons) < 300000)
cadastre_list = get_cadastre(latLngs);
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']
]
}
})
}
function add_event_freeDraw() {
freeDraw.on('markers', function (e) {
$("#json_latlngs").val(JSON.stringify(e.latLngs));
add_event_edit();
get_external_data(e.latLngs);
});
$("#map").on('click', function(){
freeDraw.setMode(L.FreeDraw.MODES.VIEW);
});
$("#new").on('click', function (e) {
freeDraw.setMode(L.FreeDraw.MODES.CREATE);
});
$("#delete").on('click', function (e) {
freeDraw.setMode(L.FreeDraw.MODES.DELETE);
});
}
function add_event_edit (){
$(".leaflet-container g path").on('click', function (e) {
setTimeout(function(){freeDraw.setMode(L.FreeDraw.MODES.EDIT | L.FreeDraw.MODES.DELETE)}, 50);
});
}
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 get_address_point(request) {
$.get('/ban/address_point', { request: request })
.done(function (data) {
if (data.lat !== null) {
map.setView(new L.LatLng(data.lat, data.lon), data.zoom);
}
});
}
function jsObject_to_array(qp_list) {
return Object.keys(qp_list).map(function (v) {
return qp_list[v];
});
}
function add_event_search_address() {
$("#search-by-address input[type='address']").bind('autocomplete:select', function (ev, suggestion) {
get_address_point(suggestion['label']);
});
$("#search-by-address input[type='address']").keypress(function (e) {
if (e.keyCode == 13)
get_address_point($(this).val());
});
}

View file

@ -1,60 +0,0 @@
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);
}