Static image 3

transparent

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/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"></vl-view>
    
    <vl-layer-tile>
      <vl-source-osm />
    </vl-layer-tile>
    
    <vl-layer-image id="static">
        <vl-source-image-static
          url="http://assets.stickpng.com/images/5cb0633d80f2cf201a4c3253.png"
          :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 // calculate from origin
let y = 968 * 10000 // calculate from origin
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(),
      imageSize: [1024, 968],
      imageExtent,
    }
  },
})