openlayers2調用天地圖WMTS服務簡單例子

 var map;
        function init(){
            map = new OpenLayers.Map( 'map',{
                numZoomLevels:19
            });
            var wmts = new OpenLayers.Layer.WMTS({
                name: "My WMTS Layer",
                //url: "http://example.com/wmts",
                url:"http://t0.tianditu.com/vec_c/wmts",
                layer: "vec",
                style: "default",
                matrixSet: "c",
                //matrixIds: matrixIds,
                format:"tiles",
                //opacity:1,
                //maxZoomLevel:19,
                isBaseLayer:true
            });
            //map.addLayers([osm,layer]);
            map.addLayer(wmts);
            map.setCenter(new OpenLayers.LonLat(115.86, 34.4), 12);
            //map.addControl( new OpenLayers.Control.LayerSwitcher() );
            //map.zoomToMaxExtent();
        }

開始忘記設置map的numZoomLevels屬性,導致ol源碼中zoom = Math.max(0, Math.min(zoom, this.resolutions.length - 1));this.resolutions.length=undefined

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