【发布时间】:2019-04-27 20:29:54
【问题描述】:
我正在尝试将 BingMaps 图层添加到已初始化的地图中。我遇到了一个我无法理解的错误。你知道出了什么问题吗?我正在使用 OpenLayers 5.3.1。
TypeError: r is null[Weitere Informationen] map.js:1:677385
• a http://localhost:8080/map/map.js:1
• inverse http://localhost:8080/map/map.js:1
• I http://localhost:8080/map/map.js:1
• transformInv_ http://localhost:8080/map/map.js:1
• u http://localhost:8080/map/map.js:1
• t http://localhost:8080/map/map.js:1
• getTile http://localhost:8080/map/map.js:1
• manageTilePyramid http://localhost:8080/map/map.js:1
• prepareFrame http://localhost:8080/map/map.js:1
• renderFrame http://localhost:8080/map/map.js:1
• renderFrame_ http://localhost:8080/map/map.js:1
• animationDelay_ http://localhost:8080/map/map.js:1
• <anonym> self-hosted:974
我的打字稿是这样的:
import Map from 'ol/Map';
import OlTileLayer from 'ol/layer/Tile';
import BingMaps from 'ol/source/BingMaps';
@injectable()
export class MapWrapper {
private _map: Map;
public getMap() {
return this._map;
}
set map(value: Map) {
this._map = value;
}
public createBingLayer(bingKey: string, style : string) : OlTileLayer {
return new OlTileLayer({
visible: true,
preload: Infinity,
source: new BingMaps({
key: bingKey,
imagerySet: style
})
});
}
}
而我的 HTML 中的 javascript 就是这样的:
function addBingMap() {
var realMap = map.mapWrapper.getMap();
var bingLayer = map.mapHolder.createBingLayer("someAPIKey", "Road");
//realMap.getLayers().insertAt(0, bingLayer);
realMap.addLayer(bingLayer);
}
更新
我发现我看到的错误是由 BingMaps 瓷砖被重新投影到 EPSG:32632 引起的,我的所有其他图层都使用它。 proj4 transformer() 方法中抛出了错误。我为 ol 创建了一个 bug 票,因为我认为它至少应该抛出一个有意义的错误消息,即使我不能使用另一个投影将 BingMaps(网络墨卡托投影)与图层混合。
【问题讨论】:
-
能否提供一些相关代码?
标签: webpack openlayers