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> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/> <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script> <style> html, body { margin: 0; padding: 0; height: 100%; } .map { width: 100%; height: 100%; } </style> </head> <body> <div id="map" class="map"></div> <div id="info" class="info"></div> <script> var map = L.map('map').setView([40.02, -4.9], 17); L.tileLayer('https://tms-ign-base.idee.es/1.0.0/IGNBaseTodo/{z}/{x}/{-y}.jpeg', { maxZoom: 19, attribution: "
CC BY 4.0 scne.es
" }).addTo(map); var wmsUrl = 'https://wms.mapa.gob.es/sigpac/wms' var wmsLayer = L.tileLayer.wms(wmsUrl, { layers: 'recinto', format: 'image/png', transparent: true, version: '1.3.0', crs: L.CRS.EPSG3857 }).addTo(map); map.on('click', function (e) { const url = getFeatureInfoUrl(e.latlng, map.getZoom(), wmsLayer); if(url){ fetch(url) .then(response => response.text()) .then(data => { document.getElementById('info').innerHTML = data; }) .catch(error => { L.popup() .setLatLng(e.latlng) .setContent('Error fetching data') .openOn(map); console.log(error) }); } }); function getFeatureInfoUrl(latlng, zoom, wmsLayer) { var point = map.latLngToContainerPoint(latlng, zoom), bounds = map.getBounds(), sw = map.options.crs.project(bounds.getSouthWest()), ne = map.options.crs.project(bounds.getNorthEast()), size = map.getSize(); var params = { request: 'GetFeatureInfo', service: 'WMS', srs: 'EPSG:3857', styles: '', transparent: true, version: '1.3.0', format: 'image/png', bbox: [sw.x, sw.y, ne.x, ne.y].join(','), height: size.y, width: size.x, layers: wmsLayer.wmsParams.layers, query_layers: wmsLayer.wmsParams.layers, info_format: 'text/html' }; params[params.version === '1.3.0' ? 'i' : 'x'] = point.x; params[params.version === '1.3.0' ? 'j' : 'y'] = point.y; return wmsLayer._url + L.Util.getParamString(params, wmsLayer._url, true); } </script> </body> </html>