1、将米转换成坐标度数
function getRadiusByMile(raidusMile){
var radius = 0;
var degree = (24901*1609)/360.0;
var draidusMile = raidusMile;
var dpm = 1/degree;
radius = dpm*draidusMile;
return radius;
}
2、根据坐标点和半径将地图缩放到合适等级
var x;
var y;
var radius = parseInt($(".bufferRidius").val());
var r = getRadiusByMile(radius); //前面的算法
var rectArr = [];
var leftBottom = [x-r,y-r];
var leftTop = [x+r,y-r];
var righttBottom = [x+r,y-r];
var rightTop = [x+r,y+r];
rectArr = [leftBottom,leftTop,rightTop,righttBottom];
top.setFitResolutionAdmin(rectArr);
//设置最佳可视范围[[x,y],[x,y],[x,y]]
function setFitResolutionAdmin(pointsArr){
var lineStr = new ol.geom.LineString(pointsArr);
if (map){
var view = map.getView();
var res = view.fit(lineStr);
mapZoom(1); //地图缩小两级
}else{
console.log("地图还未初始化完成")
}
}
网友评论