vlad filippov
vlad filippov

Reputation: 21

ol.tilegrid.WMTS.WMTSTileGrid is not a constructor

All examples OL5 for NodeJS.

For browser code I convert import OSM from 'ol/source/OSM.js'; to ol.source.OSM(), import WMTS from 'ol/source/WMTS.js'; to ol.source.WMTS, etc.

But creating WMTSTileGrid object doesn't work.

I do - new ol.tilegrid.WMTS.WMTSTileGrid(.... but browser say

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

How create WMTSTileGrid object? Where i'm wrong?

my code:

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

Upvotes: 0

Views: 2071

Answers (1)

vlad filippov
vlad filippov

Reputation: 21

I solved the problem

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'

        })
    })

and

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

Upvotes: 1

Related Questions