1function OmekaGeocoder(geocoder) { 2 function photon(query) { 3 var url = 'https://photon.komoot.io/api/'; 4 return jQuery.getJSON(url, {q: query, limit: 1}) 5 .then(function (data) { 6 if (!data.features.length) { 7 return jQuery.Deferred().reject('No results found'); 8 } 9 10 return data.features[0].geometry.coordinates.reverse(); 11 }); 12 } 13 14 function nominatim(query) { 15 var url = 'https://nominatim.openstreetmap.org/search'; 16 return jQuery.getJSON(url, {q: query, limit: 1, format: 'json'}) 17 .then(function (data) { 18 if (!data.length) { 19 return jQuery.Deferred().reject('No results found'); 20 } 21 22 return [data[0].lat, data[0].lon]; 23 }); 24 } 25 26 switch (geocoder) { 27 case 'photon': 28 this.geocoder = photon; 29 break; 30 case 'nominatim': 31 this.geocoder = nominatim; 32 break; 33 default: 34 console.log('Unknown geocoder specified'); 35 } 36} 37 38OmekaGeocoder.prototype.geocode = function (query) { 39 function matchLiteralCoords(query) { 40 var latLngMatch = query.trim().match(/^(-?[\d]+(?:\.[\d]+)?)[\s]*[,;][\s]*(-?[\d]+(?:\.[\d]+)?)$/); 41 if (latLngMatch && Math.abs(latLngMatch[1]) <= 90 && Math.abs(latLngMatch[2]) <= 180) { 42 return [latLngMatch[1], latLngMatch[2]]; 43 } 44 return false; 45 } 46 var literalCoords = matchLiteralCoords(query); 47 if (literalCoords) { 48 return jQuery.Deferred().resolve(literalCoords); 49 } 50 return this.geocoder(query); 51};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.