Add security to make not to longer cadastre request

This commit is contained in:
Xavier J 2016-01-22 14:01:02 +01:00
parent 4d812220fd
commit 0c2bbc482f
5 changed files with 55 additions and 13 deletions

1
.gitignore vendored
View file

@ -28,6 +28,5 @@ config/initializers/token.rb
doc/*.svg
rubocop.html
config/france_connect.yml
vendor/**/*
uploads/*

View file

@ -25,3 +25,4 @@
//= require graham_scan.min
//= require leaflet.freedraw
//= require smart_listing
//= require turf

View file

@ -21,17 +21,17 @@ function get_cadastre(coordinates) {
return cadastre['cadastres'];
}
function display_cadastre(cadastre_list) {
function display_cadastre(cadastre_array) {
if (!cadastre_active())
return;
cadastre_array = cadastre_list;
$("#cadastre.list ul").html('');
new_cadastreLayer();
if (cadastre_array.length > 0) {
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>');
@ -56,6 +56,5 @@ function new_cadastreLayer() {
map.removeLayer(cadastreItems);
cadastreItems = new L.GeoJSON();
cadastreItems.addTo(map);
}

View file

@ -41,17 +41,42 @@ function initCarto() {
add_event_freeDraw();
}
function default_position (){
function default_position() {
return {lon: LON, lat: LAT, zoom: 13}
}
function get_external_data (latLngs){
function get_external_data(latLngs) {
if (qp_active())
display_qp(get_qp(latLngs));
if (cadastre_active())
display_cadastre(get_cadastre(latLngs));
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']
]
}
})
}
function add_event_freeDraw() {

18
vendor/assets/javascripts/turf.js vendored Normal file

File diff suppressed because one or more lines are too long