gpt4 book ai didi

javascript - WMTS 和 WMTSTileGrid 导致 "Cannot read property ' 每个'未定义'

转载 作者:行者123 更新时间:2023-11-29 10:56:21 32 4
gpt4 key购买 nike

我基本上做的是尝试在开放图层中获取 map ,其 View 仅限于丹麦。我想使用 EPSG:25832 来完成它,因为我需要来自使用此投影的特定服务的一些覆盖。

我正在尝试创建一个 WMTSTileGrid,并通过 WMTS 将其解析为 TileLayer,我在其中调用服务来获取我的图层。我正在使用 ol@5.3.2。

我收到以下错误,我需要帮助找出导致错误的原因:

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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com