Readme
Get IMD Warning for a location ( actually of the district the location belongs to). Go to the blog post below for all the details.
Blog: https://thejeshgn.com/2024/09/11/simple-imd-alerts/
Credit : https://mausam.imd.gov.in/responsive/subDivisionWiseWarningGIS.php
- HTML - https://thejeshgn-imd_distrcitwise_warnings.web.val.run/?lat=12.9796&lon=77.5906&format=html
- JSON - https://thejeshgn-imd_distrcitwise_warnings.web.val.run/?lat=12.9796&lon=77.5906&format=json
- lat = latitude
- lon = longitude
- format = html or json
defaults
- If no lat or lon given, it will take bangalore's.
- defaults : If no format is given then it is html
- Bangalore, KA https://thejeshgn-imd_distrcitwise_warnings.web.val.run/?lat=12.9796&lon=77.5906
- Thrissur, KL https://thejeshgn-imd_distrcitwise_warnings.web.val.run/?lat=10.527611&lon=76.214389
- Lalitpur, UP https://thejeshgn-imd_distrcitwise_warnings.web.val.run/?lat=24.6936599&lon=78.412621
- Vishisha, MP https://thejeshgn-imd_distrcitwise_warnings.web.val.run/?lat=23.5210259&lon=77.809569
Code
HTTP
// bangalore https://thejeshgn-imd_distrcitwise_warnings.web.val.run/?lat=12.9796&lon=77.5906
// lalitpur up https://thejeshgn-imd_distrcitwise_warnings.web.val.run/?lat=24.6936599&lon=78.412621
// vishisha MP https://thejeshgn-imd_distrcitwise_warnings.web.val.run/?lat=23.5210259&lon=77.809569
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
const lat = parseFloat(url.searchParams.get("lat") || "12.9796");
const lon = parseFloat(url.searchParams.get("lon") || "77.5906");
const format = url.searchParams.get("format") || "html";
// 1 degree of latitude is roughly 111 kilometers
const latOffset = 0.0045; // ~500 meters
// Adjust the longitude offset by the latitude's cosine to account for the Earth's curvature
const lonOffset = latOffset / Math.cos(lat * (Math.PI / 180));
const minLat = lat - latOffset;
const minLon = lon - lonOffset;
const maxLat = lat + latOffset;
const maxLon = lon + lonOffset;
const bbox = minLon + "," + minLat + "," + maxLon + "," + maxLat;
// crude hack but works for now
const now = new Date();
const utcOffset = 5.5 * 60; // IST is UTC+5:30
const istDate = new Date(now.getTime() + utcOffset * 60 * 1000);
// const today = istDate.toISOString();
const today = istDate.toISOString().replace("Z", "+05:30");
const osmand_web = "http://osmand.net/go.html?z=16&lat=" + lat + "&lon=" + lon;
const gmaps_poi = "https://www.google.com/maps?&hl=en&t=m&z=12&ll=" + lat + "," + lon + "&q=" + lat + "," + lon;
const osm = "http://www.openstreetmap.org/?&zoom=16&layers=M&mlat=" + lat + "&mlon=" + lon;
const geo_uri = "geo:" + lat + "," + lon;
const dist_nowcast_warnings =
"https://reactjs.imd.gov.in/geoserver/imd/wms?service=WMS&request=GetMap&layers=imd%3ANowcast_StateDistrict_Merged&styles=&format=image%2Fsvg&transparent=true&version=1.1.1&width=256&height=256&srs=EPSG%3A4326&bbox="
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
thejeshgn-imd_distrcitwise_warnings.web.val.run
Updated: September 11, 2024