@@ -4,18 +4,26 @@ var L = require('leaflet'),
4
4
module . exports = {
5
5
class : L . Class . extend ( {
6
6
options : {
7
- serviceUrl : 'https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/'
7
+ serviceUrl : 'https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/' ,
8
+ geocodingQueryParams : { } ,
9
+ reverseQueryParams : { }
8
10
} ,
9
11
10
12
initialize : function ( accessToken , options ) {
11
13
L . setOptions ( this , options ) ;
12
- this . _accessToken = accessToken ;
14
+ this . options . geocodingQueryParams . access_token = accessToken ;
15
+ this . options . reverseQueryParams . access_token = accessToken ;
13
16
} ,
14
17
15
18
geocode : function ( query , cb , context ) {
16
- Util . getJSON ( this . options . serviceUrl + encodeURIComponent ( query ) + '.json' , {
17
- access_token : this . _accessToken ,
18
- } , function ( data ) {
19
+ var params = this . options . geocodingQueryParams ;
20
+ if ( typeof params . proximity !== 'undefined'
21
+ && params . proximity . hasOwnProperty ( 'lat' )
22
+ && params . proximity . hasOwnProperty ( 'lng' ) )
23
+ {
24
+ params . proximity = params . proximity . lng + ',' + params . proximity . lat ;
25
+ }
26
+ Util . getJSON ( this . options . serviceUrl + encodeURIComponent ( query ) + '.json' , params , function ( data ) {
19
27
var results = [ ] ,
20
28
loc ,
21
29
latLng ,
@@ -24,7 +32,7 @@ module.exports = {
24
32
for ( var i = 0 ; i <= data . features . length - 1 ; i ++ ) {
25
33
loc = data . features [ i ] ;
26
34
latLng = L . latLng ( loc . center . reverse ( ) ) ;
27
- if ( loc . hasOwnProperty ( 'bbox' ) )
35
+ if ( loc . hasOwnProperty ( 'bbox' ) )
28
36
{
29
37
latLngBounds = L . latLngBounds ( L . latLng ( loc . bbox . slice ( 0 , 2 ) . reverse ( ) ) , L . latLng ( loc . bbox . slice ( 2 , 4 ) . reverse ( ) ) ) ;
30
38
}
@@ -49,9 +57,7 @@ module.exports = {
49
57
} ,
50
58
51
59
reverse : function ( location , scale , cb , context ) {
52
- Util . getJSON ( this . options . serviceUrl + encodeURIComponent ( location . lng ) + ',' + encodeURIComponent ( location . lat ) + '.json' , {
53
- access_token : this . _accessToken ,
54
- } , function ( data ) {
60
+ Util . getJSON ( this . options . serviceUrl + encodeURIComponent ( location . lng ) + ',' + encodeURIComponent ( location . lat ) + '.json' , this . options . reverseQueryParams , function ( data ) {
55
61
var results = [ ] ,
56
62
loc ,
57
63
latLng ,
@@ -60,7 +66,7 @@ module.exports = {
60
66
for ( var i = 0 ; i <= data . features . length - 1 ; i ++ ) {
61
67
loc = data . features [ i ] ;
62
68
latLng = L . latLng ( loc . center . reverse ( ) ) ;
63
- if ( loc . hasOwnProperty ( 'bbox' ) )
69
+ if ( loc . hasOwnProperty ( 'bbox' ) )
64
70
{
65
71
latLngBounds = L . latLngBounds ( L . latLng ( loc . bbox . slice ( 0 , 2 ) . reverse ( ) ) , L . latLng ( loc . bbox . slice ( 2 , 4 ) . reverse ( ) ) ) ;
66
72
}
0 commit comments