WMTS 和 WMTSTileGrid 导致“无法读取未定义的属性‘every’”
2019-06-11
1331
我基本上是在尝试获取开放图层中的地图,该图层的视图仅限于丹麦。我想使用 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
});```
1个回答
您在导入时犯了一个错误:
import WMTS from 'ol/tilegrid/WMTS';
应该是:
import WMTS from 'ol/source/WMTS';
transporter_room_3
2019-06-11