Projections 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">
<script src="https://unpkg.com/[email protected]/dist/proj4.js"></script>
<div id="app">
  <vl-map ref="map" data-projection="EPSG:4326">
    <vl-view ref="view" :zoom.sync="zoom" :center.sync="center" projection="EPSG:4326"></vl-view>
    <vl-layer-tile>
      <vl-source-osm></vl-source-osm>
    </vl-layer-tile>

    <vl-layer-vector>
      <vl-source-vector :features="features" projection="EPSG:3857"></vl-source-vector>
    </vl-layer-vector>

    <vl-layer-tile>
      <vl-source-wms url="https://wms.geo.admin.ch/" projection="EPSG:21781" layers="ch.swisstopo.pixelkarte-farbe-pk1000.noscale" cross-origin="anonymous"></vl-source-wms>
    </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

proj4.defs(
  'EPSG:21781',
  '+proj=somerc +lat_0=46.95240555555556 ' +
  '+lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel ' +
  '+towgs84=674.4,15.1,405.3,0,0,0,0 +units=m +no_defs',
)
ol.proj.proj4.register(proj4)

new Vue({
  el: '#app',
  data() {
    return {
      zoom: 3,
      center: [20, 20],
      features: [{
        type: 'Feature',
        geometry: {
          type: 'Point',
          coordinates: [20e5, 20e5],
        },
      }],
    }
  },
})