Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pluggable geocoder in feature_list.js #3711

Closed
3 tasks
sweco-semtne opened this issue Jan 2, 2017 · 5 comments · Fixed by #3754
Closed
3 tasks

Pluggable geocoder in feature_list.js #3711

sweco-semtne opened this issue Jan 2, 2017 · 5 comments · Fixed by #3754
Assignees
Labels
new-feature A new feature for iD

Comments

@sweco-semtne
Copy link

sweco-semtne commented Jan 2, 2017

We are using Pelias as a geocoder over openstreetmap data and would like to extract the functionality in feature_list.js to be able to use a pluggable geocoder instead of directly calling nominatim.
I'm thinking that it could be a service that can be setup in the context in the same way as the nominatim service.

A simple API like the one below could be enough

function geocode(searchTerm, callback) {}

The simplest way to do introduce this would be to:

  • Introduce new service geocode with the api above (model the response after Nominatim)
  • Import service in feature_list.js
  • Change the eventlistener in feature_list.js to call imported service

I know that nominatim is more or less the standard but it would be nice to be pluggable in this regard and I don't think it would be intrusive to the users in any way. The default service would of course be Nominatim.

@bhousel
Copy link
Member

bhousel commented Jan 2, 2017

Good suggestion, I agree...

@bhousel bhousel added the new-feature A new feature for iD label Jan 2, 2017
@sweco-semtne
Copy link
Author

Could the current nominatim service be used if we add a function geocode?
In feature_list.js

 import { services } from '../services/index';
 ...
 function geocode() {
            services.nominatim.geocode(search.property('value'), function(resp) {
                geocodeResults = resp;
                drawList();
            });
        }

And in nominatim.js

var endpoint = 'https://nominatim.openstreetmap.org/', 
   nominatimCache;

   ...
   geocode: function(value, callback) {
        var searchVal = encodeURIComponent(value);
        d3.json(endpoint + 'search/' + searchVal + '?limit=10&format=json', function(err, resp) {
            callback(resp || []);
        });
    }

@sweco-semtne
Copy link
Author

Btw, what's the correct/best way of making a service pluggable for the developer without modifying the library code?

@bhousel
Copy link
Member

bhousel commented Jan 5, 2017

Everything in the services module is designed to be swappable at runtime. See API.md#services

So after we fix the issues in this ticket, it should ideally be as easy as a line like this before your page initializes the iD context object.

iD.services.geocoder = replacementService;

@sweco-semtne
Copy link
Author

Great! And I just want to thank you for the great work you and everyone else that has contributed to iD has done!

@bhousel bhousel added the wip Work in progress label Jan 13, 2017
@bhousel bhousel removed the wip Work in progress label Jan 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature A new feature for iD
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants