2.15 Consulta d'elements
Exemple
.addFeatureQuery(layer, queryFields, popupStyle)
Retorna informació al fer clic sobre un element
See the Pen Exemple Consulta d'elements by unitatgeostart (@unitatgeostart) on CodePen.
Codi
<html>
<head>
<meta charset="utf-8" />
<title>Exemple mapicgc-gl-js: Consulta d'elements</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>
<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: 7.4,
maxZoom: 19,
hash: true,
pitch: 0,
});
map.on("load", () => {
let paintOptions = {
layout: { visibility: "visible" },
paint: {
"line-color": "red",
"line-width": 2,
"line-opacity": 1,
},
layerPosition: "top",
};
map.fetchData(
"https://analisi.transparenciacatalunya.cat/resource/pzaa-n72w.geojson",
"RutesMontserrat",
paintOptions
);
let popupStyle = {
title: "Informació:",
image: "https://eines.icgc.cat/recursos/logos/icgc_logo_color.png",
};
// si volem camps específics:
// let queryFields = ["nom", "municipi"];
let queryFields = [];
map.addFeatureQuery("RutesMontserrat", queryFields, popupStyle);
//si volem tots els paràmetres:
// map.addFeatureQuery("RutesMontserrat");
});
}
initMap();
</script>
</body>
</html>