8#include <QtQml/QQmlInfo>
9#include <QtQuick/QSGOpacityNode>
11#include <QtQuick/private/qquickmousearea_p.h>
12#include <QtQuick/private/qquickitem_p.h>
13#include <QtPositioning/private/qdoublevector2d_p.h>
14#include <QtLocation/private/qgeomap_p.h>
15#include <QtLocation/private/qgeoprojection_p.h>
17#include <QtQuickShapes/private/qquickshape_p_p.h>
21QDeclarativeGeoMapItemBase::QDeclarativeGeoMapItemBase(QQuickItem *parent)
24 connect(
this, &QDeclarativeGeoMapItemBase::childrenChanged,
25 this, &QDeclarativeGeoMapItemBase::afterChildrenChanged);
28 connect(
this, &QQuickItem::opacityChanged,
this, &QDeclarativeGeoMapItemBase::mapItemOpacityChanged);
31QDeclarativeGeoMapItemBase::~QDeclarativeGeoMapItemBase()
33 disconnect(
this, &QDeclarativeGeoMapItemBase::childrenChanged,
34 this, &QDeclarativeGeoMapItemBase::afterChildrenChanged);
36 quickMap_->removeMapItem(
this);
40
41
42void QDeclarativeGeoMapItemBase::afterChildrenChanged()
44 const QList<QQuickItem *> kids = childItems();
45 if (kids.size() > 0) {
46 bool printedWarning =
false;
47 for (
auto *i : kids) {
48 if (i->flags() & QQuickItem::ItemHasContents
49 && !qobject_cast<QQuickMouseArea *>(i)
50 && i->objectName() != QStringLiteral(
"_qt_map_item_shape"))
52 if (!printedWarning) {
53 qmlWarning(
this) <<
"Geographic map items do not support child items";
54 printedWarning =
true;
57 qmlWarning(i) <<
"deleting this child";
65
66
67void QDeclarativeGeoMapItemBase::setMap(QDeclarativeGeoMap *quickMap, QGeoMap *map)
69 if (quickMap == quickMap_)
71 if (quickMap && quickMap_)
77 if (map_ && quickMap_) {
81 lastMapSize_ = QSizeF(quickMap_->width(), quickMap_->height());
82 lastCameraData_ = map_->cameraData();
87
88
89void QDeclarativeGeoMapItemBase::baseCameraDataChanged(
const QGeoCameraData &cameraData)
91 QGeoMapViewportChangeEvent evt;
92 evt.cameraData = cameraData;
93 evt.mapSize = QSizeF(quickMap_->width(), quickMap_->height());
95 if (evt.mapSize != lastMapSize_)
96 evt.mapSizeChanged =
true;
98 if (cameraData.bearing() != lastCameraData_.bearing())
99 evt.bearingChanged =
true;
100 if (cameraData.center() != lastCameraData_.center())
101 evt.centerChanged =
true;
102 if (cameraData.roll() != lastCameraData_.roll())
103 evt.rollChanged =
true;
104 if (cameraData.tilt() != lastCameraData_.tilt())
105 evt.tiltChanged =
true;
106 if (cameraData.zoomLevel() != lastCameraData_.zoomLevel())
107 evt.zoomLevelChanged =
true;
109 lastMapSize_ = evt.mapSize;
110 lastCameraData_ = cameraData;
112 afterViewportChanged(evt);
115void QDeclarativeGeoMapItemBase::visibleAreaChanged()
117 QGeoMapViewportChangeEvent evt;
118 evt.mapSize = QSizeF(quickMap_->width(), quickMap_->height());
119 afterViewportChanged(evt);
123
124
125void QDeclarativeGeoMapItemBase::setPositionOnMap(
const QGeoCoordinate &coordinate,
const QPointF &offset)
127 if (!map_ || !quickMap_)
131 if (map()->geoProjection().projectionType() == QGeoProjection::ProjectionWebMercator) {
132 const QGeoProjectionWebMercator &p =
static_cast<
const QGeoProjectionWebMercator&>(map()->geoProjection());
133 QDoubleVector2D wrappedProjection = p.geoToWrappedMapProjection(coordinate);
134 if (!p.isProjectable(wrappedProjection))
136 pos = p.wrappedMapProjectionToItemPosition(wrappedProjection);
138 pos = map()->geoProjection().coordinateToItemPosition(coordinate,
false);
143 QPointF topLeft = pos.toPointF() - offset;
145 setPosition(topLeft);
148bool QDeclarativeGeoMapItemBase::autoFadeIn()
const
156void QDeclarativeGeoMapItemBase::setAutoFadeIn(
bool fadeIn)
158 if (fadeIn == m_autoFadeIn)
160 m_autoFadeIn = fadeIn;
161 if (quickMap_ && quickMap_->zoomLevel() < opacityRampMax)
165QLocation::ReferenceSurface QDeclarativeGeoMapItemBase::referenceSurface()
const
167 return m_referenceSurface;
170void QDeclarativeGeoMapItemBase::setReferenceSurface(QLocation::ReferenceSurface referenceSurface)
172 if (referenceSurface == m_referenceSurface)
174 m_referenceSurface = referenceSurface;
175 emit referenceSurfaceChanged();
179int QDeclarativeGeoMapItemBase::lodThreshold()
const
181 return m_lodThreshold;
184void QDeclarativeGeoMapItemBase::setLodThreshold(
int lt)
186 if (lt == m_lodThreshold)
193
194
195
196
197
198
199unsigned int QDeclarativeGeoMapItemBase::zoomForLOD(
int zoom)
const
201 if (zoom >= m_lodThreshold)
207
208
209float QDeclarativeGeoMapItemBase::zoomLevelOpacity()
const
213 else if (quickMap_->zoomLevel() > opacityRampMax)
215 else if (quickMap_->zoomLevel() > opacityRampMin)
216 return quickMap_->zoomLevel() - opacityRampMin;
221void QDeclarativeGeoMapItemBase::setShapeTriangulationScale(QQuickShape *shape, qreal maxCoord)
const
223 const qreal zoom = qMax(0.01, quickMap_->zoomLevel());
224 qreal scale = 1 / zoom;
227 qint64 coord = qint64(maxCoord);
228 const qint64 COORD_LIMIT = (1 << 21) / 32;
229 while (coord > COORD_LIMIT) {
230 coord /= COORD_LIMIT;
231 scale /= COORD_LIMIT;
234 QQuickShapePrivate::get(shape)->triangulationScale = scale;
238
239
240QSGNode *QDeclarativeGeoMapItemBase::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *pd)
242 if (!map_ || !quickMap_ || map_->supportedMapItemTypes() & itemType()) {
249 QSGOpacityNode *opn =
static_cast<QSGOpacityNode *>(oldNode);
251 opn =
new QSGOpacityNode();
253 opn->setOpacity(zoomLevelOpacity());
255 QSGNode *oldN = opn->childCount() ? opn->firstChild() : 0;
256 opn->removeAllChildNodes();
257 if (opn->opacity() > 0.0) {
258 QSGNode *n =
this->updateMapItemPaintNode(oldN, pd);
260 opn->appendChildNode(n);
269
270
271QSGNode *QDeclarativeGeoMapItemBase::updateMapItemPaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
278
279
280
281
282
283qreal QDeclarativeGeoMapItemBase::mapItemOpacity()
const
286 return parentGroup_->mapItemOpacity() * opacity();
290void QDeclarativeGeoMapItemBase::setParentGroup(QDeclarativeGeoMapItemGroup &parentGroup)
292 parentGroup_ = &parentGroup;
294 connect(parentGroup_, &QDeclarativeGeoMapItemGroup::mapItemOpacityChanged,
295 this, &QDeclarativeGeoMapItemBase::mapItemOpacityChanged);
299bool QDeclarativeGeoMapItemBase::isPolishScheduled()
const
301 return QQuickItemPrivate::get(
this)->polishScheduled;
304void QDeclarativeGeoMapItemBase::polishAndUpdate()
static const double opacityRampMin
static const double opacityRampMax