@@ -15,6 +15,7 @@ Display an image with a custom defined projection (e.g., EPSG:27770).
1515 <meta name =" viewport" content =" width=device-width, initial-scale=1" />
1616 <link rel =" stylesheet" href =" https://unpkg.com/maplibre-gl/dist/maplibre-gl.css" />
1717 <script src =" https://unpkg.com/maplibre-gl/dist/maplibre-gl.js" ></script >
18+ <script src =" https://unpkg.com/proj4/dist/proj4.js" ></script >
1819 <script src =" https://unpkg.com/@naivemap/maplibre-gl-image-layer" ></script >
1920 <style >
2021 * {
@@ -31,6 +32,13 @@ Display an image with a custom defined projection (e.g., EPSG:27770).
3132 <body >
3233 <div id =" map" ></div >
3334 <script >
35+ proj4 .defs (
36+ ' EPSG:27700' ,
37+ ' +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 ' +
38+ ' +x_0=400000 +y_0=-100000 +ellps=airy ' +
39+ ' +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' +
40+ ' +units=m +no_defs'
41+ )
3442 const map = new maplibregl.Map ({
3543 container: ' map' ,
3644 style: ' https://www.naivemap.com/demotiles/style.json' ,
@@ -43,15 +51,8 @@ Display an image with a custom defined projection (e.g., EPSG:27770).
4351 }
4452 })
4553 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' ,
54+ const layer = new ImageLayer (' image-layer' , {
55+ url: ' ./images/2000px-British_National_Grid.png' ,
5556 projection: ' EPSG:27700' ,
5657 coordinates: [
5758 [0 , 1300000 ], // top-left
@@ -61,7 +62,7 @@ Display an image with a custom defined projection (e.g., EPSG:27770).
6162 ]
6263 })
6364
64- map .addLayer (layer4326 )
65+ map .addLayer (layer )
6566 })
6667 </script >
6768 </body >
0 commit comments