Openlayers2调用ArcGis的WMTS服务,restful和kvp两种模式

主要代码:

map = new OpenLayers.Map( 'map',{
                numZoomLevels:20
            });
            var wmts = new OpenLayers.Layer.WMTS({
                name: "My WMTS Layer",
                requestEncoding:"REST",
                url:"http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS/tile",
                layer: "WorldTimeZones",
                style: "default",
                tileFullExtent: new OpenLayers.Bounds(-2.0037507067161843E7,-3.024097195838617E7,2.0037507067161843E7,3.0240971458386205E7),
                matrixSet: "default028mm",
                //matrixIds: matrixIds,
                format:"image/png",
                //opacity:1,
                //maxZoomLevel:19,
                isBaseLayer:true
            });
            //map.addLayers([osm,layer]);
            map.addLayer(wmts);
            map.setCenter(new OpenLayers.LonLat(0, 0), 0);
            //map.addControl( new OpenLayers.Control.LayerSwitcher() );
            //map.zoomToMaxExtent();

几个主要参数与wmts的xml信息对应:

<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>RESTfulows:Value>
ows:AllowedValues>
ows:Constraint>
ows:Get>

该标签内表示wmts服务支持restful类型,对应Openlayers.layer.WMTS的参数为:requestEncoding:”“。

<Layer>
<ows:Title>WorldTimeZonesows:Title>
<ows:Identifier>WorldTimeZonesows:Identifier>
<ows:BoundingBox crs="urn:ogc:def:crs:EPSG::3857">
<ows:LowerCorner>-2.0037507067161843E7 -3.024097195838617E7ows:LowerCorner>
<ows:UpperCorner>2.0037507067161843E7 3.0240971458386205E7ows:UpperCorner>
ows:BoundingBox>
<ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84">
<ows:LowerCorner>-179.99999550841463 -88.99999992161119ows:LowerCorner>
<ows:UpperCorner>179.99999550841463 88.99999992161118ows:UpperCorner>
ows:WGS84BoundingBox>
<Style isDefault="true">
<ows:Title>Default Styleows:Title>
<ows:Identifier>defaultows:Identifier>
Style>
<Format>image/pngFormat>
<TileMatrixSetLink>
<TileMatrixSet>default028mmTileMatrixSet>
TileMatrixSetLink>
<TileMatrixSetLink>

<TileMatrixSet>GoogleMapsCompatibleTileMatrixSet>
TileMatrixSetLink>
<ResourceURL format="image/png" resourceType="tile" template="http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS/tile/1.0.0/WorldTimeZones/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png"/>
Layer>

layer标签,
ows:Identifier对应OL的layer:”“,
s:BoundingBox的crs属性为地图坐标参考系,子标签是地图的范围,相当于OL的tileFullExtent:“”,
Style标签ows:Identifier对应OL的style:”“,为空的话一般OL中style:”_null”,
Format标签对应OL的format:”“,
OL的matrixIds:”“为数组参数,默认是0,1,2…,若XML的TileMatrix为EPSG:4326:0,EPSG:4326:1,EPSG:4326:3…需要自己设定参数

注意:ArcGis的restful方式,url需要在…/WMTS/后多加一个tile

你可能感兴趣的:(2015)