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%; font-family: Arial, sans-serif; } .map { width: 100%; height: 100%; cursor: default; } #info { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); background-color: rgba(255, 255, 255, 0.8); padding: 15px; border-radius: 8px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); max-width: 700px; font-size: 12px; z-index: 9999; overflow-y: auto; } #info h3 { margin: 0; font-size: 14px; color: #333; } #info p { margin: 5px 0; color: #555; } #info a { color: #007BFF; text-decoration: none; } #info a:hover { text-decoration: underline; } #info table { width: 100%; border-collapse: collapse; margin-top: 10px; } #info table, #info th, #info td { border: 1px solid #ddd; } #info th, #info td { padding: 8px; text-align: left; } #info th { background-color: #f2f2f2; } #info td { font-size: 12px; word-wrap: break-word; } </style> </head> <body> <div id="map" class="map"></div> <div id="info"></div> <script> const cnigSource = new ol.source.XYZ({ url: 'https://tms-ign-base.idee.es/1.0.0/IGNBaseTodo/{z}/{x}/{-y}.jpeg' }); const wmsSource = new ol.source.TileWMS({ url: 'https://sigpac-hubcloud.es/wms', params: { 'SERVICE': 'WMS', 'VERSION': '1.3.0', 'LAYERS': 'AU.Sigpac:recinto', 'TILED': true, 'TRANSPARENT': true, 'FORMAT': 'image/png' }, serverType: 'geoserver' }); const cnigLayer = new ol.layer.Tile({ source: cnigSource, }); const wmsLayer = new ol.layer.Tile({ source: wmsSource, }); const view = new ol.View({ center: ol.proj.fromLonLat([-5, 40]), zoom: 16 }); const map = new ol.Map({ layers: [cnigLayer, wmsLayer], target: 'map', view: view, }); map.on('singleclick', function (evt) { const coordinate = evt.coordinate; document.getElementById('info').innerHTML = '
Cargando información...
'; const viewResolution = view.getResolution(); const url = wmsSource.getFeatureInfoUrl( coordinate, viewResolution, 'EPSG:3857', {'INFO_FORMAT': 'text/html'} ); if (url) { fetch(url) .then((response) => response.text()) .then((html) => { console.log(html) document.getElementById('info').innerHTML = html; }); } }); map.on('pointermove', function (evt) { if (evt.dragging) { return; } const data = wmsLayer.getData(evt.pixel); const hit = data && data[3] > 0; map.getTargetElement().style.cursor = hit ? 'pointer' : ''; }); </script> </body> </html>