- Save polygon from carte on procedure

- Display save polygon from database
This commit is contained in:
Xavier J 2015-11-12 17:34:12 +01:00
parent 047cf952f7
commit ce6af625d2
7 changed files with 103 additions and 34 deletions

View file

@ -1,5 +1,3 @@
//récupération de la position de l'entreprise
function initCarto() {
OSM = L.tileLayer("http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png", {
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
@ -13,11 +11,35 @@ function initCarto() {
layers: [OSM]
});
freeDraw = new L.FreeDraw({
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() {
@ -32,23 +54,4 @@ function get_position() {
});
return position;
}
function get_ref_dossier() {
$.post("http://apicarto.coremaps.com/api/v1/datastore", {
contentType: "application/json",
dataType: 'json',
geom: JSON.stringify(window.featureCollection.features[0]),
ascyn: false
}).done(function (data) {
$("#ref_dossier").val(data.reference);
});
}
function submit_check_draw(e) {
if (window.location.href.indexOf('carte') > -1 && window.featureCollection.features.length == 0) {
$("#flash_message").html('<div class="alert alert-danger">Un dessin est obligatoire.</div>');
e.preventDefault();
return false;
}
}

View file

@ -6,18 +6,79 @@ table {
font-size: 13;
}
#map.mode-create {
cursor: crosshair;
#map section.overlay {
position: absolute;
top: 0;
left: 0;
pointer-events: none;
box-shadow: inset -100px 0 100px -100px rgba(0, 0, 0, .25);
width: 100%;
height: 100%;
z-index: 2001;
}
svg.tracer {
#map.mode-create {
cursor: crosshair !important;
}
#map g path {
transition: all 0.25s;
stroke-width: 4px;
stroke-opacity: 1;
stroke: #D7217E;
position: absolute;
z-index: 1001;
fill: #D7217E;
fill-opacity: .75;
-webkit-filter: none;
}
#map.mode-delete path {
cursor: no-drop !important;
}
#map.mode-delete path:hover {
fill: #4d4d4d !important;
}
#map div.polygon-elbow {
-webkit-transition: opacity .25s;
box-shadow: 0 0 0 2px white, 0 0 10px rgba(0, 0, 0, .35);
border: 5px solid #D7217E;
border-radius: 10px;
transition: opacity 0.25s;
cursor: move;
opacity: 0;
pointer-events: none;
box-sizing: border-box;
width: 0 !important;
height: 0 !important;
}
#map div.polygon-elbow.non-polygon {
opacity: 0 !important;
pointer-events: none !important;
border: 5px solid darkgray;
}
#map.mode-edit div.polygon-elbow {
opacity: 1;
pointer-events: all;
}
#map svg.tracer {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2001;
pointer-events: none;
}
.info {
padding: 6px 8px;
font: 14px/16px Arial, Helvetica, sans-serif;

View file

@ -10,9 +10,9 @@ class Users::CarteController < UsersController
def save_ref_api_carto
dossier = current_user_dossier
dossier.update_attributes(json_latlngs: params[:json_latlngs])
if dossier.draft?
#dossier.update_attributes(ref_dossier_carto: params[:ref_dossier])
redirect_to url_for(controller: :description, action: :show, dossier_id: params[:dossier_id])
else
commentaire_params = {
@ -23,7 +23,6 @@ class Users::CarteController < UsersController
commentaire = Commentaire.new commentaire_params
commentaire.save
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: params[:dossier_id])
end
end

View file

@ -3,11 +3,11 @@
%br
.content{style:'margin-bottom:60px'}
%button.btn.btn-sm.btn-success{type:'button', disabled: 'disabled'} Nouveau
%button#new.btn.btn-sm.btn-success{type:'button'} Nouveau
\-
%button.btn.btn-sm.btn-info{type:'button', disabled: 'disabled'} Editer
%button#edit.btn.btn-sm.btn-info{type:'button'} Editer
\-
%button.btn.btn-sm.btn-danger{type:'button', disabled: 'disabled'} Supprimer
%button#delete.btn.btn-sm.btn-danger{type:'button'} Supprimer
%br
%br
@ -15,7 +15,7 @@
= form_tag(url_for({controller: :carte, action: :save_ref_api_carto, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
%br
%input{type: 'hidden', value: '', name: 'ref_dossier', id: 'ref_dossier'}
%input{type: 'hidden', value: "#{@dossier.json_latlngs}", name: 'json_latlngs', id: 'json_latlngs'}
-if @dossier.draft?
=render partial: '/layouts/etape_suivante'

View file

@ -0,0 +1,5 @@
class AddJsonLatLngsToDossier < ActiveRecord::Migration
def change
add_column :dossiers, :json_latlngs, :text
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151110091451) do
ActiveRecord::Schema.define(version: 20151112151918) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -66,6 +66,7 @@ ActiveRecord::Schema.define(version: 20151110091451) do
t.datetime "updated_at", default: '2015-09-22 09:25:29'
t.string "state"
t.integer "user_id"
t.text "json_latlngs"
end
add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree

View file

@ -22,8 +22,8 @@ describe 'users/carte/show.html.haml', type: :view do
end
context 'présence des inputs hidden' do
it 'stockage de la référence du dossie de l\'API carto' do
expect(rendered).to have_selector('input[type=hidden][id=ref_dossier][name=ref_dossier]')
it 'stockage du json des polygons dessinés' do
expect(rendered).to have_selector('input[type=hidden][id=json_latlngs][name=json_latlngs]')
end
end