2.8 Afegir llistat de capes
Exemple
.addLayerTree(options)
See the Pen Exemple AddMarker by unitatgeostart (@unitatgeostart) on CodePen.
Codi
<html>
<head>
<meta charset="utf-8" />
<title>Exemple mapicgc-gl-js: Afegir arbre de capes</title>
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<script src="https://eines.icgc.cat/recursos/mapicgc-gl-js/mapicgc-gl.js"></script>
<link
href="https://eines.icgc.cat/recursos/mapicgc-gl-js/mapicgc-gl.css"
rel="stylesheet"
/>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<nav id="filter-group" class="filter-group"></nav>
<script>
async function initMap() {
const data = await mapicgcgl.Config.getConfigICGC();
const map = new mapicgcgl.Map({
container: "map",
style: data.Styles.TOPO,
center: [2.1464, 41.306],
zoom: 6.4,
maxZoom: 19,
hash: true,
pitch: 0,
});
let options = {
features: {
type: "FeatureCollection",
features: [
{
type: "Feature",
properties: {
icon: "Rubí",
},
geometry: {
type: "Point",
coordinates: [2.0119, 41.489],
},
},
{
type: "Feature",
properties: {
icon: "Moià",
},
geometry: {
type: "Point",
coordinates: [2.119, 41.87],
},
},
{
type: "Feature",
properties: {
icon: "Les Borges Blanques",
},
geometry: {
type: "Point",
coordinates: [0.97319, 41.4589],
},
},
{
type: "Feature",
properties: {
icon: "Berga",
},
geometry: {
type: "Point",
coordinates: [1.83, 42.163],
},
},
],
},
id: "testLayer",
type: "geojson",
};
map.on("load", () => {
map.addLayerTree(options);
});
}
initMap();
</script>
</body>
</html>