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>RESTful</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Get>

該標籤內表示wmts服務支持restful類型,對應Openlayers.layer.WMTS的參數爲:requestEncoding:”“。

<Layer>
<ows:Title>WorldTimeZones</ows:Title>
<ows:Identifier>WorldTimeZones</ows:Identifier>
<ows:BoundingBox crs="urn:ogc:def:crs:EPSG::3857">
<ows:LowerCorner>-2.0037507067161843E7 -3.024097195838617E7</ows:LowerCorner>
<ows:UpperCorner>2.0037507067161843E7 3.0240971458386205E7</ows:UpperCorner>
</ows:BoundingBox>
<ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84">
<ows:LowerCorner>-179.99999550841463 -88.99999992161119</ows:LowerCorner>
<ows:UpperCorner>179.99999550841463 88.99999992161118</ows:UpperCorner>
</ows:WGS84BoundingBox>
<Style isDefault="true">
<ows:Title>Default Style</ows:Title>
<ows:Identifier>default</ows:Identifier>
</Style>
<Format>image/png</Format>
<TileMatrixSetLink>
<TileMatrixSet>default028mm</TileMatrixSet>
</TileMatrixSetLink>
<TileMatrixSetLink>
<!--
Only show this TileMatrixSet if the tiling scheme is compliant to Google Maps (and that happens with tile width = 256 px)
-->
<TileMatrixSet>GoogleMapsCompatible</TileMatrixSet>
</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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章