@@ -11,7 +11,8 @@ L.Control.Geonames = L.Control.extend({
1111 workingClass : 'fa-spin' , //class for search underway
1212 featureClasses : [ 'A' , 'H' , 'L' , 'P' , 'R' , 'T' , 'U' , 'V' ] , //feature classes to search against. See: http://www.geonames.org/export/codes.html
1313 baseQuery : 'isNameRequired=true' , //The core query sent to GeoNames, later combined with other parameters above
14- position : 'topleft'
14+ position : 'topleft' ,
15+ markNames : true //show a marker at the location of each geoname found, with an associated popup which shows the name
1516 } ,
1617 onAdd : function ( ) {
1718 this . _container = L . DomUtil . create ( 'div' , 'leaflet-geonames-search leaflet-bar' ) ;
@@ -107,6 +108,7 @@ L.Control.Geonames = L.Control.extend({
107108 L . DomUtil . addClass ( this . _resultsList , 'hasResults' ) ;
108109 this . _hasResults = true ;
109110 var li ;
111+ var zoomLevel = this . options . zoomLevel || this . _map . getMaxZoom ( ) ;
110112 response . geonames . forEach ( function ( geoname ) {
111113 li = L . DomUtil . create ( 'li' , '' , this . _resultsList ) ;
112114 li . innerHTML = this . _getName ( geoname ) ;
@@ -117,9 +119,12 @@ L.Control.Geonames = L.Control.extend({
117119 this . _map . removeLayer ( this . _marker ) ;
118120 this . _marker = null ;
119121 }
120- this . _marker = L . marker ( [ lat , lon ] ) . addTo ( this . _map ) . bindPopup ( this . _getName ( geoname ) ) ;
121- this . _map . setView ( [ lat , lon ] , this . options . zoomLevel || this . _map . getMaxZoom ( ) , false ) ;
122- this . _marker . openPopup ( ) ;
122+ this . _map . setView ( [ lat , lon ] , zoomLevel , false ) ;
123+ if ( this . options . markNames ) {
124+ this . _marker = L . marker ( [ lat , lon ] ) ;
125+ this . _marker . addTo ( this . _map ) . bindPopup ( this . _getName ( geoname ) ) ;
126+ this . _marker . openPopup ( ) ;
127+ }
123128 } , this ) ;
124129 } , this ) ;
125130 }
0 commit comments