Created
February 6, 2018 14:56
-
-
Save jelmervdl/7259cc07954993d73284dc6504b73ea3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PDOKGeocoder = L.Class.extend({ | |
options: { | |
suggestUrl: 'https://geodata.nationaalgeoregister.nl/locatieserver/v3/suggest', | |
lookupUrl: 'https://geodata.nationaalgeoregister.nl/locatieserver/v3/lookup', | |
geocodingQueryParams: { | |
wt: 'json' | |
} | |
}, | |
initialize: function(options) { | |
L.Util.setOptions(this, options); | |
}, | |
geocode: function(value, callback, context) { | |
var query = L.Util.extend({}, this.options.geocodingQueryParams, {'q': value}); | |
fetchJSON(this.options.suggestUrl + L.Util.getParamString(query), function(response) { | |
var results = response.response.docs.map(function(doc) { | |
return { | |
id: doc.id, | |
name: doc.weergavenaam, | |
}; | |
}); | |
callback.call(context, results); | |
}); | |
}, | |
lookup: function(id, callback, context) { | |
fetchJSON(this.options.lookupUrl + L.Util.getParamString({id: id}), function(response) { | |
var wkt = response.response.docs[0].centroide_ll; | |
var match = wkt.match(/POINT\((\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)\)/); | |
callback.call(context, [parseFloat(match[2], 10), parseFloat(match[1], 10)]); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment