| 1 |
/* |
| 2 |
* Copyright (C) 2019-2020 UBports Foundation |
| 3 |
* |
| 4 |
* This file is part of Lomiri Weather App |
| 5 |
* |
| 6 |
* Lomiri Weather App is free software: you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License version 3 as |
| 8 |
* published by the Free Software Foundation. |
| 9 |
* |
| 10 |
* Lomiri Weather App is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
import QtQuick 2.12 |
| 20 |
import Lomiri.Components 1.3 |
| 21 |
import QtQuick.Controls 2.2 as QC |
| 22 |
import QtWebEngine 1.10 |
| 23 |
import "../components" |
| 24 |
|
| 25 |
Page { |
| 26 |
id: onlineMapPage |
| 27 |
property string sourceName: "rainviewer.com" |
| 28 |
property double latitude: weatherApp.locationsList[settings.current].location.coord.lat |
| 29 |
property double longitude: weatherApp.locationsList[settings.current].location.coord.lon |
| 30 |
property int zoom: 7 |
| 31 |
property string snow: "&sn=1" //snow on |
| 32 |
property string mapType: "&mlayer=0" //road map |
| 33 |
|
| 34 |
header: PageHeader { |
| 35 |
id: header |
| 36 |
|
| 37 |
title: i18n.tr("Rain radar") |
| 38 |
|
| 39 |
QC.AbstractButton { |
| 40 |
id: sourceButton |
| 41 |
height: width |
| 42 |
width: units.gu(3) |
| 43 |
anchors { |
| 44 |
verticalCenter: parent.verticalCenter |
| 45 |
right: reloadButton.left |
| 46 |
rightMargin: units.gu(1) |
| 47 |
} |
| 48 |
|
| 49 |
onClicked: Qt.openUrlExternally("https://" + sourceName) |
| 50 |
|
| 51 |
Rectangle { |
| 52 |
anchors.fill: parent |
| 53 |
color: Theme.palette.selected.background |
| 54 |
visible: parent.pressed |
| 55 |
} |
| 56 |
|
| 57 |
Icon { |
| 58 |
anchors.centerIn: parent |
| 59 |
color: theme.palette.normal.baseText |
| 60 |
height: width |
| 61 |
name: "external-link" |
| 62 |
width: units.gu(2) |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
QC.AbstractButton { |
| 67 |
id: reloadButton |
| 68 |
height: width |
| 69 |
width: units.gu(3) |
| 70 |
anchors { |
| 71 |
verticalCenter: parent.verticalCenter |
| 72 |
right: mapButton.left |
| 73 |
rightMargin: units.gu(1) |
| 74 |
} |
| 75 |
|
| 76 |
onClicked: { |
| 77 |
webview.reloadAndBypassCache(); |
| 78 |
webview.firstLoadComplete = true; |
| 79 |
} |
| 80 |
|
| 81 |
Rectangle { |
| 82 |
anchors.fill: parent |
| 83 |
color: Theme.palette.selected.background |
| 84 |
visible: parent.pressed |
| 85 |
} |
| 86 |
|
| 87 |
Icon { |
| 88 |
anchors.centerIn: parent |
| 89 |
color: theme.palette.normal.baseText |
| 90 |
height: width |
| 91 |
name: "reload" |
| 92 |
width: units.gu(2) |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
QC.AbstractButton { |
| 97 |
id: mapButton |
| 98 |
height: width |
| 99 |
width: units.gu(3) |
| 100 |
anchors { |
| 101 |
verticalCenter: parent.verticalCenter |
| 102 |
right: snowButton.left |
| 103 |
rightMargin: units.gu(1) |
| 104 |
} |
| 105 |
|
| 106 |
onClicked: { |
| 107 |
if (mapType === "&mlayer=1") { //if satellite, change to road map |
| 108 |
mapType = "&mlayer=0"; |
| 109 |
} else { //if road map, change back to satellite map |
| 110 |
mapType = "&mlayer=1"; |
| 111 |
} |
| 112 |
webview.url = buildURL(sourceName,latitude,longitude,zoom,snow,mapType) |
| 113 |
} |
| 114 |
|
| 115 |
Rectangle { |
| 116 |
anchors.fill: parent |
| 117 |
color: Theme.palette.selected.background |
| 118 |
visible: parent.pressed |
| 119 |
} |
| 120 |
|
| 121 |
Icon { |
| 122 |
id:mapIcon |
| 123 |
anchors.centerIn: parent |
| 124 |
color: mapType == "&mlayer=0" ? theme.palette.disabled.baseText : theme.palette.normal.baseText |
| 125 |
height: width |
| 126 |
source: "qrc:/satellite.svg" |
| 127 |
width: units.gu(2) |
| 128 |
} |
| 129 |
} |
| 130 |
QC.AbstractButton { |
| 131 |
id: snowButton |
| 132 |
height: width |
| 133 |
width: units.gu(3) |
| 134 |
anchors { |
| 135 |
verticalCenter: parent.verticalCenter |
| 136 |
right: parent.right |
| 137 |
rightMargin: units.gu(1) |
| 138 |
} |
| 139 |
|
| 140 |
onClicked: { |
| 141 |
if (snow === "&sn=1") { |
| 142 |
snow = "&sn=0"; |
| 143 |
snowIcon.color = theme.palette.disabled.baseText; |
| 144 |
} else { |
| 145 |
snow = "&sn=1"; |
| 146 |
snowIcon.color = theme.palette.normal.baseText; |
| 147 |
} |
| 148 |
webview.url = buildURL(sourceName,latitude,longitude,zoom,snow,mapType) |
| 149 |
} |
| 150 |
|
| 151 |
Rectangle { |
| 152 |
anchors.fill: parent |
| 153 |
color: Theme.palette.selected.background |
| 154 |
visible: parent.pressed |
| 155 |
} |
| 156 |
|
| 157 |
Icon { |
| 158 |
id:snowIcon |
| 159 |
anchors.centerIn: parent |
| 160 |
color: theme.palette.normal.baseText |
| 161 |
height: width |
| 162 |
name: "weather-chance-of-snow" |
| 163 |
width: units.gu(2) |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
ProgressBar { |
| 169 |
id: loadingIndicator |
| 170 |
anchors { |
| 171 |
top: header.bottom |
| 172 |
left: parent.left |
| 173 |
right: parent.right |
| 174 |
} |
| 175 |
height: units.gu(0.2) |
| 176 |
//aquire the webviews loading progress for the indicators value |
| 177 |
value: webview.loadProgress/100 |
| 178 |
//hide loadingIndicator when page has been loaded successfully |
| 179 |
visible: webview.loadProgress === 100 ? false : true |
| 180 |
} |
| 181 |
|
| 182 |
Rectangle { |
| 183 |
//show placeholder while the page is loading to avoid ugly flickering of webview |
| 184 |
id: webViewPlaceholder |
| 185 |
anchors { |
| 186 |
top: loadingIndicator.bottom |
| 187 |
left: parent.left |
| 188 |
right: parent.right |
| 189 |
bottom: parent.bottom |
| 190 |
} |
| 191 |
z: 1 |
| 192 |
color: theme.palette.normal.background |
| 193 |
visible: webview.loadProgress === 100 ? false : true |
| 194 |
|
| 195 |
QC.BusyIndicator { |
| 196 |
id: busy |
| 197 |
anchors.centerIn: parent |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
WebEngineView { |
| 202 |
id: webview |
| 203 |
//to reload with another (or altered) url just change the url-value, no reload function needed |
| 204 |
url: buildURL(sourceName,latitude,longitude,zoom,snow,mapType) |
| 205 |
zoomFactor: 1.8 |
| 206 |
profile: webViewProfile |
| 207 |
anchors { |
| 208 |
topMargin: onlineMapPage.header.height |
| 209 |
fill: parent |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
WebEngineProfile { |
| 214 |
id: webViewProfile |
| 215 |
persistentCookiesPolicy: WebEngineProfile.NoPersistentCookies; |
| 216 |
httpCacheType: WebEngineProfile.DiskHttpCache; |
| 217 |
} |
| 218 |
|
| 219 |
//on Xperias WebEngineView causes a unity8 crash after approx. 5 minutes if the page is not reloaded |
| 220 |
Timer { |
| 221 |
id: refreshTimer |
| 222 |
interval: 240000 //4 minutes |
| 223 |
running: false |
| 224 |
repeat: false |
| 225 |
onTriggered: webview.reload() |
| 226 |
} |
| 227 |
|
| 228 |
function buildURL (basisURL,latValue, longValue, zoomValue, snVal, mapVal) { |
| 229 |
var url = ""; |
| 230 |
|
| 231 |
if (latValue !== undefined && longValue !== undefined && basisURL !== undefined) { |
| 232 |
url = "https://www.rainviewer.com/map.html?loc=" + latValue.toString() + "," + longValue.toString()+ "," + zoomValue.toString() + "&oFa=0&oC=0&oU=0&oCS=1&oF=1&oAP=1&c=1&o=70&lm=1&sm=0&layer=radar&hu=false" + snVal + mapVal; |
| 233 |
/* parameters of rainviewer.com: |
| 234 |
&mlayer=0 ... map type: 0=road map (default), 1=satellite |
| 235 |
&layer=radar ... rain radar view |
| 236 |
&sn=1 ... 0=snow off, 1=snow on |
| 237 |
&c=1 ... weather data color scheme: 0=Original, 1=Universal Blue, 2=TITAN, 3=The Weather Channel, 5=NEXRAD Level-III 6=RAINBOW @ SELEX SI 7=Dark Sky |
| 238 |
&o=83 ... radar layer opacitiy value |
| 239 |
&oFa=0 ... 0=fast animation off, 1=fast animation on |
| 240 |
&oC=0 ... 0=show coverage off, 1=show coverage time on |
| 241 |
&oU=0 ... 0=UTC time off, 1=UTC time on |
| 242 |
&oCS=1 ... 0=legend off, 1=legend on |
| 243 |
&oF=1 ... 0=fullscreen off, 1=fullscreen on |
| 244 |
&oAP=1 ... 0=play off, 1=play on |
| 245 |
&sm=1 ... 0=smooth radar data off, 1=smooth radar data on |
| 246 |
&lm=1 ... 0=legend maximized, 1=legend minimized |
| 247 |
*/ |
| 248 |
} |
| 249 |
|
| 250 |
if (networkError) { |
| 251 |
return "" |
| 252 |
} else { |
| 253 |
return url |
| 254 |
} |
| 255 |
} |
| 256 |
} |