Proj4js
by Vladimir Vershinin
HTML
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/dist/proj4-src.js"></script>
<script src="https://unpkg.com/[email protected]/dist/ol.js"></script>
<script src="https://unpkg.com/[email protected]/lib/index.umd.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/lib/style.min.css">
<div id="app">
<div>
View Projection: {{ viewProj }}<br>
Center (EPSG:4326): {{ center }}
</div>
<vl-map ref="map">
<vl-view :projection="viewProj" :zoom.sync="zoom" :center.sync="center"></vl-view>
<vl-layer-tile>
<vl-source-wms url="https://wms.geo.admin.ch/" layers="ch.swisstopo.pixelkarte-farbe-pk1000.noscale" :ext-params="{FORMAT: 'image/jpeg'}" server-type="mapserver" cross-origin="anonymous" :attributions="attributions" :projection="viewProj"></vl-source-wms>
</vl-layer-tile>
</vl-map>
</div>
CSS
html, body, #app {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
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=660.077,13.551,369.344,2.484,1.783,2.939,5.66 +units=m +no_defs')
Vue.use(VueLayers)
// register custom projection
let center = [660000, 190000]
let extent = [420000, 30000, 900000, 350000]
new Vue({
el: '#app',
data () {
return {
zoom: 2,
center: center,
viewProj: 'EPSG:21781',
viewExtent: extent,
attributions: `© <a href="http://www.geo.admin.ch/internet/geoportal/en/home.html">Pixelmap 1:1000000 / geo.admin.ch</a>`
}
},
})