Add address input on carte view
This commit is contained in:
parent
54256b1e55
commit
b987b86bd8
7 changed files with 72 additions and 25 deletions
BIN
app/assets/images/marker-icon.png
Normal file
BIN
app/assets/images/marker-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.4 KiB |
22
app/assets/javascripts/address_typeahead.js
Normal file
22
app/assets/javascripts/address_typeahead.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
function address_type_init() {
|
||||
display = 'label';
|
||||
|
||||
var bloodhound = new Bloodhound({
|
||||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(display),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
|
||||
remote: {
|
||||
url: '/ban/search?request=%QUERY',
|
||||
wildcard: '%QUERY'
|
||||
}
|
||||
});
|
||||
bloodhound.initialize();
|
||||
|
||||
$("input[type='address']").typeahead({
|
||||
minLength: 1
|
||||
}, {
|
||||
display: display,
|
||||
source: bloodhound,
|
||||
limit: 5
|
||||
});
|
||||
}
|
|
@ -14,6 +14,17 @@ function initCarto() {
|
|||
layers: [OSM]
|
||||
});
|
||||
|
||||
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()));
|
||||
|
||||
|
@ -39,6 +50,7 @@ function initCarto() {
|
|||
map.setView(new L.LatLng(position.lat, position.lon), position.zoom);
|
||||
|
||||
add_event_freeDraw();
|
||||
add_event_search_address();
|
||||
}
|
||||
|
||||
function default_gestionnaire_position() {
|
||||
|
@ -111,8 +123,32 @@ function get_position() {
|
|||
return position;
|
||||
}
|
||||
|
||||
function get_address_point(request) {
|
||||
$.ajax({
|
||||
url: '/ban/address_point?request=' + request,
|
||||
dataType: 'json',
|
||||
async: true
|
||||
}).done(function (data) {
|
||||
if (data.lat != null) {
|
||||
map.setView(new L.LatLng(data.lat, data.lon), data.zoom);
|
||||
L.marker([data.lat, data.lon], {icon: icon}).addTo(map);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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('typeahead:select', function (ev, seggestion) {
|
||||
get_address_point(seggestion['label']);
|
||||
});
|
||||
|
||||
$("#search_by_address input[type='address']").keypress(function (e) {
|
||||
if (e.which == 13)
|
||||
get_address_point($(this).val());
|
||||
});
|
||||
}
|
|
@ -45,27 +45,3 @@ function validateEmail(email) {
|
|||
function validateInput(input, regex) {
|
||||
return regex.test(input);
|
||||
}
|
||||
|
||||
function address_type_init() {
|
||||
|
||||
display = 'label';
|
||||
|
||||
var bloodhound = new Bloodhound({
|
||||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(display),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
|
||||
remote: {
|
||||
url: '/ban/search?request=%QUERY',
|
||||
wildcard: '%QUERY'
|
||||
}
|
||||
});
|
||||
bloodhound.initialize();
|
||||
|
||||
$("input[type='address']").typeahead({
|
||||
minLength: 1
|
||||
}, {
|
||||
display: display,
|
||||
source: bloodhound,
|
||||
limit: 5
|
||||
});
|
||||
}
|
|
@ -6,4 +6,15 @@ class Ban::SearchController < ApplicationController
|
|||
|acc, value| acc.push({label: value})
|
||||
}.to_json
|
||||
end
|
||||
|
||||
def get_address_point
|
||||
point = Carto::Geocodeur.convert_adresse_to_point(params[:request])
|
||||
|
||||
unless point.nil?
|
||||
lon = point.x.to_s
|
||||
lat = point.y.to_s
|
||||
end
|
||||
|
||||
render json: {lon: lon, lat: lat, zoom: '14', dossier_id: params[:dossier_id]}
|
||||
end
|
||||
end
|
|
@ -9,6 +9,8 @@
|
|||
\-
|
||||
%button#delete.btn.btn-sm.btn-danger{type:'button'} Supprimer
|
||||
|
||||
%span#search_by_address{style: 'margin-left: 20px'}
|
||||
%input.form-control{type: :address, placeholder: 'Rechercher une adresse'}
|
||||
%br
|
||||
%br
|
||||
#carte_page.row
|
||||
|
@ -24,7 +26,6 @@
|
|||
%h3.text-warning Cadastres
|
||||
%ul
|
||||
|
||||
|
||||
= form_tag(url_for({controller: :carte, action: :save, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
|
||||
%br
|
||||
%input{type: 'hidden', value: "#{@dossier.json_latlngs}", name: 'json_latlngs', id: 'json_latlngs'}
|
||||
|
|
|
@ -114,6 +114,7 @@ Rails.application.routes.draw do
|
|||
|
||||
namespace :ban do
|
||||
get 'search' => 'search#get'
|
||||
get 'address_point' => 'search#get_address_point'
|
||||
end
|
||||
|
||||
get 'backoffice' => 'backoffice#index'
|
||||
|
|
Loading…
Reference in a new issue