OpenLayers 3 Beginner’s Guide

Applying Zoomify sample knowledge to a single raw image

Open sample in a new windows

<!doctype html>
<html>
  <head>
    <title>Image static sample</title>
    <link rel="stylesheet" href="../assets/ol3/css/ol.css" type="text/css" />
    <link rel="stylesheet" href="../assets/css/samples.css" type="text/css" />
  </head>
  <body>
    <div id="map" class="map"></div>
    <script src="../assets/ol3/js/ol.js"></script>
    <script>
      var imgWidth = 9945;
      var imgHeight = 6846;
      var url = '/assets/data/1797-map-of-Dublin.jpg';

      var imgCenter = [imgWidth / 2, imgHeight / 2];

      // Maps always need a projection, but Zoomify layers are not geo-referenced, and
      // are only measured in pixels.  So, we create a fake projection that the map
      // can use to properly display the layer.
      var proj = new ol.proj.Projection({
        code: 'ZOOMIFY',
        units: 'pixels',
        extent: [0, 0, imgWidth, imgHeight]
      });

      var source = new ol.source.ImageStatic({
        attributions: [
          new ol.Attribution({
            html: '&copy; <a href="https://commons.wikimedia.org/wiki/File:1797-map-of-Dublin.jpg#Summary">Wikipedia Commons</a>'
          })
        ],
        url: url,
        imageSize: [imgWidth, imgHeight],
        projection: proj,
        imageExtent: proj.getExtent()
      });

      var map = new ol.Map({
        layers: [
          new ol.layer.Image({
            source: source
          })
        ],
        target: 'map',
        view: new ol.View({
          projection: proj,
          center: imgCenter,
          zoom: 1
        })
      });
    </script>
  </body>
</html>