Image Reprojection

This example uses OpenLayers v4.0.1. The latest is v.

#### Image Reprojection

Demonstrates client-side reprojection of single image source.

This example shows client-side reprojection of single image source.

Related API documentation:

- ol.Map
,
- ol.View
,
- ol.extent
,
- ol.layer.Image
,
- ol.layer.Tile
,
- ol.proj
,
- ol.source.ImageStatic
,
- ol.source.OSM

Copy Edit
Image Reprojection Demonstrates client-side reprojection of single image source. proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 ' + '+x_0=400000 +y_0=-100000 +ellps=airy ' + '+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' + '+units=m +no_defs'); var imageExtent = [0, 0, 700000, 1300000]; var map = new ol.Map({ layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }), new ol.layer.Image({ source: new ol.source.ImageStatic({ url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/' + 'British_National_Grid.svg/2000px-British_National_Grid.svg.png', crossOrigin: '', projection: 'EPSG:27700', imageExtent: imageExtent }) }) ], target: 'map', view: new ol.View({ center: ol.proj.transform( ol.extent.getCenter(imageExtent), 'EPSG:27700', 'EPSG:3857'), zoom: 4 }) }); <div id="map" class="map"></div>

    <!DOCTYPE html>
    <html>
      <head>
        <title>Image Reprojection</title>
        <link rel="stylesheet" href="https://openlayers.org/en/v4.0.1/css/ol.css" type="text/css">
        <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
        <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
        <script src="https://openlayers.org/en/v4.0.1/build/ol.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.15/proj4.js"></script>
      </head>
      <body>
        <div id="map" class="map"></div>
        <script>
          proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 ' +
              '+x_0=400000 +y_0=-100000 +ellps=airy ' +
              '+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' +
              '+units=m +no_defs');
          var imageExtent = [0, 0, 700000, 1300000];

          var map = new ol.Map({
            layers: [
              new ol.layer.Tile({
                source: new ol.source.OSM()
              }),
              new ol.layer.Image({
                source: new ol.source.ImageStatic({
                  url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/' +
                         'British_National_Grid.svg/2000px-British_National_Grid.svg.png',
                  crossOrigin: '',
                  projection: 'EPSG:27700',
                  imageExtent: imageExtent
                })
              })
            ],
            target: 'map',
            view: new ol.View({
              center: ol.proj.transform(
                  ol.extent.getCenter(imageExtent), 'EPSG:27700', 'EPSG:3857'),
              zoom: 4
            })
          });
        </script>
      </body>
    </html>