我想检查我的地图的边界,以便我可以根据边界应用集群。 var bounds = map.getBounds();
var ne = bounds.getNorthEast(); // LatLng of the north-east corner
var sw = bounds.getSouthWest(); // LatLng of the south-west corner
我已经通过纬度增量和经度增量找到缩放级别来清除我的问题。
let zoom = Math.round(Math.log(360 / region.longitudeDelta) / Math.LN2);
this.zoom = zoom;
已编辑
const getBoundingBox = (region) => ([
region.longitude - region.longitudeDelta, // westLng - min lng
region.latitude - region.latitudeDelta, // southLat - min lat
region.longitude + region.longitudeDelta, // eastLng - max lng
region.latitude + region.latitudeDelta // northLat - max lat
])
export const getBoundByRegion = (region, scale = 1) => {
/*
* Latitude : max/min +90 to -90
* Longitude : max/min +180 to -180
*/
const latOffset = (region.latitudeDelta / 2) * scale;
const lngD =
region.longitudeDelta < -180
? 360 + region.longitudeDelta
: region.longitudeDelta;
const lngOffset = (lngD / 2) * scale;
return {
minLng: calcMinLngByOffset(region.longitude, lngOffset), // westLng - min lng
minLat: calcMinLatByOffset(region.latitude, latOffset), // southLat - min lat
maxLng: calcMaxLngByOffset(region.longitude, lngOffset), // eastLng - max lng
maxLat: calcMaxLatByOffset(region.latitude, latOffset), // northLat - max lat
};
};
const calcMinLatByOffset = (lng: number, offset: number) => {
const factValue = lng - offset;
if (factValue < -90) {
return (90 + offset) * -1;
}
return factValue;
};
const calcMaxLatByOffset = (lng: number, offset: number) => {
const factValue = lng + offset;
if (90 < factValue) {
return (90 - offset) * -1;
}
return factValue;
};
const calcMinLngByOffset = (lng: number, offset: number) => {
const factValue = lng - offset;
if (factValue < -180) {
return (180 + offset) * -1;
}
return factValue;
};
const calcMaxLngByOffset = (lng: number, offset: number) => {
const factValue = lng + offset;
if (180 < factValue) {
return (180 - offset) * -1;
}
return factValue;
};
信用:https://github.com/react-native-maps/react-native-maps/issues/356