0

NodeJS 的所有示例 OL5。

对于浏览器代码,我转换import OSM from 'ol/source/OSM.js';ol.source.OSM(), import WMTS from 'ol/source/WMTS.js';tool.source.WMTS等。

但是创建WMTSTileGrid对象不起作用。

我愿意 -new ol.tilegrid.WMTS.WMTSTileGrid(.... 但浏览器说

TypeError: ol.tilegrid.WMTS.WMTSTileGrid is not a constructor

如何创建WMTSTileGrid对象?我哪里错了?

我的代码:

var projection = new ol.proj.get('EPSG:3857');
var projectionExtent = projection.getExtent();
console.log(projectionExtent);
var size = ol.extent.getWidth(projectionExtent) / 256;
var resolutions = new Array(18);
var matrixIds = new Array(18);
for (var z = 0; z < 18; ++z) {
    // generate resolutions and matrixIds arrays for this WMTS
    resolutions[z] = size / Math.pow(2, z);
    matrixIds[z] = z;
}
;
var tileGrid = new ol.tilegrid.WMTS.WMTSTileGrid(
        {
            origin: ol.extent.getTopLeft(projectionExtent),
            resolutions: resolutions,
            matrixIds: matrixIds
        }
);

var layers = [
    new ol.layer.Tile({
        source: new ol.source.OSM()
    }),
    new ol.layer.Tile({
        source: new ol.source.WMTS({
            url: 'http://93.174.00.00:8080/geoserver/gwc/service/wmts',
            format: 'image/png',
            layer: "wrksp:rest_test_Mercator",
            projection: projection,
            tileGrid: tileGrid,
            style: 'default',
            wrapX: true,
            matrixSet: 'EPSG:900913'
        })
    })
];
var map = new ol.Map({
    layers: layers,
    target: 'map',
    view: new ol.View({
        center: [3830333, 7606624],
        zoom: 14
    })
});
4

1 回答 1

1

我解决了问题

new ol.layer.Tile({
        source: new ol.source.WMTS({
            url: 'http://93.174.76.56:8080/geoserver/gwc/service/wmts',
            format: 'image/png',
            layer: "bigland:rest_test_Mercator",
            projection: projection,
            tileGrid: tileGrid,                
            wrapX: true,
            matrixSet: 'EPSG:900913'

        })
    })

var projection = new ol.proj.get('EPSG:900913');
for (var z = 0; z < 18; ++z) {
        // generate resolutions and matrixIds arrays for this WMTS
        resolutions[z] = size / Math.pow(2, z);
        matrixIds[z] ='EPSG:900913:' + z;
        //matrixIds[z] = z;
    }
于 2018-08-29T04:19:11.670 回答