ArcGIS for Android 100.3.0(19):WmsLayer

ArcGIS for Android 100.3.0(19):WmsLayer_第1张图片

代表开放地理空间联盟(OGC)Web地图服务(WMS)层。
该服务可以在ArcGIS Online上的云中,第三方服务器上或ArcGIS Server上内部托管。

构造方法:
ArcGIS for Android 100.3.0(19):WmsLayer_第2张图片
预先知道感兴趣层的名称时创建WMS图层的示例:

 private MapView mMapView;

    private String wms_layer_url = "https://certmapper.cr.usgs.gov/arcgis/services/geology/africa/MapServer/WMSServer?request=GetCapabilities&service=WMS";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wms_layer_url);

        mMapView = findViewById(R.id.mapView);
        ArcGISMap map = new ArcGISMap(Basemap.Type.IMAGERY, 2.0, 18.0, 3);
        mMapView.setMap(map);

        // 保存一个用于显示的唯一标识WMS层名称的列表
        List wmsLayerNames = new ArrayList<>();
        wmsLayerNames.add("0");

        // create a new WMS layer displaying the specified layers from the service
        WmsLayer wmsLayer = new WmsLayer(wms_layer_url, wmsLayerNames);

        // add the layer to the map
        map.getOperationalLayers().add(wmsLayer);

        wmsLayer.addDoneLoadingListener(new Runnable() {

            @Override
            public void run() {
                if (wmsLayer.getLoadStatus() == LoadStatus.LOADED) {
                    // work with WMS layer here
                }
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        mMapView.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.resume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.dispose();
    }

ArcGIS for Android 100.3.0(19):WmsLayer_第3张图片

从WMS服务检索感兴趣的图层时创建WMS图层的示例:

 private MapView mMapView;

    private String wmts_url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wmts_layer);

        mMapView = findViewById(R.id.mapView);
        ArcGISMap map = new ArcGISMap();
        mMapView.setMap(map);

        // create wmts service from url string
        WmtsService wmtsService = new WmtsService(wmts_url);
        wmtsService.addDoneLoadingListener(() -> {
            if (wmtsService.getLoadStatus() == LoadStatus.LOADED) {
                // get service info
                WmtsServiceInfo wmtsServiceInfo = wmtsService.getServiceInfo();
                // get the first layer id
                List layerInfoList = wmtsServiceInfo.getLayerInfos();
                // create WMTS layer from layer info
                WmtsLayer wmtsLayer = new WmtsLayer(layerInfoList.get(0));
                // set the basemap of the map with WMTS layer
                map.setBasemap(new Basemap(wmtsLayer));
            } else {
                String error = "Error loading WMTS Service: " + wmtsService.getLoadError();
                Log.e("xyh", error);
                Toast.makeText(this, error, Toast.LENGTH_LONG).show();
            }
        });
        wmtsService.loadAsync();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mMapView.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.resume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.dispose();
    }

ArcGIS for Android 100.3.0(19):WmsLayer_第4张图片

设置WmsLayer的样式

  private static final String TAG = MainActivity.class.getSimpleName();

    private MapView mMapView;

    private String wms_layer_url_minnesota = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_style_wms_layer);

        mMapView = findViewById(R.id.mapView);
        ArcGISMap map = new ArcGISMap(Basemap.createImagery());
        mMapView.setMap(map);

        // create a WMS layer
        List wmsLayerNames = Collections.singletonList("fsa2017");
        WmsLayer wmsLayer = new WmsLayer(wms_layer_url_minnesota, wmsLayerNames);
        wmsLayer.loadAsync();
        wmsLayer.addDoneLoadingListener(() -> {
            if (wmsLayer.getLoadStatus() == LoadStatus.LOADED) {
                // add the layer to the map
                map.getOperationalLayers().add(wmsLayer);

                // zoom to the layer on the map
                mMapView.setViewpoint(new Viewpoint(wmsLayer.getFullExtent()));

                // get styles
                List styles = wmsLayer.getSublayers().get(0).getSublayerInfo().getStyles();

                // set the style when the button is toggled
                ToggleButton toggle = findViewById(R.id.toggleStyleButton);
                toggle.setOnCheckedChangeListener((buttonView, isChecked) -> {
                    if (isChecked) {
                        // set the sublayer's current style
                        wmsLayer.getSublayers().get(0).setCurrentStyle(styles.get(1));
                    } else {
                        //[DocRef: Name=Set WMS Layer Style, Category=Fundamentals, Topic=Symbols and Renderers]
                        // set the sublayer's current style
                        wmsLayer.getSublayers().get(0).setCurrentStyle(styles.get(0));
                        //[DocRef: END]
                    }
                });
            } else {
                String error = "Failed to load WMS layer: " + wmsLayer.getLoadError().getMessage();
                Log.e(TAG, error);
                Toast.makeText(this, error, Toast.LENGTH_LONG).show();
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        mMapView.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.resume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.dispose();
    }

你可能感兴趣的:(ArcGIS for Android 100.3.0(19):WmsLayer)