From: Tom Hughes Date: Thu, 25 Apr 2013 23:39:26 +0000 (+0100) Subject: Show OSM objects for Nominatim search results as map overlays X-Git-Tag: live~5608 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/b1308a87be1aaa0c6e5fd27e0635ef22b76e8081?ds=sidebyside Show OSM objects for Nominatim search results as map overlays --- diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 7c80b0108..519a805bb 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -58,6 +58,10 @@ $(document).ready(function () { map.setView(centre, data.zoom); } + if (data.type && data.id) { + addObjectToMap(data, true); + } + if (marker) { map.removeLayer(marker); } diff --git a/app/assets/javascripts/map.js.erb b/app/assets/javascripts/map.js.erb index 928575eb5..990093570 100644 --- a/app/assets/javascripts/map.js.erb +++ b/app/assets/javascripts/map.js.erb @@ -49,6 +49,7 @@ L.extend(L.Bounds.prototype, { L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>; var map; +var objectLayer; var layers = [ { @@ -128,11 +129,15 @@ function getUserIcon(url) { } function addObjectToMap(object, zoom, callback) { + if (objectLayer) { + map.removeLayer(objectLayer); + } + $.ajax({ url: OSM.apiUrl(object), dataType: "xml", success: function (xml) { - var layer = new L.OSM.DataLayer(xml, { + objectLayer = new L.OSM.DataLayer(xml, { style: { strokeColor: "blue", strokeWidth: 3, @@ -143,7 +148,7 @@ function addObjectToMap(object, zoom, callback) { } }); - var bounds = layer.getBounds(); + var bounds = objectLayer.getBounds(); if (zoom) { map.fitBounds(bounds); @@ -153,7 +158,7 @@ function addObjectToMap(object, zoom, callback) { callback(bounds); } - layer.addTo(map); + objectLayer.addTo(map); } }); } diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 7f5065b2f..b4c8e05b1 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -175,11 +175,14 @@ class GeocoderController < ApplicationController min_lat,max_lat,min_lon,max_lon = place.attributes["boundingbox"].to_s.split(",") prefix_name = t "geocoder.search_osm_nominatim.prefix.#{klass}.#{type}", :default => type.gsub("_", " ").capitalize prefix = t "geocoder.search_osm_nominatim.prefix_format", :name => prefix_name + object_type = place.attributes["osm_type"].to_s + object_id = place.attributes["osm_id"].to_s @results.push({:lat => lat, :lon => lon, :min_lat => min_lat, :max_lat => max_lat, :min_lon => min_lon, :max_lon => max_lon, - :prefix => prefix, :name => name}) + :prefix => prefix, :name => name, + :type => object_type, :id => object_id}) @more_params[:exclude].push(place.attributes["place_id"].to_s) end