|
1 |
| -var map = L.map('map'), |
2 |
| - realtime = L.realtime('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson', { |
| 1 | +function createRealtimeLayer(url, container) { |
| 2 | + return L.realtime(url, { |
3 | 3 | interval: 60 * 1000,
|
4 | 4 | getFeatureId: function(f) {
|
5 |
| - return f.properties.url; |
| 5 | + return f.properties.url; |
6 | 6 | },
|
7 | 7 | cache: true,
|
8 |
| - container: L.markerClusterGroup(), |
| 8 | + container: container, |
9 | 9 | onEachFeature(f, l) {
|
10 |
| - l.bindPopup(function() { |
11 |
| - return '<h3>' + f.properties.place + '</h3>' + |
12 |
| - '<p>' + new Date(f.properties.time) + |
13 |
| - '<br/>Magnitude: <strong>' + f.properties.mag + '</strong></p>' + |
14 |
| - '<p><a href="' + f.properties.url + '">More information</a></p>'; |
15 |
| - }); |
| 10 | + l.bindPopup(function() { |
| 11 | + return '<h3>' + f.properties.place + '</h3>' + |
| 12 | + '<p>' + new Date(f.properties.time) + |
| 13 | + '<br/>Magnitude: <strong>' + f.properties.mag + '</strong></p>' + |
| 14 | + '<p><a href="' + f.properties.url + '">More information</a></p>'; |
| 15 | + }); |
16 | 16 | }
|
17 |
| - }).addTo(map); |
| 17 | + }); |
| 18 | +} |
| 19 | + |
| 20 | +var map = L.map('map'), |
| 21 | + clusterGroup = L.markerClusterGroup().addTo(map), |
| 22 | + subgroup1 = L.featureGroup.subGroup(clusterGroup), |
| 23 | + subgroup2 = L.featureGroup.subGroup(clusterGroup), |
| 24 | + realtime1 = createRealtimeLayer('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson', subgroup1).addTo(map), |
| 25 | + realtime2 = createRealtimeLayer('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson', subgroup2); |
18 | 26 |
|
19 | 27 | L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
20 | 28 | attribution: '© <a href="https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php">USGS Earthquake Hazards Program</a>, © <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
21 | 29 | }).addTo(map);
|
22 | 30 |
|
23 |
| -realtime.once('update', function() { |
24 |
| - map.fitBounds(realtime.getBounds(), {maxZoom: 3}); |
| 31 | +L.control.layers(null, { |
| 32 | + 'Earthquakes 2.5+': realtime1, |
| 33 | + 'All Earthquakes': realtime2 |
| 34 | +}).addTo(map); |
| 35 | + |
| 36 | +realtime1.once('update', function() { |
| 37 | + map.fitBounds(realtime1.getBounds(), {maxZoom: 3}); |
25 | 38 | });
|
0 commit comments