gpt4 book ai didi

javascript - MapBox/Open Layers map 渲染图 block 不正确

转载 作者:行者123 更新时间:2023-12-01 03:59:56 29 4
gpt4 key购买 nike

enter image description here

根据上图,我尝试使用以下代码在 OpenLayers/MapBox 中渲染 map :

var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
url: 'https://api.mapbox.com/styles/v1/mapbox/streets-v9/tiles/512/{z}/{y}/{x}?access_token=<the access token goes here>'
})
})
],
target: 'map',
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}),
view: new ol.View({
center: [0, 0],
zoom: 2
})
});

HTML:

{% extends "layout.html" %}

{% block head %}
<link rel="stylesheet" href="https://openlayers.org/en/v4.0.1/css/ol.css" type="text/css">
<link href='http://mapbox.com/base/latest/base.css' rel='stylesheet'/>
{% endblock %}

{% block body %}
<main id="content">
<div id="map" class="map" tabindex="0"></div>
</main>
<script src="https://openlayers.org/en/v4.0.1/build/ol.js"></script>
<script src="{{ url_for('static', filename='js/search/map.js')></script>

{% endblock %}

显然 map 渲染不正确。有人以前遇到过这个吗?

最佳答案

真是愚蠢的错误。我的网址中有 z, y, x 而不是 z, x, y!

url: 'https://api.mapbox.com/styles/v1/mapbox/streets-v9/tiles/512/{z}/{y}/{x}?access_token=<the access token goes here>

关于javascript - MapBox/Open Layers map 渲染图 block 不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42275851/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com