-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeonames-terremoto.html
126 lines (105 loc) · 4.3 KB
/
geonames-terremoto.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<html>
<head lang="es">
<title>GeoNames</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.js"></script>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
}
#map {
height: 100%;
width: 100%;
}
#ventana {
position: absolute;
top: 100px;
left: 10px;
z-index: 1000;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var terremotoPunto = null;
var map;
$(document).ready(function () {
map = L.map("map", {
attributionControl: false,
zoom: 8,
center: [42, 2]
});
L.tileLayer('//{s}.tile.stamen.com/toner-lite/{z}/{x}/{y}.png', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
subdomains: 'abcd',
maxZoom: 17,
minZoom: 2
}).addTo(map);
function peticionTerremotos() {
var peticion = 'http://api.geonames.org/earthquakesJSON?' +
'north=' + map.getBounds()._northEast.lat + '&' +
'south=' + map.getBounds()._southWest.lat + '&' +
'east=' + map.getBounds()._northEast.lng + '&' +
'west=' + map.getBounds()._southWest.lng + '&' +
'maxRows=50&' +
'username=masterupc&';
$.ajax({
url: peticion,
method: "GET",
dataType: "jsonp",
success: function (respuesta) {
respuestaTerremotos(respuesta);
}
}); //fin ajax
} //fin peticion
function respuestaTerremotos(respuesta) {
if (respuesta == null) {
return;
} else {
if (terremotoPunto) {
map.eachLayer(function (layer) {
if (layer._radius) {
map.removeLayer(layer);
}
});
}
var total_terremotos = respuesta.earthquakes;
for (var i = 0; i < total_terremotos.length; i++) {
var terremoto = total_terremotos[i];
var aspectos = lookTerremoto(terremoto.magnitude);
console.info(aspectos);
terremotoPunto = new L.circleMarker([terremoto.lat, terremoto.lng], {
radius: aspectos.radio,
fillColor: aspectos.color,
color: "#ff0000",
weight: 2,
opacity: 1,
fillOpacity: 0.8
});
terremotoPunto.bindPopup("Mg:" + terremoto.magnitude + "<br>" + terremoto.datetime);
terremotoPunto.addTo(map);
}
}
} //Fin respuesta terremotos
peticionTerremotos();
map.on('moveend', function () {
peticionTerremotos();
});
function lookTerremoto(magnitude) {
var opciones = { "radio": parseInt(magnitude * 2), "color": "#ff0000" };
if(parseInt(magnitude * 2) >= 14){
opciones.radio = 25;
opciones.color = "#0000ff";
}
return opciones;
}//fin de funcion lookTerremoto
}); //fin document ready
</script>
</body>
</html>