Initializing...
Liveweave
expand_more
home
Home
data_object
CSS Explorer
arrow_outward
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
outbox_alt
Generative AI
arrow_outward
build
Tools
expand_more
restart_alt
Load base template
post_add
Generate Lorem ipsum...
code
Format HTML
code_blocks
Format CSS
data_object
Format JavaScript
library_add
Library
expand_more
A
Algolia JS
Animate CSS
Apex Charts JS
B
Bulma CSS
Bootstrap
C
Chart JS
Chartist
Create JS
D
D3
Dojo
F
Foundation
Fullpage JS
G
Granim JS
Google Charts
H
Halfmoon
J
jQuery
M
Materialize
Moment JS
Masonry JS
Milligram CSS
P
Pure CSS
Primer CSS
Popper JS
Pattern CSS
Picnic CSS
R
React JS
Raphael JS
Raisin CSS
S
Semantic UI
Skeleton CSS
Spectre CSS
Tachyons CSS
T
Tailwind
Three JS
U
UI Kit
Vis JS
W
Water CSS
download
Download
expand_more
developer_mode
Download as HTML
folder_zip
Download as .ZIP
cloud_upload
Save
account_circle
Login
settings
Settings
expand_more
14
px
Live mode
Night mode
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
<! DOCTYPE html> <html> <head> <!-- En primer lugar, cargamos la librerÃa y su hoja de estilos --> <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" /> <script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script> </head> <body> <!-- Luego creamos el div donde se cargará el mapa --> <div id="map"></div> </body> </html>
/* Aquà incorporamos el estilo del mapa */ #map { height: 380px; width: 100%;}
// Inicializamos el maapa, definiendo el tipo "map", las coordenadas de visualización, y el nivel de zoom var map = L.map('map').setView([51.505, -0.09], 13); //Ahora, creamos una capa llamando a la librerÃa de Leaflet, en la que cargamos, mediante la API de MapBox, una visualización de un mapa concreto. Se pasa el ID del mapa mediante el "access_token". La relación de números es el ID del mapa en Mapbox. Definimos el nivel de zoom, los créditos del mapa L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpandmbXliNDBjZWd2M2x6bDk3c2ZtOTkifQ._QA7i5Mpkd_m30IGElHziw', { maxZoom: 18, attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' + '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' + 'Imagery © <a href="http://mapbox.com">Mapbox</a>', id: 'mapbox.streets' }).addTo(map); // Ahora añadimos elementos sobre el mapa. Primero un marcador, luego un cÃrculo y, por último, un polÃgono. L.marker([51.5, -0.09]).addTo(map) .bindPopup("<b>Hola clase</b><br />Soy un popup.").openPopup(); L.circle([51.508, -0.11], 500, { color: 'red', fillColor: '#f03', fillOpacity: 0.5 }).addTo(map).bindPopup("I am a circle."); L.polygon([ [51.509, -0.08], [51.503, -0.06], [51.51, -0.047] ]).addTo(map).bindPopup("I am a polygon."); // Ahora establecemos la interactividad con los elementos, para definir qué evento lanza los popup y cómo var popup = L.popup(); function onMapClick(e) { popup .setLatLng(e.latlng) .setContent("Las coordenadas de este lugar son " + e.latlng.toString()) .openOn(map); } map.on('click', onMapClick);