Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
OpenLayers 3 - Terremotos recientes USGS
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Ejemplo sencillo con OL3</title>
<link href="|Dosis:400,800" rel="stylesheet" type="text/css" />
<!-- Versión específica vs. master | min vs. debug -->
<link rel="stylesheet" href="" type="text/css">
<script src=""></script>
/* General */
h1 {
font-family: 'Dosis', sans-serif;
font-weight: 400;
font-size: 40px;
line-height: 46px;
margin-bottom: 10px;
color: #E50275;
body {
font-family: 'Open Sans', sans-serif;
background-color: #F7FBFF;
.ficha {
color: #03A1C4;
<h1>Mapa de terremotos significativos el último mes (USGS)</h1>
<div id="mapa" style="height: 400px; border: 2px gray solid;"></div>
<div id="seleccion" style="margin-top:10px"></div>
<!-- JavaScript -->
var mapa = new ol.Map({
layers: [new ol.layer.Tile({
source: new ol.source.OSM()
target: 'mapa',
view: new ol.View({
center: [0, 0],
zoom: 2
mapa.addControl(new ol.control.OverviewMap());
// carga de datos
var urlTerremotos = '';
var capaTerremotos = new ol.layer.Vector({
source: new ol.source.Vector({
url: urlTerremotos,
format: new ol.format.GeoJSON()
// interacción capa vectorial
var seleccion = new ol.interaction.Select();
seleccion.on('select', function (e) {
// ol.interaction.SelectEvent
var div = document.getElementById('seleccion');
var seleccionados =;
var html = '';
seleccionados.forEach(function (t) {
html += '<div class="ficha"><ul>';
html += '<li><strong>Lugar</strong>: ' + t.get('place') + '</li>';
html += '<li><strong>Magnitud</strong>: ' + t.get('mag') + '</li>';
html += '<li><strong>Fecha</strong>: ' + new Date(t.get('time')).toLocaleDateString() + '</li>';
html += '</ul></div>';
div.innerHTML = html;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.