Change XYZ url v0.12

by Vladimir Vershinin

HTML

<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.4.3/build/ol.js"></script>
<script src="https://unpkg.com/[email protected]/dist/vuelayers.umd.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/vuelayers.css">
<div id="app">
  <button @click="url = urls[0]">OSM</button>
  <button @click="url = urls[1]">Sputnik</button>
  <vl-map ref="map" data-projection="EPSG:4326">
    <vl-view ref="view" :zoom.sync="zoom" :center.sync="center"></vl-view>
    <vl-layer-tile>
      <vl-source-xyz :url="url"></vl-source-xyz>
    </vl-layer-tile>
  </vl-map>
</div>

CSS

html, body, #app {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

#app {
  display: flex;
  flex-direction: column;
}

.vl-map {
  overflow: hidden;
}

JavaScript

new Vue({
  el: '#app',
  data() {
    return {
      zoom: 2,
      center: [0, 0],
      urls: [
      	'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png',
        'http://tiles.maps.sputnik.ru/{z}/{x}/{y}.png'
      ],
      url: null,
    }
  },
  created () {
    this.url = this.urls[0]
  },
})