1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtLocation module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL3$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or later as published by the Free
28 ** Software Foundation and appearing in the file LICENSE.GPL included in
29 ** the packaging of this file. Please review the following information to
30 ** ensure the GNU General Public License version 2.0 requirements will be
31 ** met: http://www.gnu.org/licenses/gpl-2.0.html.
32 **
33 ** $QT_END_LICENSE$
34 **
35 ****************************************************************************/
36 
37 #include "qgeotiledmaplabs_p.h"
38 #include <QtLocation/private/qgeotiledmap_p_p.h>
39 #include <QtLocation/private/qgeomapobject_p.h>
40 #include <QtLocation/private/qmappolylineobjectqsg_p_p.h>
41 #include <QtLocation/private/qmappolygonobjectqsg_p_p.h>
42 #include <QtLocation/private/qmapcircleobjectqsg_p_p.h>
43 #include <QtLocation/private/qmaprouteobjectqsg_p_p.h>
44 #include <QtLocation/private/qmapiconobjectqsg_p_p.h>
45 #include <QtLocation/private/qdeclarativepolylinemapitem_p.h>
46 #include <QtLocation/private/qgeomapobjectqsgsupport_p.h>
47 #include <QtPositioning/private/qlocationutils_p.h>
48 #include <math.h>
49 
50 QT_BEGIN_NAMESPACE
51 
52 class QGeoTiledMapLabsPrivate : public QGeoTiledMapPrivate
53 {
54     Q_DECLARE_PUBLIC(QGeoTiledMapLabs)
55 public:
56     QGeoTiledMapLabsPrivate(QGeoTiledMappingManagerEngine *engine, QGeoTiledMapLabs *map);
57     virtual ~QGeoTiledMapLabsPrivate();
58 
59     QGeoMapObjectPrivate *createMapObjectImplementation(QGeoMapObject *obj) override;
60     virtual QList<QGeoMapObject *> mapObjects() const override;
61     void removeMapObject(QGeoMapObject *obj);
62     QList<QObject *>mapObjectsAt(const QGeoCoordinate &coordinate) const;
63 
64     void updateMapObjects(QSGNode *root, QQuickWindow *window);
65     void updateObjectsGeometry();
66 
67 protected:
68     void changeViewportSize(const QSize &size) override;
69     void changeCameraData(const QGeoCameraData &oldCameraData) override;
70     void changeActiveMapType(const QGeoMapType mapType) override;
71 
72     QGeoMapObjectQSGSupport m_qsgSupport;
73 };
74 
QGeoTiledMapLabsPrivate(QGeoTiledMappingManagerEngine * engine,QGeoTiledMapLabs * map)75 QGeoTiledMapLabsPrivate::QGeoTiledMapLabsPrivate(QGeoTiledMappingManagerEngine *engine, QGeoTiledMapLabs *map)
76     : QGeoTiledMapPrivate(engine)
77 {
78     m_qsgSupport.m_map = map;
79 }
80 
~QGeoTiledMapLabsPrivate()81 QGeoTiledMapLabsPrivate::~QGeoTiledMapLabsPrivate()
82 {
83 
84 }
85 
createMapObjectImplementation(QGeoMapObject * obj)86 QGeoMapObjectPrivate *QGeoTiledMapLabsPrivate::createMapObjectImplementation(QGeoMapObject *obj)
87 {
88     return m_qsgSupport.createMapObjectImplementationPrivate(obj);
89 }
90 
mapObjects() const91 QList<QGeoMapObject *> QGeoTiledMapLabsPrivate::mapObjects() const
92 {
93     return m_qsgSupport.mapObjects();
94 }
95 
removeMapObject(QGeoMapObject * obj)96 void QGeoTiledMapLabsPrivate::removeMapObject(QGeoMapObject *obj)
97 {
98     m_qsgSupport.removeMapObject(obj);
99 }
100 
mapObjectsAt(const QGeoCoordinate & coordinate) const101 QList<QObject *> QGeoTiledMapLabsPrivate::mapObjectsAt(const QGeoCoordinate &coordinate) const
102 {
103     // ToDo: use a space partitioning strategy
104     QList<QObject *> res;
105     for (const auto o: mapObjects()) {
106         // explicitly handle lines
107         bool contains = false;
108         if (o->type() == QGeoMapObject::PolylineType ) {
109             QMapPolylineObject *mpo = static_cast<QMapPolylineObject *>(o);
110             qreal mpp = QLocationUtils::metersPerPixel(m_cameraData.zoomLevel(), coordinate);
111             QGeoPath path = o->geoShape();
112             path.setWidth(mpp * mpo->border()->width());
113             contains = path.contains(coordinate);
114         } else if (o->type() == QGeoMapObject::RouteType) {
115             qreal mpp = QLocationUtils::metersPerPixel(m_cameraData.zoomLevel(), coordinate);
116             QGeoPath path = o->geoShape();
117             path.setWidth(mpp * 4); // MapRouteObjectQSG has a hardcoded 4 pixels width;
118             contains = path.contains(coordinate);
119         } else {
120             contains = o->geoShape().contains(coordinate);
121         }
122 
123         if (contains)
124             res.append(o);
125     }
126     return res;
127 }
128 
updateMapObjects(QSGNode * root,QQuickWindow * window)129 void QGeoTiledMapLabsPrivate::updateMapObjects(QSGNode *root, QQuickWindow *window)
130 {
131     m_qsgSupport.updateMapObjects(root, window);
132 }
133 
updateObjectsGeometry()134 void QGeoTiledMapLabsPrivate::updateObjectsGeometry()
135 {
136     m_qsgSupport.updateObjectsGeometry();
137 }
138 
changeViewportSize(const QSize & size)139 void QGeoTiledMapLabsPrivate::changeViewportSize(const QSize &size)
140 {
141     updateObjectsGeometry();
142     QGeoTiledMapPrivate::changeViewportSize(size);
143 }
144 
changeCameraData(const QGeoCameraData & oldCameraData)145 void QGeoTiledMapLabsPrivate::changeCameraData(const QGeoCameraData &oldCameraData)
146 {
147     updateObjectsGeometry();
148     QGeoTiledMapPrivate::changeCameraData(oldCameraData);
149 }
150 
changeActiveMapType(const QGeoMapType mapType)151 void QGeoTiledMapLabsPrivate::changeActiveMapType(const QGeoMapType mapType)
152 {
153     updateObjectsGeometry();
154     QGeoTiledMapPrivate::changeActiveMapType(mapType);
155 }
156 
157 
158 /*
159     QGeoTiledMapLabs
160 */
161 
162 
163 
QGeoTiledMapLabs(QGeoTiledMappingManagerEngine * engine,QObject * parent)164 QGeoTiledMapLabs::QGeoTiledMapLabs(QGeoTiledMappingManagerEngine *engine, QObject *parent)
165     : QGeoTiledMap(*new QGeoTiledMapLabsPrivate(engine, this), engine, parent)
166 {
167 
168 }
169 
~QGeoTiledMapLabs()170 QGeoTiledMapLabs::~QGeoTiledMapLabs()
171 {
172 
173 }
174 
createMapObjectImplementation(QGeoMapObject * obj)175 bool QGeoTiledMapLabs::createMapObjectImplementation(QGeoMapObject *obj)
176 {
177     Q_D(QGeoTiledMapLabs);
178     return d->m_qsgSupport.createMapObjectImplementation(obj, d);
179 }
180 
updateSceneGraph(QSGNode * node,QQuickWindow * window)181 QSGNode *QGeoTiledMapLabs::updateSceneGraph(QSGNode *node, QQuickWindow *window)
182 {
183     Q_D(QGeoTiledMapLabs);
184     QSGNode *root = QGeoTiledMap::updateSceneGraph(node, window);
185     d->updateMapObjects(root, window);
186     return root;
187 }
188 
removeMapObject(QGeoMapObject * obj)189 void QGeoTiledMapLabs::removeMapObject(QGeoMapObject *obj)
190 {
191     Q_D(QGeoTiledMapLabs);
192     d->removeMapObject(obj);
193 }
194 
mapObjectsAt(const QGeoCoordinate & coordinate) const195 QList<QObject *> QGeoTiledMapLabs::mapObjectsAt(const QGeoCoordinate &coordinate) const
196 {
197     Q_D(const QGeoTiledMapLabs);
198     return d->mapObjectsAt(coordinate);
199 }
200 
QGeoTiledMapLabs(QGeoTiledMapLabsPrivate & dd,QGeoTiledMappingManagerEngine * engine,QObject * parent)201 QGeoTiledMapLabs::QGeoTiledMapLabs(QGeoTiledMapLabsPrivate &dd, QGeoTiledMappingManagerEngine *engine, QObject *parent)
202     : QGeoTiledMap(dd, engine, parent)
203 {
204 
205 }
206 
207 QT_END_NAMESPACE
208 
209