more fixes

This commit is contained in:
j 2025-08-06 21:50:00 +02:00
commit f3e0632f0e
4 changed files with 39 additions and 16 deletions

View file

@ -595,10 +595,17 @@ Ox.Map = function(options, self) {
self.boundsChanged = true;
}
function toSpan(bounds) {
return {
lat: bounds._ne.lat - bounds._sw.lat,
lng: bounds._ne.lng - bounds._sw.lng,
}
}
function canContain(outerBounds, innerBounds) {
// checks if outerBounds _can_ contain innerBounds
var outerSpan = outerBounds.toSpan(),
innerSpan = innerBounds.toSpan();
var outerSpan = toSpan(outerBounds),
innerSpan = toSpan(innerBounds);
return outerSpan.lat > innerSpan.lat &&
outerSpan.lng > innerSpan.lng;
}
@ -614,6 +621,8 @@ Ox.Map = function(options, self) {
}
function clickMap(event) {
console.log("not this one", event)
return
var place = getSelectedPlace();
if (self.options.clickable/* && !editing()*/) {
getPlaceByLatLng(event.lngLat, self.map.getBounds(), function(place) {
@ -753,19 +762,19 @@ Ox.Map = function(options, self) {
self.$loadingIcon && self.$loadingIcon.start();
var results = await reverseGeocode(latlng);
self.$loadingIcon && self.$loadingIcon.stop();
if (true) {
if (results.features.length) {
if (bounds) {
Ox.forEach(results, function(result, i) {
Ox.forEach(results.features, function(result, i) {
if (
i == results.length - 1 ||
canContain(bounds, result.geometry.bounds || result.geometry.viewport)
canContain(bounds, result.bounds)
) {
callback(new Ox.MapPlace(parseGeodata(results[i])));
callback(new Ox.MapPlace(parseGeodata(result)));
return false; // break
}
});
} else {
callback(new Ox.MapPlace(parseGeodata(results[0])));
callback(new Ox.MapPlace(parseGeodata(results.features[0])));
}
}
if (!results.length) {
@ -1151,7 +1160,7 @@ Ox.Map = function(options, self) {
function parseGeodata(data) {
console.log("parseGeodata", data)
// FIXME: data is geojson Feature with Polygon geometry now
var bounds = data.bounds || data.geometry.bounds || data.geometry.viewport,
var bounds = data.bounds,
northEast = bounds._ne,
southWest = bounds._sw,
place = {
@ -1472,6 +1481,8 @@ Ox.Map = function(options, self) {
// someone may want to cache google geocode data, so we fire an event.
// google puts functions like lat or lng on the objects' prototypes,
// so we create properly named properties, for json encoding
console.log(data)
/*
if (data.latLng) {
data.latLng = {
lat: data.latLng.lat,
@ -1500,6 +1511,7 @@ Ox.Map = function(options, self) {
}
}
});
*/
that.triggerEvent('geocode', data);
}