-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HERE as a provider for geocoding and reverse geocoding
- Loading branch information
Showing
5 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "leaflet-control-geocoder", | ||
"version": "1.3.2", | ||
"description": "Extendable geocoder with builtin support for Nominatim, Bing, Google, Mapbox, Photon, What3Words, MapQuest, Mapzen", | ||
"description": "Extendable geocoder with builtin support for Nominatim, Bing, Google, Mapbox, Photon, What3Words, MapQuest, Mapzen, HERE", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"prepublish": "sh ./scripts/build.sh", | ||
|
@@ -22,7 +22,8 @@ | |
"photon", | ||
"what3words", | ||
"mapquest", | ||
"mapzen" | ||
"mapzen", | ||
"here" | ||
], | ||
"author": "Per Liedman <[email protected]>", | ||
"license": "BSD-2-Clause", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
var L = require('leaflet'), | ||
Util = require('../util'); | ||
|
||
module.exports = { | ||
class: L.Class.extend({ | ||
options: { | ||
geocodeUrl: 'http://geocoder.api.here.com/6.2/geocode.json', | ||
reverseGeocodeUrl: 'http://reverse.geocoder.api.here.com/6.2/reversegeocode.json', | ||
app_id: '<insert your app_id here>', | ||
app_code: '<insert your app_code here>', | ||
geocodingQueryParams: {}, | ||
reverseQueryParams: {} | ||
}, | ||
|
||
initialize: function(options) { | ||
L.setOptions(this, options); | ||
}, | ||
|
||
geocode: function(query, cb, context) { | ||
var params = { | ||
searchtext: query, | ||
gen: 9, | ||
app_id: this.options.app_id, | ||
app_code: this.options.app_code, | ||
jsonattributes: 1 | ||
}; | ||
params = L.Util.extend(params, this.options.geocodingQueryParams); | ||
this.getJSON(this.options.geocodeUrl, params, cb, context); | ||
}, | ||
|
||
reverse: function(location, scale, cb, context) { | ||
var params = { | ||
prox: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng), | ||
mode: 'retrieveAddresses', | ||
app_id: this.options.app_id, | ||
app_code: this.options.app_code, | ||
gen: 9, | ||
jsonattributes: 1 | ||
}; | ||
params = L.Util.extend(params, this.options.reverseQueryParams); | ||
this.getJSON(this.options.reverseGeocodeUrl, params, cb, context); | ||
}, | ||
|
||
getJSON: function(url, params, cb, context) { | ||
Util.getJSON(url, params, function(data) { | ||
var results = [], | ||
loc, | ||
latLng, | ||
latLngBounds; | ||
if (data.response.view && data.response.view.length) { | ||
for (var i = 0; i <= data.response.view[0].result.length - 1; i++) { | ||
loc = data.response.view[0].result[i].location; | ||
latLng = L.latLng(loc.displayPosition.latitude, loc.displayPosition.longitude); | ||
latLngBounds = L.latLngBounds(L.latLng(loc.mapView.topLeft.latitude, loc.mapView.topLeft.longitude), L.latLng(loc.mapView.bottomRight.latitude, loc.mapView.bottomRight.longitude)); | ||
results[i] = { | ||
name: loc.address.label, | ||
bbox: latLngBounds, | ||
center: latLng | ||
}; | ||
} | ||
} | ||
cb.call(context, results); | ||
}) | ||
} | ||
}), | ||
|
||
factory: function(options) { | ||
return new L.Control.Geocoder.HERE(options); | ||
} | ||
}; |
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