Merge branch 'maplibre-big-bbox' into maplibre
This commit is contained in:
commit
bbc8debf46
2 changed files with 25 additions and 25 deletions
|
|
@ -16,7 +16,7 @@ Ox.load(['UI', 'Geo'], function() {
|
|||
addPlace: function(place, callback) {
|
||||
place = Ox.clone(place)
|
||||
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)
|
||||
places.push(place)
|
||||
$storage("places", places)
|
||||
|
|
|
|||
|
|
@ -767,34 +767,24 @@ Ox.Map = function(options, self) {
|
|||
}
|
||||
|
||||
async function getPlaceByLatLng(latlng, bounds, callback) {
|
||||
// gets the largest place at latlng that would fit in bounds
|
||||
// gets the place at latlng appropriate for current zoom level
|
||||
var callback = arguments.length == 3 ? callback : bounds,
|
||||
bounds = arguments.length == 3 ? bounds : null;
|
||||
self.$loadingIcon && self.$loadingIcon.start();
|
||||
var results = await reverseGeocode(latlng);
|
||||
self.$loadingIcon && self.$loadingIcon.stop();
|
||||
|
||||
if (results.features.length) {
|
||||
if (bounds) {
|
||||
Ox.forEach(results.features, function(result, i) {
|
||||
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) {
|
||||
// We only have one result based on current zoom level
|
||||
var feature = results.features[0];
|
||||
callback(new Ox.MapPlace(parseGeodata(feature)));
|
||||
|
||||
triggerGeocodeEvent({
|
||||
latLng: latlng,
|
||||
results: results
|
||||
results: results.features
|
||||
});
|
||||
} else {
|
||||
Ox.Log('Map', 'geocode failed:', status);
|
||||
Ox.Log('Map', 'geocode failed: no results');
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -895,20 +885,30 @@ Ox.Map = function(options, self) {
|
|||
|
||||
async function reverseGeocode(config) {
|
||||
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 {
|
||||
const request = `${self.options.nominatim}/reverse?lat=${
|
||||
config.lat
|
||||
}&lon=${
|
||||
config.lng
|
||||
}&format=geojson&polygon_geojson=1&addressdetails=1`;
|
||||
config.lat
|
||||
}&lon=${
|
||||
config.lng
|
||||
}&format=geojson&polygon_geojson=1&addressdetails=1&zoom=${currentMapZoom}&extratags=1`;
|
||||
|
||||
const response = await fetch(request);
|
||||
const geojson = await response.json();
|
||||
for (const feature of geojson.features) {
|
||||
features.push(converNominatimFeature(feature));
|
||||
|
||||
if (geojson.features && geojson.features.length > 0) {
|
||||
const feature = converNominatimFeature(geojson.features[0]);
|
||||
feature.zoom = currentMapZoom;
|
||||
features.push(feature);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Failed to reverseGeocode with error: ${e}`);
|
||||
}
|
||||
|
||||
return {
|
||||
features
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue