// 坐标转换 var getRectWH = function (mainmap, minimap){ // 投影坐标系:以东为x轴正半轴,以北为y轴正半轴 // 屏幕坐标系:以right为x轴正半轴,以bottom为y轴正半轴 var x, y, w, h;
var mainExtend = mainmap.getView().calculateExtent(mainmap.getSize()); var topLeftPixelCoor = minimap.getPixelFromCoordinate(ol.extent.getTopLeft(mainExtend)); var rightBottomPiexlCoor = minimap.getPixelFromCoordinate(ol.extent.getBottomRight(mainExtend));
x = topLeftPixelCoor[0]; y = topLeftPixelCoor[1]; w = Math.abs(topLeftPixelCoor[0]- rightBottomPiexlCoor[0]); h = Math.abs(topLeftPixelCoor[1] - rightBottomPiexlCoor[1]);
// 返回结果 return { x: x, y: y, width: w, height: h }; };