简体   繁体   中英

MapBox/Open Layers map rendering tiles incorrectly

在此处输入图片说明

As per the image above, I am trying to render a map in OpenLayers/MapBox with the following code:

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 %}

Obviously the map is not rendering correctly. Anyone come across this before?

Really silly mistake. I had z, y, x in the url rather than 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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