1/**************************************************************************** 2** 3** Copyright (C) 2020 The Qt Company Ltd. 4** Contact: https://www.qt.io/licensing/ 5** 6** This file is part of the test suite of the Qt Toolkit. 7** 8** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 9** Commercial License Usage 10** Licensees holding valid commercial Qt licenses may use this file in 11** accordance with the commercial license agreement provided with the 12** Software or, alternatively, in accordance with the terms contained in 13** a written agreement between you and The Qt Company. For licensing terms 14** and conditions see https://www.qt.io/terms-conditions. For further 15** information use the contact form at https://www.qt.io/contact-us. 16** 17** GNU General Public License Usage 18** Alternatively, this file may be used under the terms of the GNU 19** General Public License version 3 as published by the Free Software 20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21** included in the packaging of this file. Please review the following 22** information to ensure the GNU General Public License requirements will 23** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24** 25** $QT_END_LICENSE$ 26** 27****************************************************************************/ 28 29import QtQuick 2.7 30import QtQuick.Window 2.2 31import QtQuick.Controls 2.13 as C2 32import QtPositioning 5.6 33import QtLocation 5.15 34 35Window { 36 id: win 37 visible: true 38 width: 1600 39 height: 800 40 title: qsTr("MapPolyline tester") 41 42 property real initialZL: 4 43 property var initialCenter: QtPositioning.coordinate(55, -160) 44 property real rotation : 0 45 46 Shortcut { 47 sequence: "Ctrl+R" 48 onActivated: { 49 rotation = rotation + 36 50 } 51 } 52 53 function syncMaps(mFrom, mTo, propName) 54 { 55 if (mTo[propName] !== mFrom[propName]) { 56 mTo[propName] = mFrom[propName] 57 } 58 } 59 60 Plugin { 61 id: osm // use only one plugin, to avoid messing up the cache 62 name: "osm" 63 } 64 Rectangle { 65 id: mapContainer 66 rotation: win.rotation 67 anchors.fill: parent 68 color: "lightsteelblue" 69 70 Map { 71 id: map 72 rotation: win.rotation 73 gesture.enabled: true 74 objectName: "map1" 75 anchors { 76 bottom: parent.bottom 77 top: parent.top 78 left: parent.left 79 right: (leftSwitch.checked) ? parent.right : parent.horizontalCenter 80 } 81 82 onCenterChanged: syncMaps(map, map2, "center") 83 onTiltChanged: syncMaps(map, map2, "tilt") 84 onBearingChanged: syncMaps(map, map2, "bearing") 85 onZoomLevelChanged: syncMaps(map, map2, "zoomLevel") 86 onFieldOfViewChanged: syncMaps(map, map2, "fieldOfView") 87 88 opacity: 1.0 89 color: 'transparent' 90 plugin: osm 91 center: initialCenter 92 activeMapType: map.supportedMapTypes[2] 93 zoomLevel: initialZL 94 z : parent.z + 1 95 copyrightsVisible: false 96 97 Component.onCompleted: { 98 var o = migComponent.createObject(map) 99 o.glPolylines = Qt.binding(function() {return switchPolylines1.currentText}) 100 map.addMapItemGroup(o); 101 } 102 MouseArea { 103 anchors.fill: parent 104 onClicked: { 105 mouse.accepted = false 106 var crd = map.toCoordinate(Qt.point(mouse.x, mouse.y)) 107 var s = crd.toString(0) 108 console.log("Clicked the map (not an Item) on ",s) 109 } 110 } 111 112 C2.ComboBox { 113 model: ['Software','OpenGL LineStrip','OpenGL Triangles'] 114 id: switchPolylines1 115 anchors { 116 top: parent.top 117 right: parent.right 118 topMargin: 12 119 rightMargin: 12 120 } 121 } 122 } 123 Map { 124 id: map2 125 rotation: win.rotation 126 gesture.enabled: true 127 objectName: "map2" 128 visible: !leftSwitch.checked 129 anchors { 130 bottom: parent.bottom 131 top: parent.top 132 left: parent.horizontalCenter 133 right: parent.right 134 } 135 136 onCenterChanged: syncMaps(map2, map, "center") 137 onTiltChanged: syncMaps(map2, map, "tilt") 138 onBearingChanged: syncMaps(map2, map, "bearing") 139 onZoomLevelChanged: syncMaps(map2, map, "zoomLevel") 140 onFieldOfViewChanged: syncMaps(map2, map, "fieldOfView") 141 142 color: 'transparent' 143 plugin: osm 144 activeMapType: map.supportedMapTypes[2] 145 center: initialCenter 146 zoomLevel: initialZL 147 copyrightsVisible: false 148 149 Component.onCompleted: { 150 var o = migComponent.createObject(map2) 151 o.glPolylines = Qt.binding(function() {return switchPolylines2.currentText}) 152 map2.addMapItemGroup(o); 153 } 154 155 C2.ComboBox { 156 model: ['Software','OpenGL LineStrip','OpenGL Triangles'] 157 id: switchPolylines2 158 anchors { 159 top: parent.top 160 right: parent.right 161 topMargin: 12 162 rightMargin: 12 163 } 164 onCurrentTextChanged: console.log("CURRENT TEXT CHANGED ",currentText) 165 } 166 } 167 } 168 169 Component { 170 id: migComponent 171 MapItemGroup { 172 id: polyGroup 173 property bool glPolygons : true 174 property string glPolylines : "Software" 175 property bool glCircles : true 176 property bool glRectangles : true 177 objectName: parent.objectName + "_MIG_" 178 179 function polylineBackend() 180 { 181 return (polyGroup.glPolylines === "OpenGL LineStrip") 182 ? MapPolyline.OpenGLLineStrip 183 : ((polyGroup.glPolylines === "Software") 184 ? MapPolyline.Software : MapPolyline.OpenGLExtruded) 185 } 186 187 function polygonBackend() 188 { 189 return (polyGroup.glPolylines === "Software") 190 ? MapPolygon.Software : MapPolygon.OpenGL 191 } 192 193 function miterValue() 194 { 195 return (miterSwitch.checked) ? Qt.RoundCap : Qt.FlatCap 196 } 197 198 MapPolyline { 199 id: tstPolyLine // to verify the polygon stays where it's supposed to 200 line.color: 'black' 201 objectName: parent.objectName + "black" 202 line.width: 1 203 opacity: 1.0 204 backend: polylineBackend() 205 path: [ 206 { latitude: 76.9965, longitude: -175.012 }, 207 { latitude: 26.9965, longitude: -175.012 } 208 ] 209 } 210 211 MapPolyline { 212 id: timeline 213 line.color: "red" 214 objectName: parent.objectName + "timeline" 215 line.width: 4 216 backend: polylineBackend() 217 path: [ 218 { latitude: 90, longitude: 180 }, 219 { latitude: -90, longitude: -180 } 220 ] 221 } 222 223 MapPolyline { 224 id: poly1 225 line.color: "pink" 226 line.width: sliWidth.value 227 objectName: parent.objectName + "red" 228 backend: polylineBackend() 229 230 path: [ 231 { latitude: 55, longitude: 170 }, 232 { latitude: 66.9965, longitude: 170 }, 233 { latitude: 66.9965, longitude: -175.012 }, 234 { latitude: 55, longitude: -160 }, 235 { latitude: 40, longitude: -165 }, 236 { latitude: 45, longitude: 174 }, 237 { latitude: 43, longitude: -168 } 238 ] 239 DynamicParameter { 240 type: "lineStyle" 241 property var lineCap: miterValue() 242 } 243 244 MouseArea { 245 anchors.fill: parent 246 onClicked: console.log("poly1 in "+parent.parent.objectName + "clicked") 247 248 Rectangle { // this is technically unsupported, but practically works. 249 color: "transparent" 250 border.color: "red" 251 anchors.fill: parent 252 } 253 } 254 } 255 256 MapPolygon { 257 id: poly2 258 color: "green" 259 border.color: "black" 260 border.width: 12 261 objectName: parent.objectName + "green" 262 backend: polygonBackend() 263 path: [ 264 { latitude: -45, longitude: -170 }, 265 { latitude: -55, longitude: -155 }, 266 { latitude: -45, longitude: -130 }, 267 { latitude: -35, longitude: -155 } 268 ] 269 MouseArea{ 270 anchors.fill: parent 271 drag.target: parent 272 Rectangle { // this is technically unsupported, but practically works. 273 color: "transparent" 274 border.color: "red" 275 anchors.fill: parent 276 } 277 } 278 } 279 280// LongPolyline { 281// id: longPolyline 282// line.width: 10 283// line.color: 'firebrick' 284// backend: polylineBackend() 285// } 286 } 287 } 288 289 290 C2.Switch { 291 text: qsTr("Left") 292 id: leftSwitch 293 anchors { 294 top: parent.top 295 left: parent.left 296 leftMargin: 12 297 rightMargin: 12 298 } 299 checked: false 300 } 301 C2.Switch { 302 text: qsTr("Miter") 303 id: miterSwitch 304 anchors { 305 top: leftSwitch.bottom 306 left: parent.left 307 leftMargin: 12 308 rightMargin: 12 309 } 310 checked: false 311 } 312 C2.Slider { 313 id: sliWidth 314 orientation: Qt.Vertical 315 anchors { 316 left: parent.left 317 top: miterSwitch.bottom 318 bottom: parent.bottom 319 topMargin: 10 320 leftMargin: 10 321 bottomMargin: 10 322 } 323 from: 1 324 to: 50 325 value: 50 326 } 327} 328