Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Last active March 22, 2024 00:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasG77/5a122812635a85af7f762858ecf052a3 to your computer and use it in GitHub Desktop.
Save ThomasG77/5a122812635a85af7f762858ecf052a3 to your computer and use it in GitHub Desktop.
<!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">
window.debugStyleMaplibre = null;
// const url_style = "https://data.geopf.fr/annexes/ressources/vectorTiles/styles/ISOHYPSE/isohypse_multicolore.json"
// const url_style = "https://data.geopf.fr/annexes/ressources/vectorTiles/styles/ISOHYPSE/isohypse_monochrome_marron.json"
const url_style = "https://data.geopf.fr/annexes/ressources/vectorTiles/styles/ISOHYPSE/isohypse_monochrome_orange.json"
fetch(url_style).then(res => res.json()).then(style => {
window.debugStyleMaplibre = style;
style.sources.isohypse.attribution = 'Données cartographiques : © IGN';
style.layers = style.layers.filter(el => el['source-layer'] != 'frontiere_france')
const map = new maplibregl.Map({
container: 'map', // container id
style: style, // style URL
center: [6.018308, 45.390043], // starting position [lng, lat]
zoom: 15, // 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://data.geopf.fr/annexes/ressources/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