Skip to content

Commit 14348fc

Browse files
committed
Merge pull request #2 from mikemoraned/feature/optional-popup
0.1.1: add "markNames: true/false" option
2 parents 48ac355 + 6c7de0b commit 14348fc

5 files changed

Lines changed: 16 additions & 9 deletions

File tree

L.Control.Geonames.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

L.Control.Geonames.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ var control = L.control.geonames({
6060
workingClass: 'fa-spin', // class for search underway
6161
featureClasses: ['A', 'H', 'L', 'P', 'R', 'T', 'U', 'V'], // feature classes to search against. See: http://www.geonames.org/export/codes.html
6262
baseQuery: 'isNameRequired=true', // The core query sent to GeoNames, later combined with other parameters above
63-
position: 'topleft'
63+
position: 'topleft',
64+
markNames: true // show a marker at the location of each geoname found, with an associated popup which shows the name
6465
});
6566
map.addControl(control);
6667
```

bower.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "Leaflet.Geonames",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"homepage": "https://github.com/consbio/Leaflet.Geonames",
55
"authors": [
6-
"Brendan Ward <bcward@consbio.org>"
6+
"Brendan Ward <bcward@consbio.org>",
7+
"Mike Moran <mike@houseofmoran.com>"
78
],
89
"description": "GeoNames geocoding search control for Leaflet",
910
"main": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "leaflet-geonames",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Geonames Geocoding Search Control for Leaflet",
55
"homepage": "http://github.com/consbio/Leaflet.Geonames",
66
"author": {

0 commit comments

Comments
 (0)