Inicio
Descripción
Ejemplos
Consulta de propiedades
Actualizar mapa
<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Documento HTML</title> <script src="https://cdn.jsdelivr.net/npm/ol@v9.1.0/dist/ol.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v9.1.0/ol.css"/> <style> html, body { margin: 0; padding: 0; height: 100%; } .map { width: 100%; height: 100%; cursor: default; } #map { position: relative; } #info { position: absolute; display: inline-block; height: auto; width: auto; z-index: 100; background-color: #333; color: #fff; text-align: center; border-radius: 4px; padding: 5px; left: 50%; transform: translateX(3%); visibility: hidden; pointer-events: none; } </style> </head> <body> <div id="map" class="map"> <div id="info"></div> </div> <script> var IGNBase = new ol.layer.Tile({ source: new ol.source.XYZ({ url: 'https://tms-ign-base.idee.es/1.0.0/IGNBaseTodo/{z}/{x}/{-y}.jpeg' }) }); var recinto_pbf = new ol.layer.VectorTile({ minZoom: 12, source: new ol.source.VectorTile({ minZoom: 12, maxZoom: 15, format: new ol.format.MVT(), url: "https://sigpac-hubcloud.es/mvt/recinto@3857@pbf/{z}/{x}/{y}.pbf" }), }); var map = new ol.Map({ layers: [IGNBase, recinto_pbf], target: 'map', view: new ol.View({ center: [-544618, 4868342], zoom: 15 }) }); const info = document.getElementById('info'); let currentFeature; const displayFeatureInfo = function (pixel, target) { const feature = target.closest('.ol-control') ? undefined : map.forEachFeatureAtPixel(pixel, function (feature) { return feature; }); if (feature) { info.style.left = pixel[0] + 'px'; info.style.top = pixel[1] + 'px'; if (feature !== currentFeature) { info.style.visibility = 'visible'; info.innerText = "provincia: " + (feature.get('provincia') || "") + "\n" + "municipio: " + (feature.get('municipio') || "") + "\n" + "agregado: " + feature.get('agregado') + "\n" + "zona: " + feature.get('zona') + "\n" + "poligono: " + (feature.get('poligono') || "") + "\n" + "parcela: " + (feature.get('parcela') || "") + "\n" + "recinto: " + (feature.get('recinto') || "") + "\n" + "superficie: " + (feature.get('superficie') || "") + "\n" + "pendiente_media: " + (feature.get('pendiente_media') || "") + "\n" + "altitud: " + (feature.get('altitud') || "") + "\n" + "uso_sigpac: " + (feature.get('uso_sigpac') || "") + "\n" + "subvencionabilidad: " + (feature.get('subvencionabilidad') || "") + "\n" + "coef_regadio: " + (feature.get('coef_regadio') || "") + "\n" + "incidencias: " + (feature.get('incidencias') || "") + "\n" + "region: " + (feature.get('region') || ""); } } else { info.style.visibility = 'hidden'; } currentFeature = feature; }; map.on('pointermove', function (evt) { if (evt.dragging) { info.style.visibility = 'hidden'; currentFeature = undefined; return; } const pixel = map.getEventPixel(evt.originalEvent); displayFeatureInfo(pixel, evt.originalEvent.target); }); map.getTargetElement().addEventListener('pointerleave', function () { currentFeature = undefined; info.style.visibility = 'hidden'; }); </script> </body> </html>