简体   繁体   English

在OpenLayers中,有没有办法在翻译层中渲染Mapbox矢量切片?

[英]In OpenLayers, is there a way to render Mapbox vector tiles in a translated layer?

The recommended approach for translating a vector tile layer seems to be to translate the canvas context on precompose (see OpenLayers 3: per-layer translation for tiled image layers ). 翻译矢量切片图层的推荐方法似乎是在预合成上翻译画布上下文(请参阅OpenLayers 3:平铺图像图层的每层翻译 )。 As noted, only those tiles that fall within the map's pre-translation visible extent are rendered. 如上所述,仅渲染落在地图的预翻译可见范围内的那些图块。

How can I achieve the effect of translation without losing those boundary tiles? 如何在不丢失边界拼贴的情况下实现翻译效果?

I also tried using a custom tile grid with an origin ( https://github.com/openlayers/openlayers/issues/9514 ) but this appears to be a misuse of the 'origin' parameter so tiles were only partially drawn. 我也尝试使用带有原点的自定义图块网格( https://github.com/openlayers/openlayers/issues/9514 ),但这似乎是对'origin'参数的误用,因此仅部分绘制了图块。 I am guessing that custom origins are required to fall on a tile boundary; 我猜测自定义起源需要落在瓷砖边界上; mine do not. 我的不。

Update: Mike's solution is correct. 更新:迈克的解决方案是正确的。 As I recall, I had tried Mike's approach before submitting this question and, although the layer was translated, there was a problem with portions of tiles disappearing (or being drawn in the wrong location). 我记得,在提交这个问题之前,我曾尝试迈克的方法,虽然图层已被翻译,但是部分图块消失(或被绘制在错误的位置)存在问题。 But experimenting with Mike's example, I noticed that setting useInterimTilesOnError to false in my application fixed both the disappearing and misdrawn tile issue. 但是在试验Mike的例子时,我注意到在我的应用程序中将useInterimTilesOnError设置为false修复了消失和误拉的tile问题。 Perhaps there is some problem with the tiles I am using, but it is interesting that when the layer is not offset, tiles are rendered properly regardless of how useInterimTilesOnError is set. 也许我正在使用的瓷砖有一些问题,但有趣的是,当图层没有偏移时,无论如何设置useInterimTilesOnError,都会正确渲染切片。

It seems to be sufficient to offset the extent of the tilegrid (the origin will default to the top left of the extent). 似乎足以抵消tilegrid的范围(原点将默认为范围的左上角)。

 var proj3857 = ol.proj.get('EPSG:3857'); var raster = new ol.layer.Tile({ source: new ol.source.XYZ({ url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', maxZoom: 23 }) }); var map = new ol.Map({ layers: [raster], target: document.getElementById('map'), view: new ol.View({ center: ol.proj.fromLonLat([0, 50]), maxZoom: 23, zoom: 5, projection: proj3857 }) }); var dx = -200000; var dy = -100000; var extent = proj3857.getExtent(); offsetExtent = [extent[0] + dx, extent[1] + dy, extent[2] + dx, extent[3] + dy]; var layer = new ol.layer.VectorTile({ source: new ol.source.VectorTile({ format: new ol.format.MVT(), url: 'https://basemaps.arcgis.com/v1/arcgis/rest/services/World_Basemap/VectorTileServer/tile/{z}/{y}/{x}.pbf', tileGrid: ol.tilegrid.createXYZ({ extent: offsetExtent, maxZoom: 18 }) }), //useInterimTilesOnError: false, style: new ol.style.Style({ stroke: new ol.style.Stroke({ width: 1, color: 'white' }) }) }); map.addLayer(layer); 
 <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script> <link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet"/> <div id="map" class="map"></div> 

Console log from the OpenLayers example near Japan 来自日本附近的OpenLayers示例的控制台日志 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM