Skip to content

Commit

Permalink
Merge pull request #3754 from kepta/geocoder
Browse files Browse the repository at this point in the history
Add a pluggable geocoder
  • Loading branch information
bhousel authored Jan 13, 2017
2 parents 3befa2d + 781f454 commit 9aaacec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import serviceWikipedia from './wikipedia';

export var services = {
mapillary: serviceMapillary,
nominatim: serviceNominatim,
geocoder: serviceNominatim,
osm: serviceOsm,
taginfo: serviceTaginfo,
wikidata: serviceWikidata,
Expand Down
5 changes: 5 additions & 0 deletions modules/services/nominatim.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export default {
callback(null, result.address.country_code);
}
);
},

search: function (val, callback) {
var searchVal = encodeURIComponent(val);
d3.json('https://nominatim.openstreetmap.org/search/' + searchVal + '?limit=10&format=json', callback);
}

};
9 changes: 5 additions & 4 deletions modules/ui/feature_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { geoExtent, geoChooseEdge } from '../geo/index';
import { modeSelect } from '../modes/index';
import { osmEntity } from '../osm/index';
import { svgIcon } from '../svg/index';
import { services } from '../services/index';

import {
utilDisplayName,
utilDisplayType,
Expand Down Expand Up @@ -181,7 +183,7 @@ export function uiFeatureList(context) {
.data([0])
.enter().append('button')
.attr('class', 'geocode-item')
.on('click', geocode)
.on('click', geocoderSearch)
.append('div')
.attr('class', 'label')
.append('span')
Expand Down Expand Up @@ -270,9 +272,8 @@ export function uiFeatureList(context) {
}


function geocode() {
var searchVal = encodeURIComponent(search.property('value'));
d3.json('https://nominatim.openstreetmap.org/search/' + searchVal + '?limit=10&format=json', function(err, resp) {
function geocoderSearch() {
services.geocoder.search(search.property('value'), function (err, resp) {
geocodeResults = resp || [];
drawList();
});
Expand Down

0 comments on commit 9aaacec

Please sign in to comment.