Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Last active June 16, 2023 15:54
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Display a map</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.js"></script>
<link rel="stylesheet" type="text/css" href="https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.css">
<style type="text/css">
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
//const url_style = "https://wxs.ign.fr/static/vectorTiles/styles/ISOHYPSE/isohypse_multicolore.json"
//const url_style = "https://wxs.ign.fr/static/vectorTiles/styles/ISOHYPSE/isohypse_monochrome_marron.json"
const url_style = "https://wxs.ign.fr/static/vectorTiles/styles/ISOHYPSE/isohypse_monochrome_orange.json"
fetch(url_style).then(res => res.json()).then(style => {
// Patch tms scheme to xyz to make it compatible for Maplibre GL JS / Mapbox GL JS
style.sources.isohypse.scheme = 'xyz';
style.sources.isohypse.attribution = 'Données cartographiques : © IGN';
style.sources.isohypse.tiles = style.sources.isohypse.tiles.map(url => url.replace('https://vectortiles.ign.fr/rok4server/1.0.0/ISOHYPSE/', 'https://wxs.ign.fr/altimetrie/geoportail/tms/1.0.0/ISOHYPSE/'))
style.sources.isohypse.url = style.sources.isohypse.url.replace('https://vectortiles.ign.fr/rok4server/1.0.0/ISOHYPSE/', 'https://wxs.ign.fr/altimetrie/geoportail/tms/1.0.0/ISOHYPSE/')
const map = new maplibregl.Map({
container: 'map', // container id
style: style, // style URL
center: [3.389162, 46.852644], // starting position [lng, lat]
zoom: 7, // starting zoom
attributionControl: false,
hash: true
});
map.addControl(new maplibregl.AttributionControl({compact: false}));
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Display a map</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.js"></script>
<link rel="stylesheet" type="text/css" href="https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.css">
<style type="text/css">
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
const url_style = "https://wxs.ign.fr/essentiels/static/vectorTiles/styles/PLAN.IGN/standard.json";
fetch(url_style).then(res => res.json()).then(style => {
// Patch tms scheme to xyz to make it compatible for Maplibre GL JS / Mapbox GL JS
style.sources.plan_ign.scheme = 'xyz';
style.sources.plan_ign.attribution = 'Données cartographiques : © IGN';
const map = new maplibregl.Map({
container: 'map', // container id
style: style, // style URL
center: [3.389162, 46.852644], // starting position [lng, lat]
zoom: 5, // starting zoom
attributionControl: false
});
map.addControl(new maplibregl.AttributionControl({compact: true}));
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment