Skip to content

Commit

Permalink
Station data isn't available for me anymore. Stations are handled pri…
Browse files Browse the repository at this point in the history
…vate now.
  • Loading branch information
buche committed Jan 13, 2018
1 parent f27a84b commit 2803077
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 35 deletions.
32 changes: 12 additions & 20 deletions README.md
Expand Up @@ -3,7 +3,7 @@
## Description
[OpenWeatherMap](https://openweathermap.org/) (OWM) is a service providing weather related data, visualizing it using an OpenLayers based map. This is an independant Leaflet based script providing easy access to OWM's features for Leaflet based maps.

In short: An independant JavaScript library for including OWM's layers and OWM's current city/station data in Leaflet based maps without hassle.
In short: An independant JavaScript library for including OWM's layers and OWM's current city data in Leaflet based maps without hassle.

Feel free to flattr me if you like it: [![alttext](https://button.flattr.com/flattr-badge-large.png)](https://flattr.com/thing/1193685/)

Expand All @@ -16,7 +16,7 @@ This map is available in the example directory, too.
## License

This code is licensed under [CC0](https://creativecommons.org/publicdomain/zero/1.0/ "Creative Commons Zero - Public Domain").
Some files in the example directory may have other licences (e.g. leaflet.js - see leaflet.license, leaflet.markercluster.js - MIT, excanvas.js - Apache license) - please have a look at the files if needed.
Some files in the example directory may have other licences (e.g. leaflet.js - see leaflet.license) - please have a look at the files if needed.

## Using TileLayers

Expand Down Expand Up @@ -49,53 +49,45 @@ Beyond standard options for Leaflet TileLayers there are additional ones:

Out of the box a legend image is only available for Pressure, Precipitation Classic, Clouds Classic, Rain Classic, Snow, Temperature and Wind Speed. Please add your own images if you need some more.

## Using current data for cities and stations
## Using current data for cities

Weather data for cities and stations are fetched using the OpenWeatherMap API. They are added as a LayerGroup of markers, one for cities and another one for stations. These layers can be refreshed every *n* minutes (set *n* with the option *intervall* but do not use less than 10 minutes, please).
Weather data for cities are fetched using the OpenWeatherMap API. They are added as a LayerGroup of markers. This layer can be refreshed every *n* minutes (set *n* with the option *intervall* but do not use less than 10 minutes, please).

### Initialization

Here's how to initialize these dynamically created layers:

* var city = L.OWM.current( /* options */ );
* var station = L.OWM.current({type: 'station' /*, additional options */ });

### Options

A lot of *options* are available to configure the behaviour of the city/station data ( **default value** is bold). But don't be scared about the large number of options, you don't need to set any if you are pleased with the defaults:
A lot of *options* are available to configure the behaviour of the city data ( **default value** is bold). But don't be scared about the large number of options, you don't need to set any if you are pleased with the defaults:

* *appId*: String ( **null** ). Please get a free API key (called APPID) if you're using OWM's current weather data regulary.
* *type*: **'city'** or 'station'. Get city data or station data.
* *lang*: **'en'**, 'de', 'ru', 'fr', 'es', 'ca'. Language of popup texts. Note: not every translation is finished yet.
* *minZoom*: Number ( **7** ). Minimal zoom level for fetching city/station data. Use smaller values only at your own risk.
* *interval*: Number ( **0** ). Time in minutes to reload city or station data. Please do not use less than 10 minutes. 0 no reload (default)
* *minZoom*: Number ( **7** ). Minimal zoom level for fetching city data. Use smaller values only at your own risk.
* *interval*: Number ( **0** ). Time in minutes to reload city data. Please do not use less than 10 minutes. 0 no reload (default)
* *progressControl*: **true** or false. Whether a progress control should be used to tell the user that data is being loaded at the moment.
* *imageLoadingUrl*: URL ( **'owmloading.gif'** ). URL of the loading image, or a path relative to the HTML document. This is important when the image is not in the same directory as the HTML document!
* *imageLoadingBgUrl*: URL ( **null** ). URL of background image for progress control if you don't like the default one.
* *temperatureUnit*: **'C'**, 'F', 'K'. Display temperature in Celsius, Fahrenheit or Kelvin.
* *temperatureDigits*: Number ( **1** ). Number of decimal places for temperature.
* *speedUnit*: **'ms'**, 'kmh' or 'mph'. Unit of wind speed (m/s, km/h or mph).
* *speedDigits*: Number ( **0** ). Number of decimal places for wind speed.
* *popup*: **true** or false. Whether to bind a popup to the city/station marker.
* *popup*: **true** or false. Whether to bind a popup to the city marker.
* *keepPopup*: **true** or false. When true it tries to reopen an already open popup on move or reload. Can result in an additional map move (after reopening the popup) with closing and reopening the popup once again.
* *showOwmStationLink*: **true** or false. Whether to link city/station name to OWM.
* *showOwmStationLink*: **true** or false. Whether to link city name to OWM.
* *showWindSpeed*: 'speed', 'beaufort' or **'both'**. Show wind speed as speed in speedUnit or in beaufort scala or both.
* *showWindDirection*: 'deg', 'desc' or **'both'**. Show wind direction as degree, as description (e.g. NNE) or both.
* *showTimestamp*: **true** or false. Whether to show the timestamp of the data.
* *showTempMinMax*: **true** or false. Whether to show temperature min/max.
* *useLocalTime*: **true** or false. Whether to use local time or UTC for the timestamp.
* *clusterSize*: Number ( **150** ). If some stations are too close to each other, they are hidden. In an area of the size clusterSize pixels * clusterSize pixels only one city or one station is allowed.
* *clusterSize*: Number ( **150** ). If some cities are too close to each other, they are hidden. In an area of the size clusterSize pixels * clusterSize pixels only one city is shown. If you zoom in the hidden cities will appear.
* *imageUrlCity*: URL ( **'https://openweathermap.org/img/w/{icon}.png'** ). URL template for weather condition images of cities. {icon} will be replaced by the icon property of city's data. See http://openweathermap.org/img/w/ for some standard images.
* *imageWidth*: Number ( **50** ). Width of city's weather condition image.
* *imageHeight*: Number ( **50** ). Height of city's weather condition image.
* *imageUrlPlane*: URL ( **'https://openweathermap.org/img/s/iplane.png'** ). Image URL for stations of type 1.
* *imageWidthPlane*: Number ( **25** ). Width of image for station type 1.
* *imageHeightPlane*: Number ( **25** ). Height of image for station type 1.
* *imageUrlStation*: URL ( **'https://openweathermap.org/img/s/istation.png'** ). Image URL for stations of type unequal to 1.
* *imageWidthStation*: Number ( **25** ). Width of image for station type unequal to 1.
* *imageHeightStation*: Number ( **25** ). Height of image for station type unequal to 1.
* *markerFunction*: Function ( **null** ). User defined function for marker creation. Needs one parameter for station data.
* *popupFunction*: Function ( **null** ). User defined function for popup creation. Needs one parameter for station data.
* *markerFunction*: Function ( **null** ). User defined function for marker creation. Needs one parameter for city data.
* *popupFunction*: Function ( **null** ). User defined function for popup creation. Needs one parameter for city data.
* *caching*: **true** or false. Use caching of current weather data. Cached data is reloaded when it is too old or the new bounding box doesn't fit inside the cached bounding box.
* *cacheMaxAge*: Number ( **15** ). Maximum age in minutes for cached data before it is considered as too old.
* *keepOnMinZoom*: **false** or true. Keep or remove markers when zoom < minZoom.
Expand Down
3 changes: 0 additions & 3 deletions example/files/map.js
Expand Up @@ -243,8 +243,6 @@ function initMap() {

var city = L.OWM.current({intervall: 15, imageLoadingUrl: 'leaflet/owmloading.gif', lang: localLang, minZoom: 5,
appId: OWM_API_KEY});
var station = L.OWM.current({type: 'station', intervall: 15, imageLoadingUrl: 'leaflet/owmloading.gif', lang: localLang,
appId: OWM_API_KEY /* , markerFunction: myOwmMarker, popupFunction: myOwmPopup */ });
var windrose = L.OWM.current({intervall: 15, imageLoadingUrl: 'leaflet/owmloading.gif', lang: localLang, minZoom: 4,
appId: OWM_API_KEY, markerFunction: myWindroseMarker, popup: false, clusterSize: 50,
imageLoadingBgUrl: 'https://openweathermap.org/img/w0/iwind.png' });
Expand Down Expand Up @@ -303,7 +301,6 @@ function initMap() {
overlayMaps[getI18n('pressure', localLang)] = pressure;
overlayMaps[getI18n('presscont', localLang)] = pressurecntr;
overlayMaps[getI18n('city', localLang) + " (min Zoom 5)"] = city;
overlayMaps[getI18n('station', localLang) + " (min Zoom 7)"] = station;
overlayMaps[getI18n('windrose', localLang)] = windrose;

var layerControl = L.control.layers(baseMaps, overlayMaps, {collapsed: false}).addTo(map);
Expand Down
5 changes: 0 additions & 5 deletions example/files/map_i18n.js
Expand Up @@ -31,7 +31,6 @@ function getI18n(key, lang) {
, presscont: 'Pressure Contour'

, city: 'Cities'
, station: 'Stations'
, windrose: 'Wind Rose'
}
, de: {
Expand All @@ -52,7 +51,6 @@ function getI18n(key, lang) {
, presscont: 'Isobaren'

, city: 'Städte'
, station: 'Stationen'
, windrose: 'Windrose'
}
, fr: {
Expand All @@ -73,7 +71,6 @@ function getI18n(key, lang) {
, presscont: 'Isobare'

, city: 'Villes'
, station: 'Stations'
, windrose: 'Boussole'
}
, ru: {
Expand All @@ -94,7 +91,6 @@ function getI18n(key, lang) {
, presscont: 'изоба́ра'

, city: 'города'
, station: 'станции'
, windrose: 'направление ветра'
}
, nl: {
Expand All @@ -115,7 +111,6 @@ function getI18n(key, lang) {
, presscont: 'Isobare'

, city: 'Steden'
, station: 'Stations'
, windrose: 'Wind roos'
}
};
Expand Down
14 changes: 7 additions & 7 deletions leaflet-openweathermap.js
@@ -1,5 +1,5 @@
/**
* A JavaScript library for using OpenWeatherMap's layers and OWM's city/station data for leaflet based maps without hassle.
* A JavaScript library for using OpenWeatherMap's layers and OWM's city data for leaflet based maps without hassle.
* License: CC0 (Creative Commons Zero), see https://creativecommons.org/publicdomain/zero/1.0/
* Project page: https://github.com/buche/leaflet-openweathermap/
*/
Expand Down Expand Up @@ -220,16 +220,16 @@ L.OWM.LegendControl = L.Control.extend({
});

/**
* Layer for current weather (cities and stations).
* Layer for current weather of cities.
*/
L.OWM.Current = L.Layer.extend({

options: {
appId: null, // get your free Application ID at www.openweathermap.org
type: 'city', // available types: 'city', 'station'
type: 'city', // available types: 'city'. 'station' is not supported any more
lang: 'en', // available: 'en', 'de', 'ru', 'fr', 'nl', 'es', 'ca' (not every language is finished yet)
minZoom: 7,
interval: 0, // interval for rereading city/station data in minutes
interval: 0, // interval for rereading city data in minutes
progressControl: true, // available: true, false
imageLoadingUrl: 'owmloading.gif', // URL of loading image relative to HTML document
imageLoadingBgUrl: null, // URL of background image for progress control
Expand Down Expand Up @@ -396,14 +396,14 @@ L.OWM.Current = L.Layer.extend({

_processRequestedData: function(_this, data) {

// read all stations/cities
// read all cities
var stations = {};
for (var i in data) {
var stat = data[i];
if (!_this._map) { // maybe layer is gone while we are looping here
return;
}
// only use stations/cities having a minimum distance of some pixels on the map
// only use cities having a minimum distance of some pixels on the map
var pt = _this._map.latLngToLayerPoint(new L.LatLng(stat.coord.Lat, stat.coord.Lon));
var key = '' + (Math.round(pt.x/_this.options.clusterSize)) + "_" + (Math.round(pt.y/_this.options.clusterSize));
if (!stations[key] || parseInt(stations[key].rang) < parseInt(stat.rang)) {
Expand All @@ -421,7 +421,7 @@ L.OWM.Current = L.Layer.extend({
}
_this._layer.clearLayers();

// add the stations/cities as markers to the LayerGroup
// add the cities as markers to the LayerGroup
_this._markers = new Array();
for (var key in stations) {
var marker;
Expand Down

0 comments on commit 2803077

Please sign in to comment.