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
})
});