0

我正在尝试将使用 OpenLayers 的地图实现到 Angular 应用程序中。

作为瓦片层,我希望使用 Open Street Map。

当我在本地运行我的应用程序时,它就像一个魅力,但是当我将它安装在服务器上时,地图不会显示。

出现以下错误:

Access to image at 'https://a.tile.openstreetmap.org/2/3/0.png' from origin 'https://my.testservices.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

谷歌搜索了一段时间后,我找到了将 crossOrigin 设置“null”添加到我的图块层的建议:

gOnInit(): void {
    this.map = new Map({
        view: new View({
            center: [0, 0],
            zoom: 1,
        }),
        layers: [
            new TileLayer({
                source: new OSM({
                    crossOrigin: null
                }),
            })
        ],
        target: 'ol-map'
    });
}

没错,标题不再丢失,但我现在收到以下错误消息:

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://a.tile.openstreetmap.org/7/69/45.png with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

任何想法我怎样才能使它工作?

非常感谢!

4

0 回答 0