The scripts referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular weather station website. A RSS Feed is available to help keep you informed on updates to the scripts.
A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier.
Announcements of version updates and new scripts are made on
WXForum.net and
Weather-Watch forums
and saratogaWXPHP Twitter account as they become available.
Note: Twitter widget has been disabled 3-Jul-2023 since it no longer displays the recent update Tweets.
This page was updated
Thursday, 01-Sep-2022 8:42 AM
Regional Mesonet Map Display
The Affiliated Regional Weather Networks have been quite popular, and now it is possible for you to add a Leaflet map display of conditions from your network to your own website. We do prefer that the script(s) be used by members who contribute their data to a Regional Weather Network. Version 4.x of the script no longer uses Google Maps, but uses Leaflet/OpenStreetMaps for display and no longer requires an API key or Access Token for operation with the free maps included. Version 4.x also allows Mapbox maps with a Mapbox API key to be used..
This script set is intended to replace the V2.x [netID]-mesomap.php script for Regional Network members and provides multiple language support for Standalone or Saratoga Template use.
Here's a sample of the display:
SWN
Temperature [ F° ]Dew Point [ F° ]Humidity [ % ]Wind [ mph ]Rain Today [ in ]Pressure [ inHg ]Fire Danger [Chandler Burning Index]
My thanks to Wim van der Kuil of Leuven Templates for the idea to use the tabbed presentation to separate the map/conditions/stations displays.
Short history of the [netID]-mesomap.php software
The V0.x version of the mesonet map for the Southwestern network used a map graphic and each station in the network
published a bit of HTML with conditions that were rotated by a common JavaScript.
The system became unmanagable as more stations entered the network, and the conditions
rotated on the map in an unsyncronized manner. Not very satisfying.
The V1.x version used a PHP script to run on each member website (when the page was viewed)
that did a quick pull of conditions from each member station, then displayed the result
on a dynamically created static map with rotating conditions displayed for each station.
As the network grew to above 20 stations, this proved unworkable as the fetch-time for conditions
from each station was added to the page-load time and times of 40+ seconds were observed
on a good day. So.. back to the drawing board.
The V2.x version used the map/data display of the 1.x version, but a new 'Regional Hub' website was
created and a cron job run to collect the data from each station and save it in a text file.
The member stations would read that text file (fast) and produce the map/data table quickly now
that the fetch-time had been 'offloaded' to the server. The member station would only fall-back
to collecting data individually from each site if the 'Regional Hub' site was unavailable, or the data
more than one hour old.
The V2.x version also added in multi-language support for displays. A separate language translation
mechanism was used so the resulting mesonet map could run in any PHP-based website.
Now V3.x version has some fundamental changes from the prior versions:
The map display is based on Google Maps, JavaScript and the Latitude/Longitude of the member
station to place the pin on the map. This is a both good and bad news. The good news is
that Regional Networks that adopt the V3.x software do not have to fuss about with manually
placing a pin on an image to add or remove a station. The bad news is that without JavaScript,
no map will be displayed (the V2.x version would display a map and temperature without JavaScript).
But.. the web seems bent on doing mostly everything using JavaScript, so here we go.
The code to fetch data directly from member stations has been removed. The V3.x map relies
on having the Regional Hub site for availability. It does cache the configuration and data files
every 5 minutes and will display what it last received. If the Regional Hub is unavailable
for an extended period, the member maps will show stale data until the Regional Hub is working
again.
The regional networks definition file is also downloaded routinely, so as networks come/go/change,
the mesonet-map will adapt. If an existing network is removed from the Global nets, then an
error message will be displayed instead of the map, and a new network can be picked from
the cache/mesonet-map-networks.txt file. We've only had 3 networks drop out in 8+ years.
Yes, I know the code is a bit of a mess.. it has been growing 'organically' for 8 years.
I did some refactoring with variable names and separation of functions from merging two
sets of code: the [netID]-mesomap.php and the global-map.php code based. I figure I've
been fiddling with this over two years in low priority, so it's time to get it done and
declare V3.0 released. I hope you enjoy!
Version 4.x has even more fundamental changes from prior versions:
The script now uses Leaflet V1.3.1 JavaScript library and open source map providers instead of a Google for map displays, so no API key is needed for the basic maps.
Support is provided for Mapbox.com maps which will be automatically enabled if you specify a Mapbox API key in the mesonet-map-settings.php file (or in Settings.php for Saratoga templates).
The Leaflet code seems to be much faster in rendering the maps and markers than the older Google-based code (bonus!)
A downside of using non-Google maps is that (for the most part) the map legends for countries/cities/names are all shown in English only.
The OpenStreetMap does show country names/cities in the native language of the country on the map, but the other maps are English names only. The translation files included do handle the legend/marker/popup language content translation as did the V3.x version of the scripts.
Additional new features added in Version 4.00 include:
Right-click context menu for map that will display the lat/long of the point, the settings needed to configure that map view as a default, center the map, zoom in and zoom out. The settings needed has the three key variables (zoom, center and clusterRadius) used to make that map be the default view.
Stations that are 'Offline' (no current conditions within one hour) no longer show a label / rotating legend.
A configuration option to set the clustering behavior is now available--you can choose to more agressively cluster markers to create a less cluttered map display.
Package contents:
mesonet-map-README.txt
Text document with background, package information and install/configuration information
mesonet-map.php
standalone script to display the mesonet map
wxmesonetmap.php
Saratoga template page to display the mesonet map
mesonet-map-settings.php
control file for the default map displays - this is the file you customize (see below)
mesonet-map.css
CSS definitions for map
mesonet-map.js
supporting JavaScripts for map
mesonet-map-inc.php
main code script - included by the mesonet-map.php or wxmesonetmap.php
mesonet-map-common.php
support script - common loading functions
mesonet-map-genhtml-inc
support script - generate HTML for conditions table and member features list
mesonet-map-genjs-inc
support script - generate main JavaScript for Google Map markers+labels
mesonet-map-json.php
convert control and conditions files to JSON format for data display
mesonet-map-check-versions.php
Utility program to check the installed v.s. currently distributed versions for key files. (new with V3.02)
mesonet-map-lang-[LL].txt
language files [LL] is the ISO 639-1 2-character language
abbreviations from country domain
MESO-images/*.jpg *.gif *.png
images for display. Same as the global-map script set (with some additions)
The following files are downloaded as needed and cached in the ./cache/ directory:
cache/mesonet-map-networks.txt
regional networks specs
downloaded from northamericanweather.net global site
cache/[netID]-stations-cc.txt
regional network station list
downloaded from the [netID] regional hub site
cache/[netID]-conditions.txt
regional network conditions
downloaded from the [netID] regional hub site
Installation/Configuration
OPTIONAL: In order to use the two Mapbox maps, you must register. You can get map ID and ACCESS_TOKEN from:
If you're using wxmesonetmap.php in the Saratoga template, put a line in the site
Settings.php in a convenient area (likely near the WeatherUnderground spec) saying
The most important settings are for the default network (by Network ID) and the default language to use:
Standalone (in mesonet-map-settings.php):
$rmNETID = 'SWN'; // default Regional Network ID -- must be one of the defined networks
$lang = 'en'; // default language
Saratoga template (in Settings.php):
$SITE['rmNETID'] = 'SWN';
$SITE['lang'] = 'en';
Look in the cache/mesonet-map-networks.txt file. The first entry in each line (without a #)
is the [netID] to use for your selected network.
See below for a current list of languages supported.
Example: you want the Benelux network with Dutch as the default language
Standalone (in mesonet-map-settings.php):
$rmNETID = 'BNLWN'; // default Regional Network ID -- must be one of the defined networks
$lang = 'nl'; // default language
Saratoga template (in Settings.php):
$SITE['rmNETID'] = 'BNLWN';
$SITE['lang'] = 'nl';
Example: you want the Czech Republic network with Czech as the default language
Standalone (in mesonet-map-settings.php):
$rmNETID = 'CZWN'; // default Regional Network ID -- must be one of the defined networks
$lang = 'cs'; // default language
Saratoga template (in Settings.php):
$SITE['rmNETID'] = 'CZWN';
$SITE['lang'] = 'cs';
Save the mesonet-map-settings.php (Standalone) or Settings.php (Saratoga template) after editing.
Upload the contents to your site, including the cache/ and MESO-images/ directories.
If your site already has a MESO-images/ directory from installation of the global-map software, you can safely replace it with the contents of this set.
During normal operation, some files from the Affiliated Regional Weather Networks home site and from the selected Regional Network will be cached locally on your website in the ./cache/ directory (default). These files are:
mesonet-map-networks.txt
[netID]-stations-cc.txt
[netID]-conditions.txt
The files will be stored in the ./cache/ directory (default) and refreshed every 5 minutes as needed from the Global site and the selected Regional Network website. If for some reason, the Global or the selected Regional Network site is unavailable, the cached copies will be used to render the map displays, and will 'catch up' when the offline site becomes available again.
There are other settings available in the mesonet-map-settings.php (and available as corresponding $SITE[...] entries in the Saratoga template's Settings.php) in case you want to change the default map zoom/center, map type, or tweak the initial displayed units for your default rmNETID. When someone uses the Regional Networks TAB to select a different network, then the defaults for that network's map/units will be used. The overrides only apply to the one network you specify in rmNETID.
If you are using the Saratoga template, I recommend you do the $SITE[...] entries in Settings.php instead of changing the mesonet-map-settings.php -- it will allow you to quickly replace scripts as updates occur in the future.
Script Settings
The following mesonet-map-settings.php and corresponding Settings.php equivalents which override the values in mesonet-map-settings.php are available:
$rmNETID or $SITE['rmNETID']; }
default Regional Network ID, initial setting is 'SWN' for Southwestern Network. Look in ./cache/mesonet-map-networks.txt for available networks, or at the Regional Networks TAB on mesonet-map.php/wxmesonetmap.php displayed on your site. The rmNETID is shown in parenthesis after each network's name.
$lang or $SITE['lang']
default language to use, initial setting is 'en' for English.
Script use in wxmesonetmap.php in the Saratoga template will use the current value selected for Language -- you don't have to respecify it here.
$rmMapUseDefaults or $SITE['rmMapUseDefaults']
This switch controls the action of the rmMapType, rmMapZoom and rmMapCenter values: = true; means the built-in map type, zoom and map center for all networks will be used based on selected network. = false; means the map type, map zoom and map center lat/long coordinates specified below will be used for the default rmNETID and the built-in type/zoom/center for other networks.
$rmMapUseUnits or $SITE['rmMapUseUnits']
This switch controls the initial display of weather data in the selected units on the map. It does not change the units displayed in the table in the second Tab -- that is always displayed in the units selected by the Regional Network itself. =true; set display map units to use the Regional Network's units =false; to display the rmNETID map using Temperature, Wind, Barometer, Rain units specified below
$rmProvider or $SITE['rmProvider']
This specifies the default map tile provider to be used. The default is:
$rmProvider = 'Esri_WorldTopoMap'; // ESRI topo map - no key needed
// Additional available maps are (remove // to enable):
//$rmProvider = 'OSM'; // OpenStreetMap - no key needed
//$rmProvider = 'Terrain'; // Terrain map by stamen.com - no key needed
//$rmProvider = 'OpenTopo'; // OpenTopoMap.com - no key needed
//$rmProvider = 'Wikimedia'; // Wikimedia map - no key needed
//$rmProvider = 'MapboxSat'; // Maps by Mapbox.com - API KEY needed in $mapboxAPIkey
//$rmProvider = 'MapboxTer'; // Maps by Mapbox.com - API KEY needed in $mapboxAPIkey
$mapboxAPIkey or $SITE['mapboxAPIkey']
OPTIONAL Mapbox.com API KEY to enable two optional maps for display (Terrain3 and Satellite).
$rmShowFireDanger or $SITE['rmShowFireDanger']
This setting controls the display of the Chandler Burning Index (CBI) on the map, popups and conditions table. =true; Display the CBI level (Low, Moderate, High, Very High, Extreme) as color-coded text. (Default) =false; Do not display the CBI level. Note: the mesonet-map-lang-LL.txt files contain constants for the words to display:
Make changes to the words in the mesonet-map-lang-LL.txt file (and I'd appreciate it if you would send me translation updates).
$rmClusterRadius or $SITE['rmClusterRadius']
Used to control the clustering behavior. The value is the number of pixels between marker locations on the map at the current zoom level. Markers within that number are clustered. The number should be between 5 and 80 (with 80 being agressive clustering behavior).
You can try various numbers on your map by adding cluster=nn argument to the URL to invoke the page where nn=5...80 in value.
(e.g. mesonet-map.php?cluster=15 or mesonet-map.php?net=BNLWN&cluster=15 ). When you like the new clustering value,
make the change to $rmClusterRadius (or $SITE['rmClusterRadius']) to make the change permanent.
$tabHeight
This sets the height of the tabbed display. Default =831 pixels. Set =false; if you do not want the tab height restricted.
$cacheDir or $SITE['cacheFileDir']
relative directory to store the updated conditions/network defs files.
The
initial value is './cache/' (same as Saratoga template)
$condIconsDir or $SITE['condsIconsDir']
Specifies the relative file location for the icons used by the script. Default is './MESO-images/'
$doLinkTarget or $SITE['doLinkTarget']
Specifies to make links in the pages with target="_blank" or not: =true; (default) add target="_blank" to URLs =false; do not add target="_blank" to URLs
$rmTempUOM or $SITE['rmTempUOM']
Specifies unit of measure for Temperature ='C' - Centigrade ='F' - Fahrenheit
$rmWindUOM or $SITE['rmWindUOM']
Specifies unit of measure for Wind Speed ='mph', - Miles/Hour ='km/h' - Kilometers/Hour ='m/s' - Meters/Second ='kts' - Knots
$rmBaroUOM or $SITE['rmBaroUOM']
Specifies unit of measure for Barometric pressure ='inHg' - inches of mercury ='hPa' - hectopascals ='mb' - millibars
$rmRainUOM or $SITE['rmRainUOM']
Specifies unit of measure for Rain ='in' - inches ='mm' - millimeters
$rmMapCenter or $SITE['rmMapCenter']
This setting is latitude,longitude for initial map center display (in decimal degrees) as a pair of decimal numbers in order of latitude,longitude.
Southern Hemisphere latitudes are negative. Northern Hemisphere are positive (without the +/plus sign).
Western longitudes (West of GMT) are negative. Eastern longitudes are positive (without the +/plus sign) for East of GMT.
$rmMapZoom or $SITE['rmMapZoom']
This setting controls the initial map display zoom level.
Values range from 2=world to 18=city(max zoom in)
Useful tips
Run the page (mesonet-map.php or wxmesonetmap.php) with ?cache=no will cause the cache files to be refreshed.
Run the page (mesonet-map.php or wxmesonetmap.php) with ?debug=yes will show additional debugging information in the view-source of the page.
If you right-click on the map while debug is specified, a pop-up JavaScript alert will display with the current map zoom level, latitude and longitude of the map center. You can use this to customize the presentation of the map for your rmNETID network using the settings above.
With Version 3.02 - 28-Jul-2016 a new utility has been added to help you keep the mesonet-map* script set up-to-date.
Just run mesonet-map-check-versions.php on your website and it will display a report of your current files v.s. the current distribution files so you can easily find/update any files that need updates. See an example here. Run mesonet-map-check-versions.php?force to reload the current distribution file definition file.
For the plugin for the AJAX/PHP multilingual templates (V2 or V3) you may want to add to your language-LL-local.txt files the translations for:
Which will allow for the translation of some headings to language LL. Be sure to use the correct character set for your page to match the other translation files used
by the Multilingual templates. The main translation for various languages is provided in the mesonet-map-lang-LL.txt files.
The mesonet-map scripts support the following languages:
Version 4.09 - 01-Sep-2022 - update mesonet-map-json.php with added fix to reject bad/missing station data
Version 4.08 - 31-Aug-2022 - update mesonet-map-genhtml-inc.php V4.08 to fix errata messages when conditions updated date from station is missing
Version 4.07 - 21-Jan-2022 - replace strftime() calls with new_strftime() for PHP 8.1+
Version 4.06 - 23-Dec-2020 - update mesonet-map-inc.php V4.06 to hide tab contents during page load for better display appearance
Version 4.05 - 04-Feb-2019 - updated mesonet-map-common.php V4.05 to fix issue with HTTP/2 returns from regional networks.
Version 4.04 - 11-Jun-2018 - updated mesonet-map-common.php, mesonet-map-genhtml-inc.php, mesonet-map-json.php to fix deprecated each() calls, correct JSON output/processing and HTML generation
Version 4.03 - 29-May-2018 - updated several .php scripts for timezone processing, updated all mesonet-map-lang-*.txt files to replace a preg_match with 'e' modifier in one function
Version 4.02 - 27-May-2018 - mesonet-map.css V4.02 adjusted z-index values in CSS to better work with Saratoga template flyout-menu set
Version 4.01 - 25-May-2018 - fixed mesonet-map-genjs-inc.php V4.01 to honor $rmProvider default map selection
Version 4.00 - 23-May-2018 - replaced Google Map with Leaflet/OpenStreetMaps functionality - no map key needed!
Version 3.11 - 15-Feb-2018 - force Google Map API to 3.31 to fix breakage with 3.32 (mesonet-map.php, wxmesomap.php)
Version 3.10 - 09-Oct-2017 - more minor fixes for PHP 7.1 compatibility in mesonet-map-common.php
Version 3.09 - 14-Aug-2017 - minor fixes for PHP 7.1 compatibility for conditions data in mesonet-map-common.php
Version 3.08 - 12-Aug-2017 - fixed https for network hubs - use curl for fetching data from networks
Version 3.07 - 07-Apr-2017 - fixed click-on-cluster redisplay issue, use https for Google script access
Version 3.06 - 14-Jan-2017 - corrected scripts for https:// station URL links
Version 3.05 - 29-Nov-2016 - fixed mesonet-map-common.php V3.04 for intermittent -18C dewpt JSON under some conditions
Version 3.04 - 07-Aug-2016 - fixed mesonet-map.js V3.04 for window.onload interference problem in sorttable script
Version 3.03 - 31-Jul-2016 - added Chandler Burning Index (CBI) display to map rotating legends, popups and table (sortable) with new option to enable/disable $rmShowFireDanger/$SITE['rmShowFireDanger']