summaryrefslogtreecommitdiff
path: root/examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli.qt@gmail.com>2019-12-30 13:27:29 +0100
committerPaolo Angelelli <paolo.angelelli.qt@gmail.com>2020-02-12 11:24:45 +0000
commitbe7cbed7411d024d178377bd327d5916c80e02a0 (patch)
treed5840e89206157770188c4472bcc752f793a6a5d /examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml
parenta4469cad4041f21e640efa9ca5d0b192dd702955 (diff)
downloadqtlocation-be7cbed7411d024d178377bd327d5916c80e02a0.tar.gz
Add geometry simplification to MapPolyline/MapPolylineObjectQSG
This change introduces a metric-based implementation of the Ramer-Douglas-Peucker line simplification algorithm to generate a LOD pyramid for the polyline geometries. This comes with a related property (in MapItemBase), lodThreshold, that can be used to change the threshold after which no simplification will be used. By default the value of this property is 0, meaning that the behavior will be unchanged and no LOD will be used. This change also introduces LOD on map polyine objects QSG, for which no property is introduced, and there's a default threshold set to zoom level 12 (which appear to produce acceptable results). Finally, this patch makes use of a threadpool with 1 thread to enqueue geometry simplification tasks, which would otherwise freeze the UI when computing for the first time. Support for geometry simplification is currently added only to polylines. It might be of interest extending it to polygons as well, once a proper strategy for handling the simplification of inner holes has been identified. Finally, extending it to circles could be of interest, while potentially bringing only minor benefits, as circle geometries are currently fixed to 128 vertices. Also adds a MapObject-based delegate to the geojson viewer example. Task-number: QTBUG-46652 Task-number: QTBUG-38459 Task-number: QTBUG-49303 Change-Id: I64b5db4577962db17e5388812909285c9356ef0d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml')
-rw-r--r--examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml152
1 files changed, 152 insertions, 0 deletions
diff --git a/examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml b/examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml
new file mode 100644
index 00000000..d1a144c8
--- /dev/null
+++ b/examples/location/geojson_viewer/GeoJsonDelegateMapObject.qml
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 Paolo Angelelli <paolo.angelelli@gmail.com>
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.12
+import QtPositioning 5.12
+import Qt.labs.location 1.0
+import Qt.labs.qmlmodels 1.0
+
+DelegateChooser {
+ id: dc
+ role: "type"
+ property color defaultColor: "grey"
+
+ DelegateChoice {
+ roleValue: "Point"
+ delegate: MapCircleObject {
+ property string geojsonType: "Point"
+ property var props: modelData.properties
+ geoShape: modelData.data
+ radius: 20*1000
+ border.width: 3
+ /* The expression below is equivalent to:
+ ((props !== undefined && props["color"] !== undefined) ? props["color"] :
+ ((parent && parent.props !== undefined && parent.props["color"] !== undefined) ? parent.props["color"] : dc.defaultColor))
+ */
+ color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
+ }
+ }
+
+ DelegateChoice {
+ roleValue: "LineString"
+ delegate: MapPolylineObject {
+ property string geojsonType: "LineString"
+ property var props: modelData.properties
+ geoShape: modelData.data
+ line.width: 4
+ line.color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
+ }
+ }
+
+ DelegateChoice {
+ roleValue: "Polygon"
+ delegate: MapPolygonObject {
+ property string geojsonType: "Polygon"
+ property var props: modelData.properties
+ geoShape: modelData.data
+ color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
+ border.width: 4
+ border.color: 'black'
+ }
+ }
+
+ DelegateChoice {
+ roleValue: "MultiPoint"
+ delegate: MapObjectView {
+ property string geojsonType: "MultiPoint"
+ property var props: modelData.properties
+ model: modelData.data
+ delegate: dc
+ }
+ }
+
+ DelegateChoice {
+ roleValue: "MultiLineString"
+ delegate: MapObjectView {
+ property string geojsonType: "MultiLineString"
+ property var props: modelData.properties
+ model: modelData.data
+ delegate: dc
+ }
+ }
+
+ DelegateChoice {
+ roleValue: "MultiPolygon"
+ delegate: MapObjectView {
+ property string geojsonType: "MultiPolygon"
+ property var props: modelData.properties
+ model: modelData.data
+ delegate: dc
+ }
+ }
+
+ DelegateChoice {
+ roleValue: "GeometryCollection"
+ delegate: MapObjectView {
+ property string geojsonType: "GeometryCollection"
+ property var props: modelData.properties
+ model: modelData.data
+ delegate: dc
+ }
+ }
+
+ // Features are explicitly not generated by the parser, but converted straight to their content + the properties.
+
+ DelegateChoice {
+ roleValue: "FeatureCollection"
+ delegate: MapObjectView {
+ property string geojsonType: "FeatureCollection"
+ property var props: modelData.properties
+ model: modelData.data
+ delegate: dc
+ }
+ }
+}