1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
|
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 2.2 as C2
import QtPositioning 5.6
import QtLocation 5.15
Window {
id: win
visible: true
width: 1600
height: 800
title: qsTr("MapItems backends")
property real initialZL: 4
property var initialCenter: QtPositioning.coordinate(59.9154, 10.7425) //QtPositioning.coordinate(66.9961, -175.012)
property real rotation : 0
Shortcut {
sequence: "Ctrl+R"
onActivated: {
rotation = 57
}
}
function syncMaps(mFrom, mTo, propName)
{
if (mTo[propName] !== mFrom[propName]) {
mTo[propName] = mFrom[propName]
}
}
Plugin {
id: osm // use only one plugin, to avoid messing up the cache
name: "osm"
PluginParameter {
name: "osm.mapping.prefetching_style"
value: "NoPrefetching"
}
PluginParameter {
name: "osm.mapping.cache.memory.cost_strategy"
value: "unitary"
}
PluginParameter {
name: "osm.mapping.cache.memory.size"
value: 0
}
PluginParameter {
name: "osm.mapping.cache.texture.cost_strategy"
value: "unitary"
}
PluginParameter {
name: "osm.mapping.cache.texture.size"
value: 70
}
}
Rectangle {
id: mapContainer
rotation: win.rotation
anchors.fill: parent
color: "lightsteelblue"
Map {
id: map
rotation: win.rotation
gesture.enabled: true
objectName: "map1"
anchors {
bottom: parent.bottom
top: parent.top
left: parent.left
right: parent.horizontalCenter
}
onCenterChanged: syncMaps(map, map2, "center")
onTiltChanged: syncMaps(map, map2, "tilt")
onBearingChanged: syncMaps(map, map2, "bearing")
onZoomLevelChanged: syncMaps(map, map2, "zoomLevel")
onFieldOfViewChanged: syncMaps(map, map2, "fieldOfView")
opacity: 1.0
color: 'transparent'
plugin: osm
center: initialCenter
activeMapType: map.supportedMapTypes[2]
zoomLevel: initialZL
z : parent.z + 1
copyrightsVisible: false
Component.onCompleted: {
var o = migComponent.createObject(map)
o.glPolygons = Qt.binding(function() {return switchPolygons1.checked})
o.glPolylines = Qt.binding(function() {return switchPolylines1.currentText})
o.glCircles = Qt.binding(function() {return switchCircles1.checked})
o.glRectangles = Qt.binding(function() {return switchRectangles1.checked})
map.addMapItemGroup(o);
}
MouseArea {
anchors.fill: parent
onClicked: {
mouse.accepted = false
var crd = map.toCoordinate(Qt.point(mouse.x, mouse.y))
var s = crd.toString(0)
console.log("Clicked on ",s)
}
}
C2.Switch {
text: qsTr("OGL Polygons")
id: switchPolygons1
checked: true
anchors {
top: parent.top
right: parent.right
topMargin: 12
rightMargin: 12
}
}
C2.ComboBox {
model: ['Software','OpenGL','Triangulated']
id: switchPolylines1
anchors {
top: switchPolygons1.bottom
right: parent.right
topMargin: 12
rightMargin: 12
}
}
C2.Switch {
text: qsTr("OGL Circles")
id: switchCircles1
anchors {
top: switchPolylines1.bottom
right: parent.right
topMargin: 12
rightMargin: 12
}
}
C2.Switch {
text: qsTr("OGL Rectangles")
id: switchRectangles1
anchors {
top: switchCircles1.bottom
right: parent.right
topMargin: 12
rightMargin: 12
}
}
// MapPolygon {
// id: geoJsonFeature
// color: "limegreen"
// border.color: "black"
// border.width: 15
// objectName: parent.objectName + "limegreen"
// backend: polygonBackend()
// path: [
// { longitude:17.13, latitude: 51.11},
// { longitude:30.54, latitude: 50.42},
// { longitude:26.70, latitude: 58.36},
// { longitude:17.13, latitude: 51.11}
// ]
// function polygonBackend()
// {
// return (switchPolygons1.checked)
// ? MapPolygon.OpenGL : MapPolygon.Software
// }
// }
layer {
enabled: true
samples: 8
}
}
Map {
id: map2
rotation: win.rotation
gesture.enabled: true
objectName: "map2"
anchors {
bottom: parent.bottom
top: parent.top
left: parent.horizontalCenter
right: parent.right
}
onCenterChanged: syncMaps(map2, map, "center")
onTiltChanged: syncMaps(map2, map, "tilt")
onBearingChanged: syncMaps(map2, map, "bearing")
onZoomLevelChanged: syncMaps(map2, map, "zoomLevel")
onFieldOfViewChanged: syncMaps(map2, map, "fieldOfView")
color: 'transparent'
plugin: osm
activeMapType: map.supportedMapTypes[2]
center: initialCenter
zoomLevel: initialZL
copyrightsVisible: false
Component.onCompleted: {
var o = migComponent.createObject(map2)
o.glPolygons = Qt.binding(function() {return switchPolygons2.checked})
o.glPolylines = Qt.binding(function() {return switchPolylines2.currentText})
o.glCircles = Qt.binding(function() {return switchCircles2.checked})
o.glRectangles = Qt.binding(function() {return switchRectangles2.checked})
map2.addMapItemGroup(o);
}
C2.Switch {
text: qsTr("OGL Polygons")
id: switchPolygons2
checked: false
anchors {
top: parent.top
right: parent.right
topMargin: 12
rightMargin: 12
}
}
C2.ComboBox {
model: ['Software','OpenGL','Triangulated']
id: switchPolylines2
anchors {
top: switchPolygons2.bottom
right: parent.right
topMargin: 12
rightMargin: 12
}
onCurrentTextChanged: console.log("CURRENT TEXT CHANGED ",currentText)
}
C2.Switch {
text: qsTr("OGL Circles")
id: switchCircles2
anchors {
top: switchPolylines2.bottom
right: parent.right
topMargin: 12
rightMargin: 12
}
}
C2.Switch {
text: qsTr("OGL Rectangles")
id: switchRectangles2
anchors {
top: switchCircles2.bottom
right: parent.right
topMargin: 12
rightMargin: 12
}
}
layer {
enabled: true
samples: 8
}
}
}
Component {
id: migComponent
MapItemGroup {
id: polyGroup
property bool glPolygons : true
property string glPolylines : "Software"
property bool glCircles : true
property bool glRectangles : true
objectName: parent.objectName + "_MIG_"
function polylineBackend()
{
return (polyGroup.glPolylines === "OpenGL")
? MapPolyline.OpenGLLineStrip
: ((polyGroup.glPolylines === "Software")
? MapPolyline.Software : MapPolyline.OpenGLExtruded)
}
function polygonBackend()
{
return (polyGroup.glPolygons)
? MapPolygon.OpenGL : MapPolygon.Software
}
function rectangleBackend()
{
return (polyGroup.glRectangles)
? MapRectangle.OpenGL : MapRectangle.Software
}
function circleBackend()
{
return (polyGroup.glCircles)
? MapCircle.OpenGL : MapCircle.Software
}
MapPolyline {
id: tstPolyLine // to verify the polygon stays where it's supposed to
line.color: 'black'
objectName: parent.objectName + "black"
line.width: 1
opacity: 1.0
backend: polylineBackend()
path: [
{ latitude: 76.9965, longitude: -175.012 },
{ latitude: 26.9965, longitude: -175.012 }
]
}
MapPolyline {
id: timeline
line.color: "red"
objectName: parent.objectName + "timeline"
line.width: 4
backend: polylineBackend()
path: [
{ latitude: 90, longitude: 180 },
{ latitude: -90, longitude: -180 }
]
}
MapPolygon {
id: poly1
color: "red"
objectName: parent.objectName + "red"
backend: polygonBackend()
path: [
{ latitude: 55, longitude: 170 },
{ latitude: 66.9965, longitude: -175.012 },
{ latitude: 55, longitude: -160 },
{ latitude: 40, longitude: -165 },
{ latitude: 45, longitude: 178 }
]
MouseArea {
anchors.fill: parent
onClicked: console.log("poly1 in "+parent.parent.objectName + "clicked")
Rectangle { // this is technically unsupported, but practically works.
color: "transparent"
border.color: "red"
anchors.fill: parent
}
}
}
MapPolygon {
id: selfIntersectingPolygon
color: 'darkmagenta'
objectName: parent.objectName + "darkmagenta"
backend: polygonBackend()
opacity: 1.0
path: [
{ latitude: 19, longitude: 49 },
{ latitude: 18, longitude: 49 },
{ latitude: 18, longitude: 51 },
{ latitude: 20, longitude: 51 },
{ latitude: 20, longitude: 50 },
{ latitude: 18.5, longitude: 50 },
{ latitude: 18.5, longitude: 52 },
{ latitude: 19, longitude: 52 }
]
MouseArea{
anchors.fill: parent
drag.target: parent // This one might glitch as the tessellation done by earcut might be
// inaccurate, so clicking in an area that is covered by earcut but
// does not exist will not trigger the panning
Rectangle { // this is technically unsupported, but practically works.
color: "transparent"
border.color: "red"
anchors.fill: parent
}
}
}
MapPolygon {
id: poly2
color: "green"
border.color: "black"
border.width: 8
objectName: parent.objectName + "green"
backend: polygonBackend()
path: [
{ latitude: -45, longitude: -170 },
{ latitude: -55, longitude: -155 },
{ latitude: -45, longitude: -130 },
{ latitude: -35, longitude: -155 }
]
MouseArea{
anchors.fill: parent
drag.target: parent
Rectangle { // this is technically unsupported, but practically works.
color: "transparent"
border.color: "red"
anchors.fill: parent
}
}
}
MapPolygon {
id: poly3
color: "deepskyblue"
objectName: parent.objectName + "deepskyblue"
backend: polygonBackend()
opacity: 0.2
path: [
{ latitude: 65, longitude: -20 },
{ latitude: 75, longitude: 140 },
{ latitude: 65, longitude: 80 },
{ latitude: 55, longitude: -30 }
]
}
MapPolygon {
id: geoJsonFeature
color: "limegreen"
border.color: "black"
border.width: 15
objectName: parent.objectName + "limegreen"
backend: polygonBackend()
path: [
{ longitude:17.13, latitude: 51.11},
{ longitude:30.54, latitude: 50.42},
{ longitude:26.70, latitude: 58.36},
{ longitude:17.13, latitude: 51.11}
]
}
MapPolygon {
id: geoJsonRect
color: "yellow"
border.color: "black"
border.width: 8
objectName: parent.objectName + "yellow"
backend: polygonBackend()
path: [
{ longitude:4, latitude: 15},
{ longitude:5, latitude: 15},
{ longitude:5, latitude: 14},
{ longitude:4, latitude: 14},
{ longitude:4, latitude: 15}
]
}
MapRectangle {
id: rect
color: 'tomato'
border.color: 'black'
border.width: 6
topLeft: QtPositioning.coordinate(10,-10)
bottomRight: QtPositioning.coordinate(-10,10)
backend: rectangleBackend()
MouseArea {
anchors.fill: parent
Rectangle {
color: "transparent"
border.color: "red"
border.width: 1
anchors.fill: parent
}
}
}
LongPolyline {
id: longPolyline
line.width: sliLineWidth.value
line.color: 'firebrick'
backend: polylineBackend()
}
MapCircle {
center: QtPositioning.coordinate(52, 0)
radius: 100*1000
color: 'deepskyblue'
border.width: 6
border.color: 'firebrick'
backend: circleBackend()
MouseArea {
anchors.fill: parent
Rectangle {
color: "transparent"
border.color: "red"
border.width: 1
anchors.fill: parent
}
}
}
MapCircle {
id: circle1
border.color: 'deepskyblue'
border.width: 26
backend: circleBackend()
center: QtPositioning.coordinate(17, 44);
radius: 200*1000
color: "firebrick"
// layer.enabled: (backend == MapCircle.Software)
// layer.samples: 4
}
}
}
C2.Slider {
id: sliLineWidth
orientation: Qt.Vertical
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
topMargin: 10
leftMargin: 10
bottomMargin: 10
}
from: 1
to: 20
value: 10
}
Text {
id: zl
text: "" + map.zoomLevel.toFixed(2)
anchors.top: parent.top
anchors.left: parent.left
}
}
|