OpenLayers - TileArcGISRest 与 XYZ
TileArcGISRest 上的 OpenLayers 文档 说:
对于缓存的 ArcGIS 服务,使用 ol/source/XYZ 可以获得更好的性能。
但是 XYZ 不适合 ArcGis,并且我的 ArcGis 切片地图(使用单融合地图缓存)在使用时不适合 OSM XYZ(参见屏幕截图)。我的代码中只有 TileArcGISRest 使地图图层适合 OSM 图层。这给我留下了一些问题:
- 如何将 TileArcGISRest 迁移到 XYZ?
- 为什么 XYZ 表现更好?
- 为什么 TileArcGISRest 没有相应地实现性能改进?
我的代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.13.0/css/ol.css"
type="text/css"
/>
<style>
.map {
height: 95vh;
width: 100%;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.13.0/build/ol.js"></script>
<title>OpenLayers example</title>
</head>
<body>
<div id="map" class="map"></div>
<script type="text/javascript">
const host = "map_host";
const map = new ol.Map({
target: "map",
layers: [
// OpenStreetMap layer
new ol.layer.Tile({
source: new ol.source.OSM(),
}),
new ol.layer.Tile({
source: new ol.source.TileArcGISRest({
url: `https://${host}/arcgis/rest/services/Geocache_UTM33_EUREF89/GeocacheBilder/MapServer`,
}),
}),
new ol.layer.Tile({
source: new ol.source.XYZ({
url: `https://${host}/arcgis/rest/services/Geocache_UTM33_EUREF89/GeocacheBilder/MapServer/tile/{z}/{y}/{x}`,
}),
}),
],
view: new ol.View({
center: [0, 6000000],
zoom: 3,
}),
});
</script>
</body>
</html>
OpenLayers docs on TileArcGISRest says:
For cached ArcGIS services, better performance is available by using ol/source/XYZ instead.
But XYZ is not adapted to ArcGis and my ArcGis tile map (with Single Fused Map Cache) does not fit OSM when using XYZ (see screenshot). Only TileArcGISRest in my code makes the map layer fit the OSM layer. That leaves me with some questions:
- How do I migrate TileArcGISRest to XYZ?
- Why does XYZ perform better?
- Why doesn't TileArcGISRest implement performance improvements accordingly?
My code is as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.13.0/css/ol.css"
type="text/css"
/>
<style>
.map {
height: 95vh;
width: 100%;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.13.0/build/ol.js"></script>
<title>OpenLayers example</title>
</head>
<body>
<div id="map" class="map"></div>
<script type="text/javascript">
const host = "map_host";
const map = new ol.Map({
target: "map",
layers: [
// OpenStreetMap layer
new ol.layer.Tile({
source: new ol.source.OSM(),
}),
new ol.layer.Tile({
source: new ol.source.TileArcGISRest({
url: `https://${host}/arcgis/rest/services/Geocache_UTM33_EUREF89/GeocacheBilder/MapServer`,
}),
}),
new ol.layer.Tile({
source: new ol.source.XYZ({
url: `https://${host}/arcgis/rest/services/Geocache_UTM33_EUREF89/GeocacheBilder/MapServer/tile/{z}/{y}/{x}`,
}),
}),
],
view: new ol.View({
center: [0, 6000000],
zoom: 3,
}),
});
</script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您从缓存图块的服务 json 中获取图块网格,您可以为图块指定正确的 OpenLayers XYZ 源。由于源位于 UTM 投影中(OpenLayers 需要 proj4),您必须将其重新投影到与 OSM 相同的 Web Mercator,或者指定 UTM33 作为视图投影并重新投影 OSM 背景。
If you obtain the tilegrid from the service json for the cached tiles you can specify the correct OpenLayers XYZ source for the tiles. As the source is in a UTM projection (for which OpenLayers needs proj4) you must either reproject it to web mercator the same as OSM, or specify UTM33 as the view projection and reproject the OSM background.
迈克的答案是正确的,您必须指定正确的tilegrid才能使用ol.source.XYZ。
但我会回答你的两个问题:
使用 ol.source.XYZ 可以直接访问图块,图块已经生成并存储在图块服务器上的某个位置。服务器无需处理。它只是发回图块,因此请求速度更快。
请求 XYZ 请求的示例:
使用 TileArcGISRest 源。图块是使用您提供的参数(投影、bbox、宽度、高度...)动态创建的。因此与 XYZ 相比,需要更多的后端处理。
请求示例:
总而言之,XYZ 使用缓存切片,而 TileArcGISRest 动态生成切片。
The answer of Mike is correct you have to specify the correct tilegrid to use an ol.source.XYZ.
But I will answers to your 2 questions:
Using an ol.source.XYZ you access the tiles directly, tiles are already generated and stored somewhere on your tile server. No treatment needed by the server. It just send back the tile so requests are faster.
Example of a request XYZ request:
Using a TileArcGISRest source. Tiles are created on the fly with the parameter you give (projection, bbox, wisth,height ..). So more backend treatment are needed compared to XYZ.
Example of a request :
To summarize, XYZ use cached tile and TileArcGISRest generates tiles on the fly.