我基本上正在做的是尝试在“开放图层”中获取 map ,该 map 的 View 仅限于丹麦。我想使用EPSG:25832来完成此操作,因为我需要使用此投影的特定服务的一些叠加层。

我正在尝试创建WMTSTileGrid,并通过WMTS将其解析为TileLayer,在其中调用服务以获取图层。我正在使用[email protected]

我收到以下错误,并且我需要帮助弄清楚是什么原因引起的:

Uncaught TypeError: Cannot read property 'every' of undefined
    at isSorted (array.js:242)
    at WMTSTileGrid.TileGrid (TileGrid.js:70)
    at new WMTSTileGrid (WMTS.js:58)
    at Object.parcelRequire.index.js.ol/ol.css (index.js:83)
    at newRequire (mao.e31bb0bc.js:47)
    at mao.e31bb0bc.js:81
    at mao.e31bb0bc.js:120

这是代码,我尝试过发布尽可能少的数量以便于阅读,如果您认为缺少的东西,请告诉我:
import { Map, View } from 'ol';
import TileLayer from 'ol/layer/Tile';
import WMTS from 'ol/tilegrid/WMTS';
import WMTSTileGrid from 'ol/tilegrid/WMTS';
import Group from 'ol/layer/Group.js';
import TileWMS from 'ol/source/TileWMS';
import proj4 from 'proj4/dist/proj4';
import { get as getProjection } from 'ol/proj';
import Projection from 'ol/proj/Projection.js';
import { getTopLeft } from 'ol/extent.js';
import { register } from 'ol/proj/proj4.js'; // ADDED THIS

var myServiceToken = '12345678';

// defining custom projection, because i want to use EPSG:25832 due to the service i'm calling
var projCode = 'EPSG:25832';
proj4.defs(projCode, "+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs");
register(proj4); // ADDED THIS

var myProjection = new Projection({
    code: 'EPSG:25832',
    units: 'm',
    extent: [120000, 5661139.2, 1378291.2, 6500000]
});

var projection = getProjection(myProjection);
var projectionExtent = projection.getExtent();
var myTileGrid = new WMTSTileGrid({
    origin: getTopLeft(projectionExtent),
    extent: [120000, 5661139.2, 1378291.2, 6500000],
    resolutions: [1638.4, 819.2, 409.6, 204.8, 102.4, 51.2, 25.6, 12.8, 6.4, 3.2, 1.6, 0.8, 0.4, 0.2],
    matrixIds: ['L00', 'L01', 'L02', 'L03', 'L04', 'L05', 'L06', 'L07', 'L08', 'L09', 'L10', 'L11', 'L12', 'L13'],
});


const map = new Map({
    target: 'map',
    layers: [
        new Group({
            'title': 'Base maps',
            layers: [
                new TileLayer({
                    opacity: 1.0,
                    title: 'Base',
                    type: 'base',
                    visible: true, // by default this layer is visible
                    source: new WMTS({
                        url: "https://services.someService.com/some_map?token=" + myServiceToken,
                        layer: "some_map",
                        matrixSet: "View1",
                        format: "image/jpeg",
                        projection: getProjection('EPSG:25832'), // ADDED THIS
                        tileGrid: myTileGrid,
                        style: 'default',
                        size: [256, 256]
                    })
                })
            ]
        })
    ],
    view: view
});```

最佳答案

您在导入中犯了一个错误:

import WMTS from 'ol/tilegrid/WMTS';

应该:
import WMTS from 'ol/source/WMTS';

关于javascript - WMTS和WMTSTileGrid导致 “Cannot read property '每个“未定义”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56540520/

10-12 21:59