JS计算缩放地图缩放级别
//根据经纬极值计算绽放级别。function getZoom (maxLng, minLng, maxLat, minLat) { var zoom = ["50","100","200","500","1000","2000","5000","10000","20000","25000","50000","100000","200000","500000","1000000","2000000"]//级别18到3。 var pointA = new BMap.Point(maxLng,maxLat); // 创建点坐标A var pointB = new BMap.Point(minLng,minLat); // 创建点坐标B var distance = map.getDistance(pointA,pointB).toFixed(1); //获取两点距离,保留小数点后两位 for (var i = 0,zoomLen = zoom.length; i < zoomLen; i++) {if(zoom[i] - distance > 0){ return 18-i+3;//之所以会多3,是因为地图范围常常是比例尺距离的10倍以上。所以级别会增加3。} };}