1/**************************************************************************** 2** 3** Copyright (C) 2020 Paolo Angelelli <paolo.angelelli@gmail.com> 4** Copyright (C) 2020 The Qt Company Ltd. 5** Contact: https://www.qt.io/licensing/ 6** 7** This file is part of the examples of the Qt Toolkit. 8** 9** $QT_BEGIN_LICENSE:BSD$ 10** Commercial License Usage 11** Licensees holding valid commercial Qt licenses may use this file in 12** accordance with the commercial license agreement provided with the 13** Software or, alternatively, in accordance with the terms contained in 14** a written agreement between you and The Qt Company. For licensing terms 15** and conditions see https://www.qt.io/terms-conditions. For further 16** information use the contact form at https://www.qt.io/contact-us. 17** 18** BSD License Usage 19** Alternatively, you may use this file under the terms of the BSD license 20** as follows: 21** 22** "Redistribution and use in source and binary forms, with or without 23** modification, are permitted provided that the following conditions are 24** met: 25** * Redistributions of source code must retain the above copyright 26** notice, this list of conditions and the following disclaimer. 27** * Redistributions in binary form must reproduce the above copyright 28** notice, this list of conditions and the following disclaimer in 29** the documentation and/or other materials provided with the 30** distribution. 31** * Neither the name of The Qt Company Ltd nor the names of its 32** contributors may be used to endorse or promote products derived 33** from this software without specific prior written permission. 34** 35** 36** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 43** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 44** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 45** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 47** 48** $QT_END_LICENSE$ 49** 50****************************************************************************/ 51 52import QtQuick 2.12 53import QtPositioning 5.12 54import Qt.labs.location 1.0 55import Qt.labs.qmlmodels 1.0 56 57DelegateChooser { 58 id: dc 59 role: "type" 60 property color defaultColor: "grey" 61 62 DelegateChoice { 63 roleValue: "Point" 64 delegate: MapCircleObject { 65 property string geojsonType: "Point" 66 property var props: modelData.properties 67 geoShape: modelData.data 68 radius: 20*1000 69 border.width: 3 70 /* The expression below is equivalent to: 71 ((props !== undefined && props["color"] !== undefined) ? props["color"] : 72 ((parent && parent.props !== undefined && parent.props["color"] !== undefined) ? parent.props["color"] : dc.defaultColor)) 73 */ 74 color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor 75 } 76 } 77 78 DelegateChoice { 79 roleValue: "LineString" 80 delegate: MapPolylineObject { 81 property string geojsonType: "LineString" 82 property var props: modelData.properties 83 geoShape: modelData.data 84 line.width: 4 85 line.color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor 86 } 87 } 88 89 DelegateChoice { 90 roleValue: "Polygon" 91 delegate: MapPolygonObject { 92 property string geojsonType: "Polygon" 93 property var props: modelData.properties 94 geoShape: modelData.data 95 color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor 96 border.width: 4 97 border.color: 'black' 98 } 99 } 100 101 DelegateChoice { 102 roleValue: "MultiPoint" 103 delegate: MapObjectView { 104 property string geojsonType: "MultiPoint" 105 property var props: modelData.properties 106 model: modelData.data 107 delegate: dc 108 } 109 } 110 111 DelegateChoice { 112 roleValue: "MultiLineString" 113 delegate: MapObjectView { 114 property string geojsonType: "MultiLineString" 115 property var props: modelData.properties 116 model: modelData.data 117 delegate: dc 118 } 119 } 120 121 DelegateChoice { 122 roleValue: "MultiPolygon" 123 delegate: MapObjectView { 124 property string geojsonType: "MultiPolygon" 125 property var props: modelData.properties 126 model: modelData.data 127 delegate: dc 128 } 129 } 130 131 DelegateChoice { 132 roleValue: "GeometryCollection" 133 delegate: MapObjectView { 134 property string geojsonType: "GeometryCollection" 135 property var props: modelData.properties 136 model: modelData.data 137 delegate: dc 138 } 139 } 140 141 // Features are explicitly not generated by the parser, but converted straight to their content + the properties. 142 143 DelegateChoice { 144 roleValue: "FeatureCollection" 145 delegate: MapObjectView { 146 property string geojsonType: "FeatureCollection" 147 property var props: modelData.properties 148 model: modelData.data 149 delegate: dc 150 } 151 } 152} 153