Static image 2

by Vladimir Vershinin

HTML

<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/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.css">
<div id="app">
  <vl-map ref="map">
    <vl-view :zoom.sync="zoom" :center.sync="center" 
             :projection="imageProj"></vl-view>
    
    <vl-layer-image id="static">
        <vl-source-image-static
          :url="currentImage"
          :size="imageSize"
          :extent="imageExtent"
          :projection="imageProj">
        </vl-source-image-static>
      </vl-layer-image>
  </vl-map>  
</div>

CSS

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

JavaScript

// Custom projection for static Image layer
let x = 1024 * 10000
let y = 968 * 10000
let imageExtent = [-x / 2, -y / 2, x / 2, y / 2]
let customProj = new ol.proj.Projection({
  code: 'xkcd-image',
  units: 'pixels',
  extent: imageExtent,
})
// add to the list of known projections
// after that it can be used by code
ol.proj.addProjection(customProj)

new Vue({
	el: '#app',
  data () {
  	return {
    	zoom: 2,
      center: [0, 0],
      imageProj: customProj.getCode(),
      images: {
      	one: 'https://imgs.xkcd.com/comics/online_communities.png',
      },
      currentImageKey: 'one',
      imageSize: [1024, 968],
      imageExtent,
    }
  },
  computed: {
  	currentImage () {
    	return this.images[this.currentImageKey]
    },
  },
})