Compare commits

..

No commits in common. "bbc8debf46220ee0f67825b6e98fbb8601de1097" and "f5d15ce75fe786628133981c69fb89b2bca8a0ec" have entirely different histories.

2 changed files with 25 additions and 25 deletions

View file

@ -16,7 +16,7 @@ Ox.load(['UI', 'Geo'], function() {
addPlace: function(place, callback) { addPlace: function(place, callback) {
place = Ox.clone(place) place = Ox.clone(place)
place.id = Ox.encodeBase26((places.length ? Ox.max(places.map(p => Ox.decodeBase26(p.id))) : 0) + 1) place.id = Ox.encodeBase26((places.length ? Ox.max(places.map(p => Ox.decodeBase26(p.id))) : 0) + 1)
place.editable = true; place.editable = true
console.log("addPlace", place.id, place) console.log("addPlace", place.id, place)
places.push(place) places.push(place)
$storage("places", places) $storage("places", places)

View file

@ -767,24 +767,34 @@ Ox.Map = function(options, self) {
} }
async function getPlaceByLatLng(latlng, bounds, callback) { async function getPlaceByLatLng(latlng, bounds, callback) {
// gets the place at latlng appropriate for current zoom level // gets the largest place at latlng that would fit in bounds
var callback = arguments.length == 3 ? callback : bounds, var callback = arguments.length == 3 ? callback : bounds,
bounds = arguments.length == 3 ? bounds : null; bounds = arguments.length == 3 ? bounds : null;
self.$loadingIcon && self.$loadingIcon.start(); self.$loadingIcon && self.$loadingIcon.start();
var results = await reverseGeocode(latlng); var results = await reverseGeocode(latlng);
self.$loadingIcon && self.$loadingIcon.stop(); self.$loadingIcon && self.$loadingIcon.stop();
if (results.features.length) { if (results.features.length) {
// We only have one result based on current zoom level if (bounds) {
var feature = results.features[0]; Ox.forEach(results.features, function(result, i) {
callback(new Ox.MapPlace(parseGeodata(feature))); if (
i == results.length - 1 ||
canContain(bounds, result.bounds)
) {
callback(new Ox.MapPlace(parseGeodata(result)));
return false; // break
}
});
} else {
callback(new Ox.MapPlace(parseGeodata(results.features[0])));
}
}
if (!results.length) {
triggerGeocodeEvent({ triggerGeocodeEvent({
latLng: latlng, latLng: latlng,
results: results.features results: results
}); });
} else { } else {
Ox.Log('Map', 'geocode failed: no results'); Ox.Log('Map', 'geocode failed:', status);
callback(null); callback(null);
} }
} }
@ -885,30 +895,20 @@ Ox.Map = function(options, self) {
async function reverseGeocode(config) { async function reverseGeocode(config) {
const features = []; const features = [];
// Use current map zoom level directly as Nominatim zoom level
const currentMapZoom = Math.round(self.map.getZoom());
console.log('Reverse geocoding: using map zoom =', currentMapZoom, 'for Nominatim zoom');
try { try {
const request = `${self.options.nominatim}/reverse?lat=${ const request = `${self.options.nominatim}/reverse?lat=${
config.lat config.lat
}&lon=${ }&lon=${
config.lng config.lng
}&format=geojson&polygon_geojson=1&addressdetails=1&zoom=${currentMapZoom}&extratags=1`; }&format=geojson&polygon_geojson=1&addressdetails=1`;
const response = await fetch(request); const response = await fetch(request);
const geojson = await response.json(); const geojson = await response.json();
for (const feature of geojson.features) {
if (geojson.features && geojson.features.length > 0) { features.push(converNominatimFeature(feature));
const feature = converNominatimFeature(geojson.features[0]);
feature.zoom = currentMapZoom;
features.push(feature);
} }
} catch (e) { } catch (e) {
console.error(`Failed to reverseGeocode with error: ${e}`); console.error(`Failed to reverseGeocode with error: ${e}`);
} }
return { return {
features features
}; };