Newer
Older
Sébastien DA ROCHA
committed
latLngBounds = L.latLngBounds(latLng, latLng);
}
results.push({
name: loc.formatted,
bbox: latLngBounds,
center: latLng
});
}
}
cb.call(context, results);
});
},

Timothee P
committed
suggest: function (query, cb, context) {
Sébastien DA ROCHA
committed
return this.geocode(query, cb, context);
},

Timothee P
committed
reverse: function (location, scale, cb, context) {
Sébastien DA ROCHA
committed
var params = {
key: this._accessToken,
q: [location.lat, location.lng].join(',')
};
params = L.extend(params, this.options.reverseQueryParams);

Timothee P
committed
getJSON(this.options.serviceUrl, params, function (data) {
Sébastien DA ROCHA
committed
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
var results = [],
latLng,
latLngBounds,
loc;
if (data.results && data.results.length) {
for (var i = 0; i < data.results.length; i++) {
loc = data.results[i];
latLng = L.latLng(loc.geometry);
if (loc.annotations && loc.annotations.bounds) {
latLngBounds = L.latLngBounds(
L.latLng(loc.annotations.bounds.northeast),
L.latLng(loc.annotations.bounds.southwest)
);
} else {
latLngBounds = L.latLngBounds(latLng, latLng);
}
results.push({
name: loc.formatted,
bbox: latLngBounds,
center: latLng
});
}
}
cb.call(context, results);
});
}
});
function opencage(apiKey, options) {
return new OpenCage(apiKey, options);
}
var Pelias = L.Class.extend({
options: {
serviceUrl: 'https://api.geocode.earth/v1',
geocodingQueryParams: {},
reverseQueryParams: {}
},

Timothee P
committed
initialize: function (apiKey, options) {
Sébastien DA ROCHA
committed
L.Util.setOptions(this, options);
this._apiKey = apiKey;
this._lastSuggest = 0;
},

Timothee P
committed
geocode: function (query, cb, context) {
Sébastien DA ROCHA
committed
var _this = this;
getJSON(
this.options.serviceUrl + '/search',
L.extend(
{
api_key: this._apiKey,
text: query
},
this.options.geocodingQueryParams
),

Timothee P
committed
function (data) {
Sébastien DA ROCHA
committed
cb.call(context, _this._parseResults(data, 'bbox'));
}
);
},

Timothee P
committed
suggest: function (query, cb, context) {
Sébastien DA ROCHA
committed
var _this = this;
getJSON(
this.options.serviceUrl + '/autocomplete',
L.extend(
{
api_key: this._apiKey,
text: query
},
this.options.geocodingQueryParams
),

Timothee P
committed
L.bind(function (data) {
Sébastien DA ROCHA
committed
if (data.geocoding.timestamp > this._lastSuggest) {
this._lastSuggest = data.geocoding.timestamp;
cb.call(context, _this._parseResults(data, 'bbox'));
}
}, this)
);
},

Timothee P
committed
reverse: function (location, scale, cb, context) {
Sébastien DA ROCHA
committed
var _this = this;
getJSON(
this.options.serviceUrl + '/reverse',
L.extend(
{
api_key: this._apiKey,
'point.lat': location.lat,
'point.lon': location.lng
},
this.options.reverseQueryParams
),

Timothee P
committed
function (data) {
Sébastien DA ROCHA
committed
cb.call(context, _this._parseResults(data, 'bounds'));
}
);
},

Timothee P
committed
_parseResults: function (data, bboxname) {
Sébastien DA ROCHA
committed
var results = [];
L.geoJson(data, {

Timothee P
committed
pointToLayer: function (feature, latlng) {
Sébastien DA ROCHA
committed
return L.circleMarker(latlng);
},

Timothee P
committed
onEachFeature: function (feature, layer) {
Sébastien DA ROCHA
committed
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
var result = {},
bbox,
center;
if (layer.getBounds) {
bbox = layer.getBounds();
center = bbox.getCenter();
} else if (layer.feature.bbox) {
center = layer.getLatLng();
bbox = L.latLngBounds(
L.GeoJSON.coordsToLatLng(layer.feature.bbox.slice(0, 2)),
L.GeoJSON.coordsToLatLng(layer.feature.bbox.slice(2, 4))
);
} else {
center = layer.getLatLng();
bbox = L.latLngBounds(center, center);
}
result.name = layer.feature.properties.label;
result.center = center;
result[bboxname] = bbox;
result.properties = layer.feature.properties;
results.push(result);
}
});
return results;
}
});
function pelias(apiKey, options) {
return new Pelias(apiKey, options);
}
var GeocodeEarth = Pelias;
var geocodeEarth = pelias;
var Mapzen = Pelias; // r.i.p.
var mapzen = pelias;
var Openrouteservice = Mapzen.extend({
options: {
serviceUrl: 'https://api.openrouteservice.org/geocode'
}
});
function openrouteservice(apiKey, options) {
return new Openrouteservice(apiKey, options);
}
var Photon = L.Class.extend({
options: {
serviceUrl: 'https://photon.komoot.de/api/',
reverseUrl: 'https://photon.komoot.de/reverse/',
nameProperties: ['name', 'street', 'suburb', 'hamlet', 'town', 'city', 'state', 'country']
},

Timothee P
committed
initialize: function (options) {
Sébastien DA ROCHA
committed
L.setOptions(this, options);
},

Timothee P
committed
geocode: function (query, cb, context) {
Sébastien DA ROCHA
committed
var params = L.extend(
{
q: query
},
this.options.geocodingQueryParams
);
getJSON(
this.options.serviceUrl,
params,

Timothee P
committed
L.bind(function (data) {
Sébastien DA ROCHA
committed
cb.call(context, this._decodeFeatures(data));
}, this)
);
},

Timothee P
committed
suggest: function (query, cb, context) {
Sébastien DA ROCHA
committed
return this.geocode(query, cb, context);
},

Timothee P
committed
reverse: function (latLng, scale, cb, context) {
Sébastien DA ROCHA
committed
var params = L.extend(
{
lat: latLng.lat,
lon: latLng.lng
},
this.options.reverseQueryParams
);
getJSON(
this.options.reverseUrl,
params,

Timothee P
committed
L.bind(function (data) {
Sébastien DA ROCHA
committed
cb.call(context, this._decodeFeatures(data));
}, this)
);
},

Timothee P
committed
_decodeFeatures: function (data) {
Sébastien DA ROCHA
committed
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
var results = [],
i,
f,
c,
latLng,
extent,
bbox;
if (data && data.features) {
for (i = 0; i < data.features.length; i++) {
f = data.features[i];
c = f.geometry.coordinates;
latLng = L.latLng(c[1], c[0]);
extent = f.properties.extent;
if (extent) {
bbox = L.latLngBounds([extent[1], extent[0]], [extent[3], extent[2]]);
} else {
bbox = L.latLngBounds(latLng, latLng);
}
results.push({
name: this._decodeFeatureName(f),
html: this.options.htmlTemplate ? this.options.htmlTemplate(f) : undefined,
center: latLng,
bbox: bbox,
properties: f.properties
});
}
}
return results;
},

Timothee P
committed
_decodeFeatureName: function (f) {
Sébastien DA ROCHA
committed
return (this.options.nameProperties || [])

Timothee P
committed
.map(function (p) {
Sébastien DA ROCHA
committed
return f.properties[p];
})

Timothee P
committed
.filter(function (v) {
Sébastien DA ROCHA
committed
return !!v;
})
.join(', ');
}
});
function photon(options) {
return new Photon(options);
}
const TYPE_LABEL = {

Timothee P
committed
housenumber: 'Numéro',
street: 'Rue',
locality: 'Lieux-dit',
municipality: 'Commune',
Sébastien DA ROCHA
committed
};
var AddOk = L.Class.extend({

Timothee P
committed
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
options: {
serviceUrl: 'https://api-adresse.data.gouv.fr',
limit: 5,
htmlTemplate: function (r) {
var parts = [];
/* some available classes:
leaflet-control-geocoder-address-detail
leaflet-control-geocoder-address-context
*/
parts.push('<span class="leaflet-control-geocoder-address-item"> {label} </span>({type})<span>' + '</span>');
parts.push('<span class="' + (parts.length > 0 ? 'leaflet-control-geocoder-address-detail' : '') +
'">{context}</span>');
return template(parts.join('<br/>'), r);
}
},
initialize: function (options) {
L.setOptions(this, options);
},
geocode: function (query, cb, context) {
var params = L.extend({
q: query,
limit: this.options.limit
}, this.options.geocodingQueryParams);
var that = this;
getJSON(this.options.serviceUrl + '/search/', params, function (data) {
var results = [],
i,
f,
c,
latLng,
extent,
bbox;
if (data && data.features) {
for (i = 0; i < data.features.length; i++) {
f = data.features[i];
c = f.geometry.coordinates;
latLng = L.latLng(c[1], c[0]);
extent = f.properties.extent;
if (extent) {
bbox = L.latLngBounds([extent[1], extent[0]], [extent[3], extent[2]]);
} else {
bbox = L.latLngBounds(latLng, latLng);
}
// Translate the type in french
if (f.properties.type) {
f.properties.type = TYPE_LABEL[f.properties.type];
}
results.push({
name: f.properties.name,
center: latLng,
bbox: bbox,
html: that.options.htmlTemplate ?
that.options.htmlTemplate(f.properties)
: undefined
});
Sébastien DA ROCHA
committed
}

Timothee P
committed
}
Sébastien DA ROCHA
committed

Timothee P
committed
cb.call(context, results);
});
},
Sébastien DA ROCHA
committed

Timothee P
committed
suggest: function (query, cb, context) {
return this.geocode(query, cb, context);
},
Sébastien DA ROCHA
committed

Timothee P
committed
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
reverse: function (location, scale, cb, context) {
var params = L.extend({
lat: location.lat,
lon: location.lng
}, this.options.reverseQueryParams);
var that = this;
getJSON(this.options.serviceUrl + '/reverse/', params, function (data) {
var results = [],
i,
f,
c,
latLng,
extent,
bbox;
if (data && data.features) {
for (i = 0; i < data.features.length; i++) {
f = data.features[i];
c = f.geometry.coordinates;
latLng = L.latLng(c[1], c[0]);
extent = f.properties.extent;
if (extent) {
bbox = L.latLngBounds([extent[1], extent[0]], [extent[3], extent[2]]);
} else {
bbox = L.latLngBounds(latLng, latLng);
}
results.push({
name: f.properties.name,
center: latLng,
bbox: bbox,
html: that.options.htmlTemplate ?
that.options.htmlTemplate(f.properties)
: undefined
});
}
}
cb.call(context, results);
});
}
Sébastien DA ROCHA
committed
});
function addok(key) {

Timothee P
committed
return new AddOk(key);
Sébastien DA ROCHA
committed
}
var What3Words = L.Class.extend({
options: {
serviceUrl: 'https://api.what3words.com/v2/'
},

Timothee P
committed
initialize: function (accessToken) {
Sébastien DA ROCHA
committed
this._accessToken = accessToken;
},

Timothee P
committed
geocode: function (query, cb, context) {
Sébastien DA ROCHA
committed
//get three words and make a dot based string
getJSON(
this.options.serviceUrl + 'forward',
{
key: this._accessToken,
addr: query.split(/\s+/).join('.')
},

Timothee P
committed
function (data) {
Sébastien DA ROCHA
committed
var results = [],
latLng,
latLngBounds;
if (data.geometry) {
latLng = L.latLng(data.geometry['lat'], data.geometry['lng']);
latLngBounds = L.latLngBounds(latLng, latLng);
results[0] = {
name: data.words,
bbox: latLngBounds,
center: latLng
};
}
cb.call(context, results);
}
);
},

Timothee P
committed
suggest: function (query, cb, context) {
Sébastien DA ROCHA
committed
return this.geocode(query, cb, context);
},

Timothee P
committed
reverse: function (location, scale, cb, context) {
Sébastien DA ROCHA
committed
getJSON(
this.options.serviceUrl + 'reverse',
{
key: this._accessToken,
coords: [location.lat, location.lng].join(',')
},

Timothee P
committed
function (data) {
Sébastien DA ROCHA
committed
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
var results = [],
latLng,
latLngBounds;
if (data.status.status == 200) {
latLng = L.latLng(data.geometry['lat'], data.geometry['lng']);
latLngBounds = L.latLngBounds(latLng, latLng);
results[0] = {
name: data.words,
bbox: latLngBounds,
center: latLng
};
}
cb.call(context, results);
}
);
}
});
function what3words(accessToken) {
return new What3Words(accessToken);
}
var geocoders = /*#__PURE__*/Object.freeze({
__proto__: null,
ArcGis: ArcGis,
arcgis: arcgis,
Bing: Bing,
bing: bing,
Google: Google,
google: google,
HERE: HERE,
here: here,
LatLng: LatLng,
latLng: latLng,
Mapbox: Mapbox,
mapbox: mapbox,
MapQuest: MapQuest,
mapQuest: mapQuest,
Neutrino: Neutrino,
neutrino: neutrino,
Nominatim: Nominatim,
nominatim: nominatim,
OpenLocationCode: OpenLocationCode,
openLocationCode: openLocationCode,
OpenCage: OpenCage,
opencage: opencage,
Pelias: Pelias,
pelias: pelias,
GeocodeEarth: GeocodeEarth,
geocodeEarth: geocodeEarth,
Mapzen: Mapzen,
mapzen: mapzen,
Openrouteservice: Openrouteservice,
openrouteservice: openrouteservice,
Photon: Photon,
photon: photon,
AddOk: AddOk,
addok: addok,
What3Words: What3Words,
what3words: what3words
});
var Geocoder = L.Control.extend({
options: {
showUniqueResult: true,
showResultIcons: false,
collapsed: true,
expand: 'touch', // options: touch, click, anythingelse
position: 'topright',
placeholder: 'Search...',
errorMessage: 'Nothing found.',
iconLabel: 'Initiate a new search',
queryMinLength: 1,
suggestMinLength: 3,
suggestTimeout: 250,
defaultMarkGeocode: true
},
includes: L.Evented.prototype || L.Mixin.Events,

Timothee P
committed
initialize: function (options) {
Sébastien DA ROCHA
committed
L.Util.setOptions(this, options);
if (!this.options.geocoder) {
this.options.geocoder = new Nominatim();
}
this._requestCount = 0;
},

Timothee P
committed
addThrobberClass: function () {
Sébastien DA ROCHA
committed
L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-throbber');
},

Timothee P
committed
removeThrobberClass: function () {
Sébastien DA ROCHA
committed
L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-throbber');
},

Timothee P
committed
onAdd: function (map) {
Sébastien DA ROCHA
committed
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
var className = 'leaflet-control-geocoder',
container = L.DomUtil.create('div', className + ' leaflet-bar'),
icon = L.DomUtil.create('button', className + '-icon', container),
form = (this._form = L.DomUtil.create('div', className + '-form', container)),
input;
this._map = map;
this._container = container;
icon.innerHTML = ' ';
icon.type = 'button';
icon.setAttribute('aria-label', this.options.iconLabel);
input = this._input = L.DomUtil.create('input', '', form);
input.type = 'text';
input.value = this.options.query || '';
input.placeholder = this.options.placeholder;
L.DomEvent.disableClickPropagation(input);
this._errorElement = L.DomUtil.create('div', className + '-form-no-error', container);
this._errorElement.innerHTML = this.options.errorMessage;
this._alts = L.DomUtil.create(
'ul',
className + '-alternatives leaflet-control-geocoder-alternatives-minimized',
container
);
L.DomEvent.disableClickPropagation(this._alts);
L.DomEvent.addListener(input, 'keydown', this._keydown, this);
if (this.options.geocoder.suggest) {
L.DomEvent.addListener(input, 'input', this._change, this);
}
L.DomEvent.addListener(
input,
'blur',

Timothee P
committed
function () {
Sébastien DA ROCHA
committed
if (this.options.collapsed && !this._preventBlurCollapse) {
this._collapse();
}
this._preventBlurCollapse = false;
},
this
);
if (this.options.collapsed) {
if (this.options.expand === 'click') {
L.DomEvent.addListener(
container,
'click',

Timothee P
committed
function (e) {
Sébastien DA ROCHA
committed
if (e.button === 0 && e.detail !== 2) {
this._toggle();
}
},
this
);
} else if (this.options.expand === 'touch') {
L.DomEvent.addListener(
container,
L.Browser.touch ? 'touchstart mousedown' : 'mousedown',

Timothee P
committed
function (e) {
Sébastien DA ROCHA
committed
this._toggle();
e.preventDefault(); // mobile: clicking focuses the icon, so UI expands and immediately collapses
e.stopPropagation();
},
this
);
} else {
L.DomEvent.addListener(container, 'mouseover', this._expand, this);
L.DomEvent.addListener(container, 'mouseout', this._collapse, this);
this._map.on('movestart', this._collapse, this);
}
} else {
this._expand();
if (L.Browser.touch) {
L.DomEvent.addListener(
container,
'touchstart',

Timothee P
committed
function () {
Sébastien DA ROCHA
committed
this._geocode();
},
this
);
} else {
L.DomEvent.addListener(
container,
'click',

Timothee P
committed
function () {
Sébastien DA ROCHA
committed
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
this._geocode();
},
this
);
}
}
if (this.options.defaultMarkGeocode) {
this.on('markgeocode', this.markGeocode, this);
}
this.on('startgeocode', this.addThrobberClass, this);
this.on('finishgeocode', this.removeThrobberClass, this);
this.on('startsuggest', this.addThrobberClass, this);
this.on('finishsuggest', this.removeThrobberClass, this);
L.DomEvent.disableClickPropagation(container);
return container;
},

Timothee P
committed
setQuery: function (string) {
Sébastien DA ROCHA
committed
this._input.value = string;
return this;
},

Timothee P
committed
_geocodeResult: function (results, suggest) {
Sébastien DA ROCHA
committed
if (!suggest && this.options.showUniqueResult && results.length === 1) {
this._geocodeResultSelected(results[0]);
} else if (results.length > 0) {
this._alts.innerHTML = '';
this._results = results;
L.DomUtil.removeClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized');
L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-options-open');
for (var i = 0; i < results.length; i++) {
this._alts.appendChild(this._createAlt(results[i], i));
}
} else {
L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-options-error');
L.DomUtil.addClass(this._errorElement, 'leaflet-control-geocoder-error');
}
},

Timothee P
committed
markGeocode: function (result) {
Sébastien DA ROCHA
committed
result = result.geocode || result;
this._map.fitBounds(result.bbox);
if (this._geocodeMarker) {
this._map.removeLayer(this._geocodeMarker);
}

Timothee P
committed
const CustomIcon = L.Icon.extend({ //* recreate leaflet default icon, because not working out of box, reason not found
options: {
iconUrl: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAABkAAAApCAYAAADAk4LOAAAFgUlEQVR4Aa1XA5BjWRTN2oW17d3YaZtr2962HUzbDNpjszW24mRt28p47v7zq/bXZtrp/lWnXr337j3nPCe85NcypgSFdugCpW5YoDAMRaIMqRi6aKq5E3YqDQO3qAwjVWrD8Ncq/RBpykd8oZUb/kaJutow8r1aP9II0WmLKLIsJyv1w/kqw9Ch2MYdB++12Onxee/QMwvf4/Dk/Lfp/i4nxTXtOoQ4pW5Aj7wpici1A9erdAN2OH64x8OSP9j3Ft3b7aWkTg/Fm91si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I9cxZQWgiSJelKnwBElKYtDOb2MFbhmUigbReQBV0Cg4+qMXSxXSyGUn4UbF8l+7qdSGnTC0XLCmahIgUHLhLOhpVCtw4CzYXvLQWQbJNmxoCsOKAxSgBJno75avolkRw8iIAFcsdc02e9iyCd8tHwmeSSoKTowIgvscSGZUOA7PuCN5b2BX9mQM7S0wYhMNU74zgsPBj3HU7wguAfnxxjFQGBE6pwN+GjME9zHY7zGp8wVxMShYX9NXvEWD3HbwJf4giO4CFIQxXScH1/TM+04kkBiAAAAAElFTkSuQmCC",
iconSize: [25, 41],
iconAnchor: [12.5, 41],
popupAnchor: [0, -40]
}
});
const icon = new CustomIcon()
this._geocodeMarker = new L.Marker(result.center, { icon })
Sébastien DA ROCHA
committed
.bindPopup(result.html || result.name)
.addTo(this._map)
.openPopup();
return this;
},

Timothee P
committed
_geocode: function (suggest) {
Sébastien DA ROCHA
committed
var value = this._input.value;
if (!suggest && value.length < this.options.queryMinLength) {
return;
}
var requestCount = ++this._requestCount,
mode = suggest ? 'suggest' : 'geocode',
eventData = { input: value };
this._lastGeocode = value;
if (!suggest) {
this._clearResults();
}
this.fire('start' + mode, eventData);
this.options.geocoder[mode](
value,

Timothee P
committed
function (results) {
Sébastien DA ROCHA
committed
if (requestCount === this._requestCount) {
eventData.results = results;
this.fire('finish' + mode, eventData);
this._geocodeResult(results, suggest);
}
},
this
);
},

Timothee P
committed
_geocodeResultSelected: function (result) {
Sébastien DA ROCHA
committed
this.fire('markgeocode', { geocode: result });
},

Timothee P
committed
_toggle: function () {
Sébastien DA ROCHA
committed
if (L.DomUtil.hasClass(this._container, 'leaflet-control-geocoder-expanded')) {
this._collapse();
} else {
this._expand();
}
},

Timothee P
committed
_expand: function () {
Sébastien DA ROCHA
committed
L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-expanded');
this._input.select();
this.fire('expand');
},

Timothee P
committed
_collapse: function () {
Sébastien DA ROCHA
committed
L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-expanded');
L.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized');
L.DomUtil.removeClass(this._errorElement, 'leaflet-control-geocoder-error');
L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-options-open');
L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-options-error');
this._input.blur(); // mobile: keyboard shouldn't stay expanded
this.fire('collapse');
},

Timothee P
committed
_clearResults: function () {
Sébastien DA ROCHA
committed
L.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized');
this._selection = null;
L.DomUtil.removeClass(this._errorElement, 'leaflet-control-geocoder-error');
L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-options-open');
L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-options-error');
},

Timothee P
committed
_createAlt: function (result, index) {
Sébastien DA ROCHA
committed
var li = L.DomUtil.create('li', ''),
a = L.DomUtil.create('a', '', li),
icon = this.options.showResultIcons && result.icon ? L.DomUtil.create('img', '', a) : null,
text = result.html ? undefined : document.createTextNode(result.name),
mouseDownHandler = function mouseDownHandler(e) {
// In some browsers, a click will fire on the map if the control is
// collapsed directly after mousedown. To work around this, we
// wait until the click is completed, and _then_ collapse the
// control. Messy, but this is the workaround I could come up with
// for #142.
this._preventBlurCollapse = true;
L.DomEvent.stop(e);
this._geocodeResultSelected(result);
L.DomEvent.on(
li,
'click touchend',

Timothee P
committed
function () {
Sébastien DA ROCHA
committed
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
if (this.options.collapsed) {
this._collapse();
} else {
this._clearResults();
}
},
this
);
};
if (icon) {
icon.src = result.icon;
}
li.setAttribute('data-result-index', index);
if (result.html) {
a.innerHTML = a.innerHTML + result.html;
} else {
a.appendChild(text);
}
// Use mousedown and not click, since click will fire _after_ blur,
// causing the control to have collapsed and removed the items
// before the click can fire.
L.DomEvent.addListener(li, 'mousedown touchstart', mouseDownHandler, this);
return li;
},

Timothee P
committed
_keydown: function (e) {
Sébastien DA ROCHA
committed
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
var _this = this,
select = function select(dir) {
if (_this._selection) {
L.DomUtil.removeClass(_this._selection, 'leaflet-control-geocoder-selected');
_this._selection = _this._selection[dir > 0 ? 'nextSibling' : 'previousSibling'];
}
if (!_this._selection) {
_this._selection = _this._alts[dir > 0 ? 'firstChild' : 'lastChild'];
}
if (_this._selection) {
L.DomUtil.addClass(_this._selection, 'leaflet-control-geocoder-selected');
}
};
switch (e.keyCode) {
// Escape
case 27:
if (this.options.collapsed) {
this._collapse();
} else {
this._clearResults();
}
break;
// Up
case 38:
select(-1);
break;
// Up
case 40:
select(1);
break;
// Enter
case 13:
if (this._selection) {
var index = parseInt(this._selection.getAttribute('data-result-index'), 10);
this._geocodeResultSelected(this._results[index]);
this._clearResults();
} else {
this._geocode();
}
break;
default:
return;
}
L.DomEvent.preventDefault(e);
},

Timothee P
committed
_change: function () {
Sébastien DA ROCHA
committed
var v = this._input.value;
if (v !== this._lastGeocode) {
clearTimeout(this._suggestTimeout);
if (v.length >= this.options.suggestMinLength) {
this._suggestTimeout = setTimeout(

Timothee P
committed
L.bind(function () {
Sébastien DA ROCHA
committed
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
this._geocode(true);
}, this),
this.options.suggestTimeout
);
} else {
this._clearResults();
}
}
}
});
function geocoder(options) {
return new Geocoder(options);
}
L.Util.extend(Geocoder, geocoders);
L.Util.extend(L.Control, {
Geocoder: Geocoder,
geocoder: geocoder
});
return Geocoder;
}(L));
//# sourceMappingURL=Control.Geocoder.js.map