Skip to content

Commit

Permalink
refactor: report
Browse files Browse the repository at this point in the history
  • Loading branch information
whes1015 committed Jul 25, 2023
1 parent 7766f65 commit 580c1a3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/core/index/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ function intensity_float_to_int(float) {
return (float < 0) ? 0 : (float < 4.5) ? Math.round(float) : (float < 5) ? 5 : (float < 5.5) ? 6 : (float < 6) ? 7 : (float < 6.5) ? 8 : 9;
}

function intensity_string_to_int(string) {
return (string == "0") ? 0 : (string == "1") ? 1 : (string == "2") ? 2 : (string == "3") ? 3 : (string == "4") ? 4 : (string == "5-") ? 5 : (string == "5+") ? 6 : (string == "6-") ? 7 : (string == "6+") ? 8 : 9;
}

function check_update() {
if (update) return;
const controller = new AbortController();
Expand Down Expand Up @@ -79,7 +75,7 @@ async function fetch_trem_eq(id) {
controller.abort();
}, 2500);
return await new Promise((c) => {
fetch(`https://exptech.com.tw/api/v1/file/trem_report/${id}.json`, { signal: controller.signal })
fetch(`https://exptech.com.tw/api/v1/earthquake/trem-info/${id}`, { signal: controller.signal })
.then((ans) => ans.json())
.then((ans) => {
c(ans);
Expand Down Expand Up @@ -559,11 +555,21 @@ async function report_report(info) {
if ((storage.getItem("report_show_trem") ?? false) && trem_eq)
if (trem_eq && Object.keys(station).length) {
const trem_eq_list = trem_eq.station;
const epicenterIcon_trem = L.icon({
iconUrl : "../resource/images/cross_trem.png",
iconSize : [30, 30],
});
if (TREM.report_epicenterIcon_trem) TREM.report_epicenterIcon_trem.remove();
const trem_eew = trem_eq.trem.eew[trem_eq.trem.eew.length - 1];
TREM.report_epicenterIcon_trem = L.marker([trem_eew.lat, trem_eew.lon],
{ icon: epicenterIcon_trem, zIndexOffset: 6000 })
.bindTooltip(`<div class='report_station_box'><div>報數: 共 ${trem_eq.trem.eew.length} 報</div><div>位置: ${trem_eew.location} | ${trem_eew.lat}°N ${trem_eew.lon} °E</div><div>類型: ${trem_eew.model}</div><div>規模: M ${trem_eew.scale}</div><div>深度: ${trem_eew.depth} km</div><div>預估最大震度: ${int_to_intensity(trem_eew.max)}</div></div>`, { opacity: 1 })
.addTo(TREM.Maps.main);
for (let i = 0; i < trem_eq_list.length; i++) {
const uuid = trem_eq_list[i].uuid.split("-")[2];
if (!station[uuid]) continue;
const _info = station[uuid];
const station_Intensity = intensity_string_to_int(trem_eq_list[i].intensity);
const station_Intensity = trem_eq_list[i].intensity;
const icon = (station_Intensity == 0) ? L.divIcon({
className : "pga_dot dot_max pga_intensity_0",
html : "<span></span>",
Expand Down
1 change: 1 addition & 0 deletions src/core/index/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ function draw_intensity(skip) {

function report_off() {
if (TREM.report_epicenterIcon) TREM.report_epicenterIcon.remove();
if (TREM.report_epicenterIcon_trem) TREM.report_epicenterIcon_trem.remove();
delete TREM.report_epicenterIcon;
for (let i = 0; i < Object.keys(TREM.report_icon_list).length; i++) {
const key = Object.keys(TREM.report_icon_list)[i];
Expand Down
Binary file added src/resource/images/cross_trem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 580c1a3

Please sign in to comment.