mirror of
https://github.com/Lissy93/dashy.git
synced 2024-11-23 04:34:44 +03:00
✨ Adds support for lat+lon location (#1142)
This commit is contained in:
parent
eb749ebcd0
commit
c4b687550d
@ -151,6 +151,8 @@ A simple, live-updating local weather component, showing temperature, conditions
|
|||||||
**`city`** | `string` | Required | A city name to use for fetching weather. This can also be a state code or country code, following the ISO-3166 format
|
**`city`** | `string` | Required | A city name to use for fetching weather. This can also be a state code or country code, following the ISO-3166 format
|
||||||
**`units`** | `string` | _Optional_ | The units to use for displaying data, can be either `metric` or `imperial`. Defaults to `metric`
|
**`units`** | `string` | _Optional_ | The units to use for displaying data, can be either `metric` or `imperial`. Defaults to `metric`
|
||||||
**`hideDetails`** | `boolean` | _Optional_ | If set to `true`, the additional details (wind, humidity, pressure, etc) will not be shown. Defaults to `false`
|
**`hideDetails`** | `boolean` | _Optional_ | If set to `true`, the additional details (wind, humidity, pressure, etc) will not be shown. Defaults to `false`
|
||||||
|
**`lat`** | `number` | _Optional_ | To show weather for a specific location, you can provide the latitude and longitude coordinates. If provided, this will override the `city` option
|
||||||
|
**`lon`** | `number` | _Optional_ | To show weather for a specific location, you can provide the latitude and longitude coordinates. If provided, this will override the `city` option
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
@ -160,7 +162,7 @@ A simple, live-updating local weather component, showing temperature, conditions
|
|||||||
apiKey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
apiKey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
city: London
|
city: London
|
||||||
units: metric
|
units: metric
|
||||||
hideDetails: false
|
hideDetails: true
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Info
|
#### Info
|
||||||
|
@ -46,7 +46,12 @@ export default {
|
|||||||
return this.options.units || 'metric';
|
return this.options.units || 'metric';
|
||||||
},
|
},
|
||||||
endpoint() {
|
endpoint() {
|
||||||
const { apiKey, city } = this.options;
|
const {
|
||||||
|
apiKey, city, lat, lon,
|
||||||
|
} = this.options;
|
||||||
|
if (lat && lon) {
|
||||||
|
return `${widgetApiEndpoints.weather}?lat=${lat}&lon=${lon}&appid=${apiKey}&units=${this.units}`;
|
||||||
|
}
|
||||||
return `${widgetApiEndpoints.weather}?q=${city}&appid=${apiKey}&units=${this.units}`;
|
return `${widgetApiEndpoints.weather}?q=${city}&appid=${apiKey}&units=${this.units}`;
|
||||||
},
|
},
|
||||||
tempDisplayUnits() {
|
tempDisplayUnits() {
|
||||||
@ -106,7 +111,11 @@ export default {
|
|||||||
checkProps() {
|
checkProps() {
|
||||||
const ops = this.options;
|
const ops = this.options;
|
||||||
if (!ops.apiKey) this.error('Missing API key for OpenWeatherMap');
|
if (!ops.apiKey) this.error('Missing API key for OpenWeatherMap');
|
||||||
if (!ops.city) this.error('A city name is required to fetch weather');
|
|
||||||
|
if ((!ops.lat || !ops.lon) && !ops.city) {
|
||||||
|
this.error('A city name or lat + lon is required to fetch weather');
|
||||||
|
}
|
||||||
|
|
||||||
if (ops.units && ops.units !== 'metric' && ops.units !== 'imperial') {
|
if (ops.units && ops.units !== 'metric' && ops.units !== 'imperial') {
|
||||||
this.error('Invalid units specified, must be either \'metric\' or \'imperial\'');
|
this.error('Invalid units specified, must be either \'metric\' or \'imperial\'');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user