WXforum.net

Web Weather => Weather Website PHP/AJAX scripting => Topic started by: saratogaWX on May 14, 2019, 11:54:39 AM

Title: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: saratogaWX on May 14, 2019, 11:54:39 AM
I've updated Curly's nws-alerts V1.42 package to use Leaflet/OpenStreetMaps instead of Google maps, so no API key is needed anymore.  Support for optional Mapbox.com API key is provided.

The Saratoga Base-USA template was updated, so use the update tool (https://saratoga-weather.org/wxtemplates/updates.php) with a query of Base-USA, Plugin-*, 14-May-2019.

The standalone script set was also updated on the legacy scripts page (https://saratoga-weather.org/scripts-legacy.php) and I've attached a small zip with the changed files.  (note that nws-alerts.php V1.43 is only a version rev from V1.42).

Also the full script set is available on my GitHub distribution (https://github.com/ktrue/NWS-alerts)
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: wvdkuil on May 14, 2019, 12:23:07 PM
As always, thanks  [tup]
Wim
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: gwwilk on May 15, 2019, 12:30:08 AM
Great job, as usual!  Thanks, Ken. [tup] =D>
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: gwwilk on May 15, 2019, 08:45:04 AM
A little glitch here with xhtml validation (https://validator.w3.org/check?uri=https%3A%2F%2Fwww.gwwilkins.org%2Fwxnws-details.php%3Fa%3DNEZ067;accept=text%2Fhtml%2Capplication%2Fxhtml%2Bxml%2Capplication%2Fxml%3Bq%3D0.9%2Cimage%2Fwebp%2Cimage%2Fapng%2C%2A%2F%2A%3Bq%3D0.8%2Capplication%2Fsigned-exchange%3Bv%3Db3;accept-language=en-US%2Cen%3Bq%3D0.9).

There's probably a simple fix, but it's beyond my ken, Ken.  :-)
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: saratogaWX on May 15, 2019, 10:47:55 AM
Ahh.. the validator was parsing the HTML inside the <script>...</script>

I've added
Code: [Select]
<script>
// <![CDATA[ 

...

// ]]>
</script>
to have the parser stop trying to do that and become annoyed :)

Try the attached replacement.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: saratogaWX on May 15, 2019, 10:59:50 AM
I've pushed that change to the Base-USA template, the Legacy-scripts and the GitHub distributions.  Thanks for spotting that omission.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: txweather.org on May 15, 2019, 11:09:25 AM
Thanks Ken!
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: gwwilk on May 15, 2019, 11:12:53 AM
I had already corrected another little glitch with this addition of 'type' to the javascript call:
Code: [Select]
$leafletScript = '<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.js" type="text/javascript"></script>'."\n";Again the validator for xhtml complained about this omission which is useless these days, really.

Thanks, Ken!  I had no idea what to do, but the CDATA exclusion is perfect.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: Jasiu on May 15, 2019, 11:19:59 AM
Again the validator for xhtml complained about this omission which is useless these days, really.

Yup. And it is no longer necessary in HTML5.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: saratogaWX on May 15, 2019, 11:26:33 AM
Ahh... for XHTML, it's needed.  HTML5 not needed.  Since the templates use XHTML 1.0 Transitional, I've added that to the script.. thanks again.

BTW, it was an interesting challenge to modify Curly's original Google map script to do Leaflet instead .. a bit of somewhat convoluted PHP to generate the inline script only if the alert had geo-coordinates present, and quite a change in the generated JavaScript to control Leaflet due to differently named/accessed Leaflet functions v.s. Google maps functions.

Posted in the usual places...
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: tmabell on May 21, 2019, 08:22:00 AM
Quick question Ken, doe the latest version still support "Filtered Events" or was that feature removed?  I ask because I did not see the necessary files in your GitHub distribution package.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: saratogaWX on May 21, 2019, 10:34:19 AM
All the filtering features from Curly's 1.42 version are still there .. I only replaced the Google map with the Leaflet map generation.

What was missing in the GitHub package??  I may have skipped something when packaging it for GitHub.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: tmabell on May 21, 2019, 10:52:27 AM
If you need these file I will forward them to you but these are needed in order to configure the filters:

nws-alerts-events.php
nws-alerts-filter-config.php
nws-alerts-filtering.php

Thank you for keeping these old scripts alive!
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: mldenison on May 21, 2019, 10:54:56 AM
Hey Ken,

The new version is working fine on my PC.

The 'check-fetch-times.php' has an 'unknown' for 'nws-alerts.css':

Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: saratogaWX on May 21, 2019, 11:09:04 AM
If you need these file I will forward them to you but these are needed in order to configure the filters:

nws-alerts-events.php
nws-alerts-filter-config.php
nws-alerts-filtering.php

Thank you for keeping these old scripts alive!

Yes, please .zip and send me those files... I see the .zip and GitHub only have ./cache/nws-alerts-filters.php in it.. the other files you cited are not there.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: saratogaWX on May 21, 2019, 11:10:13 AM
Hey Ken,

The new version is working fine on my PC.

The 'check-fetch-times.php' has an 'unknown' for 'nws-alerts.css':


I'll check.. I think maybe the versioning info is not in the CSS file.  Thanks...
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: saratogaWX on May 21, 2019, 12:34:19 PM
Hey Ken,

The new version is working fine on my PC.

The 'check-fetch-times.php' has an 'unknown' for 'nws-alerts.css':

Ahh... I discovered there was some missing code to have the .css files version info included in the version-list.  I've updated that (and check-fetch-times.php V1.27 also) so the versioning on .css scripts needed are now included in the display.
Pushed Version 3.292 - 21-May-2019 (Base-*) updated check-fetch-times.php V1.27 for .css file version checking
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: mldenison on May 21, 2019, 01:21:01 PM
Works great, Ken.  Thanks for the quick update!
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: mikeym2m on May 24, 2019, 09:16:00 AM
Thanks Ken

Worked Great last night with the "Special Weather Statement", "Severe Thunderstorm Warning" and "Tornado Warning" all showing correctly.  [tup]

Cheers

 :-)

MikeyM
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: tshattuck on May 27, 2019, 11:12:16 AM
Ken:
I noticed in your posts here you mention MapBox is optional. I don't have an API Key for MapBox what happens if I don't have API key?

Thanks
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: Otis on May 27, 2019, 11:46:33 AM
I believe it just eliminates the mapbox map display options like satellite.  I don't think it will effect the performance of the script.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: Jasiu on May 27, 2019, 12:23:44 PM
Ken:
I noticed in your posts here you mention MapBox is optional. I don't have an API Key for MapBox what happens if I don't have API key?

Thanks

The default behavior is to use the Esri_WorldTopoMap, tiles which needs no key. You only need the Mapbox key if you want to use Mapbox tiles.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: tshattuck on May 27, 2019, 08:27:37 PM
I will go without the API Key based on your comments. I want to keep it simple.
Thanks for the feedback.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: Otis on May 27, 2019, 09:23:27 PM
Just to be clear, I never said not to get the API Key, just that you don't need one for the script.
I do have one, the key.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: mldenison on May 27, 2019, 09:38:06 PM
I added my (unused) mapbox api key.  Everything still looks the same.  Anybody want to share a link to their page that uses mapbox?  Thanks.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: txweather.org on May 28, 2019, 12:08:46 AM
I added my (unused) mapbox api key.  Everything still looks the same.  Anybody want to share a link to their page that uses mapbox?  Thanks.

It will only show the map if the  alert includes location code. IE: It shows the map for an alert in Houston but not in Galveston and that's because the location code only came with the Houston alert.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: Jasiu on May 28, 2019, 08:15:45 AM
Anyone can check out other map options... you do need a key for the Mapbox tiles.

Edit nws-alerts-config.php, around line 100 or so:

Code: [Select]
$mapProvider = 'Esri_WorldTopoMap'; // ESRI topo map - no key needed
//$mapProvider = 'OSM';     // OpenStreetMap - no key needed
//$mapProvider = 'Terrain'; // Terrain map by stamen.com - no key needed
//$mapProvider = 'OpenTopo'; // OpenTopoMap.com - no key needed
//$mapProvider = 'Wikimedia'; // Wikimedia map - no key needed
//
//$mapProvider = 'MapboxSat';  // Maps by Mapbox.com - API KEY needed in $mapboxAPIkey
//$mapProvider = 'MapboxTer';  // Maps by Mapbox.com - API KEY needed in $mapboxAPIkey

###   END OF SETTINGS   ###

Just un-comment (get rid of the leading "//") the line you want to try and upload the file. If you decide you don't like that, put the "//" back.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: saratogaWX on May 28, 2019, 10:01:59 AM
Ken:
I noticed in your posts here you mention MapBox is optional. I don't have an API Key for MapBox what happens if I don't have API key?

Thanks

A MapBox key just enables two additional maps, another Terrain and a Satellite map for display.  Totally optional, and if you don’t have a key, the options for those additional map tiles will not be shown in the map type selection box.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: tshattuck on May 28, 2019, 10:10:56 AM
Ken:
Thanks for the clarification. It helps a lot.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: yamiacaveman on May 28, 2019, 04:57:50 PM
Hi Ken,

Just to be clear, the map will only show up when a warning is issued and the map does not show when a watch is issued. Or did I miss a setting?

yamiacaveman


pennlake.us
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: mldenison on May 28, 2019, 05:51:32 PM
It's working.  No map with Watch.  We're now under a Warning and the MapBox map shows up in the Warning.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: saratogaWX on May 28, 2019, 06:08:01 PM
In my experience with testing the scripts, the County Zone is the one that carries the geo info to outline on the map for Watch and Warning (not all Watches, though).  The Forecast Zone rarely caries geo info in my experience.  If an alert contains geo info, then the map will appear.. no geo info in the collection of alerts results in no map display with the detail page.
Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: Jasiu on May 28, 2019, 06:49:31 PM
Some alerts that I've seen with geo info and the type of NWS code included:

Title: Re: nws-alerts.php V1.43 with Leaflet/OpenStreetMap now available
Post by: yamiacaveman on May 28, 2019, 09:49:38 PM
Gotcha, thanks all.