|
| 1 | + |
| 2 | +# Georeferenced Image with EPSG:27770 |
| 3 | + |
| 4 | +Display an image with a custom defined projection (e.g., EPSG:27770). |
| 5 | + |
| 6 | +<iframe src="/maplibre-gl-layers/demos/image-27770.html" width="100%" style="border:none; height:400px"></iframe> |
| 7 | + |
| 8 | +```html |
| 9 | +<!doctype html> |
| 10 | +<html lang="en"> |
| 11 | + <head> |
| 12 | + <title>Georeferenced Image with EPSG:27770</title> |
| 13 | + <meta property="og:description" content="Display an image with a custom defined projection (e.g., EPSG:27770)." /> |
| 14 | + <meta charset="utf-8" /> |
| 15 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 16 | + <link rel="stylesheet" href="https://unpkg.com/maplibre-gl/dist/maplibre-gl.css" /> |
| 17 | + <script src="https://unpkg.com/maplibre-gl/dist/maplibre-gl.js"></script> |
| 18 | + <script src="https://unpkg.com/@naivemap/maplibre-gl-image-layer"></script> |
| 19 | + <style> |
| 20 | + * { |
| 21 | + margin: 0; |
| 22 | + padding: 0; |
| 23 | + } |
| 24 | +
|
| 25 | + #map { |
| 26 | + height: 400px; |
| 27 | + } |
| 28 | + </style> |
| 29 | + </head> |
| 30 | + |
| 31 | + <body> |
| 32 | + <div id="map"></div> |
| 33 | + <script> |
| 34 | + const map = new maplibregl.Map({ |
| 35 | + container: 'map', |
| 36 | + style: 'https://www.naivemap.com/demotiles/style.json', |
| 37 | + bounds: [ |
| 38 | + [105.289838, 32.204171], |
| 39 | + [110.195632, 28.164713] |
| 40 | + ], |
| 41 | + fitBoundsOptions: { |
| 42 | + padding: { top: 10, bottom: 10, left: 10, right: 10 } |
| 43 | + } |
| 44 | + }) |
| 45 | + map.on('load', () => { |
| 46 | + proj4.defs( |
| 47 | + 'EPSG:27700', |
| 48 | + '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 ' + |
| 49 | + '+x_0=400000 +y_0=-100000 +ellps=airy ' + |
| 50 | + '+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' + |
| 51 | + '+units=m +no_defs' |
| 52 | + ) |
| 53 | + const layer4326 = new ImageLayer('image-layer', { |
| 54 | + url: 'https://www.naivemap.com/mapbox-gl-js-cookbook/assets/images/4326.png', |
| 55 | + projection: 'EPSG:27700', |
| 56 | + coordinates: [ |
| 57 | + [0, 1300000], // top-left |
| 58 | + [700000, 1300000], // top-right |
| 59 | + [700000, 0], // bottom-right |
| 60 | + [0, 0] // bottom-left |
| 61 | + ] |
| 62 | + }) |
| 63 | +
|
| 64 | + map.addLayer(layer4326) |
| 65 | + }) |
| 66 | + </script> |
| 67 | + </body> |
| 68 | +</html> |
| 69 | + |
| 70 | +``` |
0 commit comments