zoukankan      html  css  js  c++  java
  • Android GIS开发系列-- 入门季(10) MapView快速定位到Geometry

    我们知道某个Geometry的坐标,但不知道具体的位置,该如何使地图快速定位呢?这时需要用到MapView.setExtent方法,来看下这个方法的介绍:Zooms the map to the given geometry so that geometry fits within the bounds of the map.大体的意思即缩小地图定位到Geometry。上代码:

    public class MainActivity extends Activity {
    
        private MapView mapView;
        private GraphicsLayer graphicsLayer;
        private static final String TILED_WORLD_STREETS_URL = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            mapView = (MapView) findViewById(R.id.map_view);
            mapView.addLayer(new ArcGISTiledMapServiceLayer(TILED_WORLD_STREETS_URL));
    
            findViewById(R.id.location).setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    //快速定位到线
                    Polyline polyline = new Polyline();
                    polyline.startPath(new Point(110, 23));
                    polyline.lineTo(new Point(115, 25));
                    //由于加载的地图是墨卡托坐标,这里需要转坐标
                    Polyline polyline2 = (Polyline) GeometryEngine.project(polyline,
                            SpatialReference.create(SpatialReference.WKID_WGS84),
                            SpatialReference
                                    .create(SpatialReference.WKID_WGS84_WEB_MERCATOR));
                    mapView.setExtent(polyline2);
                }
            });
            initLayer();
        }
    
    
        /**
         * 添加一条线
         */
        private void initLayer() {
            graphicsLayer = new GraphicsLayer();
            mapView.addLayer(graphicsLayer);
            Polyline polyline = new Polyline();
            polyline.startPath(new Point(110, 23));
            polyline.lineTo(new Point(115, 25));
            //由于加载的地图是墨卡托坐标,这里需要转坐标
            Polyline polyline2 = (Polyline) GeometryEngine.project(polyline,
                    SpatialReference.create(SpatialReference.WKID_WGS84),
                    SpatialReference
                            .create(SpatialReference.WKID_WGS84_WEB_MERCATOR));
            graphicsLayer.addGraphic(new Graphic(polyline2, new SimpleLineSymbol(
                    Color.RED, 3, SimpleLineSymbol.STYLE.SOLID)));
        }
    
    
    
    }

    定位效果图

  • 相关阅读:
    Java IO流-NIO简介
    Java IO流-Properties
    Java IO流-序列化流和反序列化流
    Codeforces Round #371 (Div. 1) C
    bzoj 2326 矩阵快速幂
    IndiaHacks 2016
    HDU
    Educational Codeforces Round 51 (Rated for Div. 2) F
    Codeforces Round #345 (Div. 1) D
    Codeforces Round #300 E
  • 原文地址:https://www.cnblogs.com/arxive/p/7751971.html
Copyright © 2011-2022 走看看