arcgis for android loads the wms service and obtains the information of the spots in the service

1. Load wms service

        First, a brief introduction to the WMS service, WMS is to publish the map as a map service, and then when the client requests the map server, it can return the corresponding map information (such as the corresponding map picture) according to the user's request information, and then the client can According to the result returned by the server, the required map is displayed on the client side.

        According to the OGC standard, the WMS service can provide the following operations:

GetCapabitities:返回服务级元数据,它是对服务信息内容和要求参数的一种描述
GetMap:返回一个地图影像,其地理空间参考和大小参数是明确定义了的
GetFeatureInfo:返回显示在地图上的某些特殊要素的信息
GetLegendGraphic:返回地图的图例信息

        In ArcGIS for Android, two operations, GetCapabitities and GetMap, are mainly involved . Among them, requesting GetCapabitities from the map server will obtain an XML file, which contains the name of the layer contained in the WMS service, the coordinate system of the layer and other data. Request GetMap from the server, and a picture will be obtained according to the requested parameters. The requested parameters include the height, width, coordinate system and other information of the picture.

        Load example (ArcGIS Runtime SDK based on Android 100.6):

        When ArcGIS for Android loads WMS services, it uses the WMSLayer class. The request method can only be GetCapabitities , the XML file will be obtained through GetCapabitities, ArcGIS for Android will parse it internally, and then automatically construct the request parameters through the current map position, and then request the server through GetMap, the server returns the image according to the request parameters, ArcGIS for Android will display the picture on MapView.

//wms服务图层名称
List<String> wmsLayersName = new ArrayList<String>();
        wmsLayersName.add("aaa");
WmsLayer wmsLayer = new WmsLayer("http://192.168.0.136:8087/geoserver/common/wms?SERVICE=WMS&REQUEST=GetCapabilities", wmsLayersName);
        wmsLayer.loadAsync();
        if (basemap != null) {
            basemap.getBaseLayers().add(wmsLayer);
        }

        The wms service is loaded.

2. Read the information of the map spots in the service

The GetFeatureInfo method         is mainly used to read map spot information . The specific parameters required by this method are  here http://ditu.mwr.gov.cn/iserver/help/html/zh/API/WMS/WMS130/GetFeatureInfo/GetFeatureInfo_request.htm 

Polygon visibleArea = getView().getMapView().getVisibleArea();
        Envelope envelope = visibleArea.getExtent();
        double xMax = envelope.getXMax();
        double xMin = envelope.getXMin();
        double yMax = envelope.getYMax();
        double yMin = envelope.getYMin();

        String x = String.valueOf(e.getX()).split("\\.")[0];
        String y = String.valueOf(e.getY()).split("\\.")[0];

//获取屏幕宽高
        Resources resources = getView().getSelfActivity().getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
        int screenWidth = dm.widthPixels;
        int screenHeight = dm.heightPixels;

String GetFeatureInfo_url = "http://192.168.0.136:8087/geoserver/common/wms?" +
                    "SERVICE=WMS" +
                    "&VERSION=1.1.1" +
                    "&REQUEST=GetFeatureInfo" +
                    "&LAYERS=common:O_0810_YSCFGDWTTB_2022" +
                    "&BBOX=" + xMin + "," + yMin + "," + xMax + "," + yMax +
                    "&FORMAT=image/png" +
                    "&TRANSPARENT=true" +
                    "&QUERY_LAYERS=common:O_0810_YSCFGDWTTB_2022" +
                    "&exceptions=application/vnd.ogc.se_xml" +
                    "&INFO_FORMAT=application/json" +
                    "&FEATURE_COUNT=1" +
                    "&X=" + x +
                    "&Y=" + y +
                    "&SRS=EPSG:4490" +
                    "&WIDTH=" + screenWidth +
                    "&HEIGHT=" + screenHeight;

Guess you like

Origin blog.csdn.net/minusn/article/details/128834904