GoogleMapActivity.java 5.44 KB
package com.pashanhoo.landsurvey;

import android.location.Location;
import android.location.LocationListener;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.esri.android.map.LocationDisplayManager;
import com.esri.android.map.MapView;
import com.esri.android.runtime.ArcGISRuntime;
import com.esri.core.geometry.Point;
import com.pashanhoo.landsurvey.layers.gaode.GaodeMapLayerTypes;
import com.pashanhoo.landsurvey.layers.gaode.GaodeMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.layers.geoq.GeoQMapLayerTypes;
import com.pashanhoo.landsurvey.layers.geoq.GeoQMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.layers.google.GoogleMapLayerTypes;
import com.pashanhoo.landsurvey.layers.google.GoogleMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.utils.AppInfo;
import com.pashanhoo.landsurvey.utils.GISHelper;
import com.pashanhoo.landsurvey.utils.JZLocationConverter;

public class GoogleMapActivity extends AppCompatActivity {

    private MapView mapView;
    // GPS定位器对象
    private LocationDisplayManager locationDisplayManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_google_map);

        AppInfo.Settings();

        ArcGISRuntime.setClientId("1eFHW78avlnRUPHm");
        mapView = (MapView) findViewById(R.id.map);
        mapView.setEsriLogoVisible(false);
        mapView.enableWrapAround(false);

//        GoogleMapsTiledServiceLayer GOOGLE_VECTOR_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.VECTOR_GOOGLE_MAP);
//        GoogleMapsTiledServiceLayer GOOGLE_TER_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.TERRAIN_GOOGLE_MAP);
//        GoogleMapsTiledServiceLayer GOOGLE_IMAGE_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.IMAGE_GOOGLE_MAP);
//        mapView.addLayer(GOOGLE_IMAGE_Layer);
//        GoogleMapsTiledServiceLayer GOOGLE_ANNO_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.IMAGE_ANNO_GOOGLE_MAP);
//        mapView.addLayer(GOOGLE_ANNO_Layer);
//        GoogleMapsTiledServiceLayer OSM_Layer = new GoogleMapsTiledServiceLayer(GoogleMapLayerTypes.OSM_Map);
//        mapView.addLayer(OSM_Layer);

        //---------------------------------------------------------------------------------------------------------------------
        // 高德矢量图层(含路网,含注记)
        GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_VECTOR);
        // 高德影像图层(不含路网,不含注记)
//        GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_IMAGE);
        // 高德路网图层(含路网,含注记)
//        GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_ROAD);
        // 高德实时交通图层
//        GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_TRAFFIC);
        mapView.addLayer(gaodeMapsTiledServiceLayer);
        //---------------------------------------------------------------------------------------------------------------------

//        GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile);
//        mapView.addLayer(geoQMapsTiledServiceLayer);

        mapView.setMaxResolution(156543.03392800014);
        mapView.setMinResolution(0.29858214164761665);

        Point pt = GISHelper.lonLat2Mercator(AppInfo.initPoint);
        mapView.zoomToResolution(pt, GoogleMapsTiledServiceLayer.getRes()[16]);

        locationDisplayManager = mapView.getLocationDisplayManager();
        locationDisplayManager.setShowLocation(true);
        locationDisplayManager.setAutoPanMode(LocationDisplayManager.AutoPanMode.LOCATION);//设置模式
        locationDisplayManager.setShowPings(true);
        locationDisplayManager.setLocationListener(new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                Point pt = new Point(location.getLongitude(), location.getLatitude());
                Point gcjPt = JZLocationConverter.wgs84ToGcj02(pt);
                mapView.zoomToResolution(GISHelper.lonLat2Mercator(gcjPt),
                        GoogleMapsTiledServiceLayer.getRes()[18]);
            }

            @Override
            public void onStatusChanged(String s, int i, Bundle bundle) {
            }

            @Override
            public void onProviderEnabled(String s) {
            }

            @Override
            public void onProviderDisabled(String s) {
            }
        });

        FloatingActionButton gps = (FloatingActionButton) findViewById(R.id.gps);
        gps.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 设置GPS功能
                if (locationDisplayManager.isStarted()) {
                    locationDisplayManager.stop();
                } else {
                    locationDisplayManager.start();
                    mapView.zoomToResolution(GISHelper.lonLat2Mercator(locationDisplayManager.getPoint()),
                            GoogleMapsTiledServiceLayer.getRes()[18]);
                }
            }
        });
    }
}