1/****************************************************************************
2**
3** Copyright (C) 2019 Julian Sherollari <jdotsh@gmail.com>
4** Copyright (C) 2019 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 QtLocation 5.15
55import Qt.labs.qmlmodels 1.0
56
57DelegateChooser {
58    id: dc
59    role: "type"
60    property color defaultColor: "grey"
61    property real defaultOpacity: 0.6
62    property bool openGLBackends: false
63
64    DelegateChoice {
65        roleValue: "Point"
66        delegate: MapCircle {
67            property string geojsonType: "Point"
68            property var props: modelData.properties
69            geoShape: modelData.data
70            radius: 20*1000
71            border.width: 3
72            opacity: dc.defaultOpacity
73            /* The expression below is equivalent to:
74               ((props !== undefined && props["color"] !== undefined) ? props["color"] :
75               ((parent && parent.props !== undefined && parent.props["color"] !== undefined) ? parent.props["color"] : dc.defaultColor))
76            */
77            color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
78        }
79    }
80
81    DelegateChoice {
82        roleValue: "LineString"
83        delegate: MapPolyline {
84            property string geojsonType: "LineString"
85            property var props: modelData.properties
86            backend: (dc.openGLBackends) ? MapPolyline.OpenGLExtruded : MapPolyline.Software
87            geoShape: modelData.data
88            line.width: 4
89            opacity: dc.defaultOpacity
90            line.color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
91        }
92    }
93
94    DelegateChoice {
95        roleValue: "Polygon"
96        delegate: MapPolygon {
97            property string geojsonType: "Polygon"
98            property var props: modelData.properties
99            geoShape: modelData.data
100            opacity: dc.defaultOpacity
101            color: (props && props.color) || (parent && parent.props && parent.props.color) || dc.defaultColor
102            border.width: 4
103            border.color: 'black'
104            backend: (dc.openGLBackends) ? MapPolygon.OpenGL : MapPolygon.Software
105            MouseArea {
106                anchors.fill: parent
107                onClicked: {
108                    if (props !== undefined)
109                        console.log(props.name)
110                    else if (parent.parent.geojsonType == "MultiPolygon")
111                        console.log(parent.parent.props.name)
112                    else
113                        console.log("NO NAME!", props)
114                }
115            }
116        }
117    }
118
119    DelegateChoice {
120        roleValue: "MultiPoint"
121        delegate: MapItemView {
122            property string geojsonType: "MultiPoint"
123            property var props: modelData.properties
124            model: modelData.data
125            delegate: dc
126        }
127    }
128
129    DelegateChoice {
130        roleValue: "MultiLineString"
131        delegate: MapItemView {
132            property string geojsonType: "MultiLineString"
133            property var props: modelData.properties
134            model: modelData.data
135            delegate: dc
136        }
137    }
138
139    DelegateChoice {
140        roleValue: "MultiPolygon"
141        delegate: MapItemView {
142            property string geojsonType: "MultiPolygon"
143            property var props: modelData.properties
144            model: modelData.data
145            delegate: dc
146        }
147    }
148
149    DelegateChoice {
150        roleValue: "GeometryCollection"
151        delegate: MapItemView {
152            property string geojsonType: "GeometryCollection"
153            property var props: modelData.properties
154            model: modelData.data
155            delegate: dc
156        }
157    }
158
159    // Features are explicitly not generated by the parser, but converted straight to their content + the properties.
160
161    DelegateChoice {
162        roleValue: "FeatureCollection"
163        delegate: MapItemView {
164            property string geojsonType: "FeatureCollection"
165            property var props: modelData.properties
166            model: modelData.data
167            delegate: dc
168        }
169    }
170}
171