最近使用arcgis for android 实现一些功能,如何实现图层中所有元素居中呢?
eg:有两个点A(ax,ay),B(bx,by),实现在图层中居中
以下为实现代码:
import com.esri.core.geometry.Point
public void zoomToCenter(){
//lonA,latA为A点的经纬度
//将经纬度转成地图参考的坐标点
Point pntA = (Point)GeometryEngine.project(lonA, latA, mapSr)
Point pntB = (Point)GeometryEngine.project(lonB, latB, mapSr)
//计算A,B点在屏幕上的像素点
Point screenPntA = mapView.toScreenPoint(pntA);
com.esri.core.geometry.Point screenPntB = mapView.toScreenPoint(pntB);
//计算缩放比例
double s = Math.max(screenCp.getX() - screenSp.getX(), screenCp.getY() - screenSp.getY()) / (Math.min(mapView.getWidth(), m