7#include <QtQml/QQmlInfo>
8#include <QtQuick/QSGOpacityNode>
10#include <QtQuick/private/qquickmousearea_p.h>
11#include <QtQuick/private/qquickitem_p.h>
12#include <QtPositioning/private/qdoublevector2d_p.h>
13#include <QtLocation/private/qgeomap_p.h>
14#include <QtLocation/private/qgeoprojection_p.h>
16#include <QtQuickShapes/private/qquickshape_p_p.h>
20QDeclarativeGeoMapItemBase::QDeclarativeGeoMapItemBase(QQuickItem *parent)
23 connect(
this, &QDeclarativeGeoMapItemBase::childrenChanged,
24 this, &QDeclarativeGeoMapItemBase::afterChildrenChanged);
27 connect(
this, &QQuickItem::opacityChanged,
this, &QDeclarativeGeoMapItemBase::mapItemOpacityChanged);
30QDeclarativeGeoMapItemBase::~QDeclarativeGeoMapItemBase()
32 disconnect(
this, &QDeclarativeGeoMapItemBase::childrenChanged,
33 this, &QDeclarativeGeoMapItemBase::afterChildrenChanged);
35 quickMap_->removeMapItem(
this);
39
40
41void QDeclarativeGeoMapItemBase::afterChildrenChanged()
43 const QList<QQuickItem *> kids = childItems();
44 if (kids.size() > 0) {
45 bool printedWarning =
false;
46 for (
auto *i : kids) {
47 if (i->flags() & QQuickItem::ItemHasContents
48 && !qobject_cast<QQuickMouseArea *>(i)
49 && i->objectName() != QStringLiteral(
"_qt_map_item_shape"))
51 if (!printedWarning) {
52 qmlWarning(
this) <<
"Geographic map items do not support child items";
53 printedWarning =
true;
56 qmlWarning(i) <<
"deleting this child";
64
65
66void QDeclarativeGeoMapItemBase::setMap(QDeclarativeGeoMap *quickMap, QGeoMap *map)
68 if (quickMap == quickMap_)
70 if (quickMap && quickMap_)
76 if (map_ && quickMap_) {
80 lastMapSize_ = QSizeF(quickMap_->width(), quickMap_->height());
81 lastCameraData_ = map_->cameraData();
86
87
88void QDeclarativeGeoMapItemBase::baseCameraDataChanged(
const QGeoCameraData &cameraData)
90 QGeoMapViewportChangeEvent evt;
91 evt.cameraData = cameraData;
92 evt.mapSize = QSizeF(quickMap_->width(), quickMap_->height());
94 if (evt.mapSize != lastMapSize_)
95 evt.mapSizeChanged =
true;
97 if (cameraData.bearing() != lastCameraData_.bearing())
98 evt.bearingChanged =
true;
99 if (cameraData.center() != lastCameraData_.center())
100 evt.centerChanged =
true;
101 if (cameraData.roll() != lastCameraData_.roll())
102 evt.rollChanged =
true;
103 if (cameraData.tilt() != lastCameraData_.tilt())
104 evt.tiltChanged =
true;
105 if (cameraData.zoomLevel() != lastCameraData_.zoomLevel())
106 evt.zoomLevelChanged =
true;
108 lastMapSize_ = evt.mapSize;
109 lastCameraData_ = cameraData;
111 afterViewportChanged(evt);
114void QDeclarativeGeoMapItemBase::visibleAreaChanged()
116 QGeoMapViewportChangeEvent evt;
117 evt.mapSize = QSizeF(quickMap_->width(), quickMap_->height());
118 afterViewportChanged(evt);
122
123
124void QDeclarativeGeoMapItemBase::setPositionOnMap(
const QGeoCoordinate &coordinate,
const QPointF &offset)
126 if (!map_ || !quickMap_)
130 if (map()->geoProjection().projectionType() == QGeoProjection::ProjectionWebMercator) {
131 const QGeoProjectionWebMercator &p =
static_cast<
const QGeoProjectionWebMercator&>(map()->geoProjection());
132 QDoubleVector2D wrappedProjection = p.geoToWrappedMapProjection(coordinate);
133 if (!p.isProjectable(wrappedProjection))
135 pos = p.wrappedMapProjectionToItemPosition(wrappedProjection);
137 pos = map()->geoProjection().coordinateToItemPosition(coordinate,
false);
142 QPointF topLeft = pos.toPointF() - offset;
144 setPosition(topLeft);
147bool QDeclarativeGeoMapItemBase::autoFadeIn()
const
155void QDeclarativeGeoMapItemBase::setAutoFadeIn(
bool fadeIn)
157 if (fadeIn == m_autoFadeIn)
159 m_autoFadeIn = fadeIn;
160 if (quickMap_ && quickMap_->zoomLevel() < opacityRampMax)
164QLocation::ReferenceSurface QDeclarativeGeoMapItemBase::referenceSurface()
const
166 return m_referenceSurface;
169void QDeclarativeGeoMapItemBase::setReferenceSurface(QLocation::ReferenceSurface referenceSurface)
171 if (referenceSurface == m_referenceSurface)
173 m_referenceSurface = referenceSurface;
174 emit referenceSurfaceChanged();
178int QDeclarativeGeoMapItemBase::lodThreshold()
const
180 return m_lodThreshold;
183void QDeclarativeGeoMapItemBase::setLodThreshold(
int lt)
185 if (lt == m_lodThreshold)
192
193
194
195
196
197
198unsigned int QDeclarativeGeoMapItemBase::zoomForLOD(
int zoom)
const
200 if (zoom >= m_lodThreshold)
206
207
208float QDeclarativeGeoMapItemBase::zoomLevelOpacity()
const
212 else if (quickMap_->zoomLevel() > opacityRampMax)
214 else if (quickMap_->zoomLevel() > opacityRampMin)
215 return quickMap_->zoomLevel() - opacityRampMin;
220void QDeclarativeGeoMapItemBase::setShapeTriangulationScale(QQuickShape *shape, qreal maxCoord)
const
222 const qreal zoom = qMax(0.01, quickMap_->zoomLevel());
223 qreal scale = 1 / zoom;
226 qint64 coord = qint64(maxCoord);
227 const qint64 COORD_LIMIT = (1 << 21) / 32;
228 while (coord > COORD_LIMIT) {
229 coord /= COORD_LIMIT;
230 scale /= COORD_LIMIT;
233 QQuickShapePrivate::get(shape)->triangulationScale = scale;
237
238
239QSGNode *QDeclarativeGeoMapItemBase::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *pd)
241 if (!map_ || !quickMap_ || map_->supportedMapItemTypes() & itemType()) {
248 QSGOpacityNode *opn =
static_cast<QSGOpacityNode *>(oldNode);
250 opn =
new QSGOpacityNode();
252 opn->setOpacity(zoomLevelOpacity());
254 QSGNode *oldN = opn->childCount() ? opn->firstChild() : 0;
255 opn->removeAllChildNodes();
256 if (opn->opacity() > 0.0) {
257 QSGNode *n =
this->updateMapItemPaintNode(oldN, pd);
259 opn->appendChildNode(n);
268
269
270QSGNode *QDeclarativeGeoMapItemBase::updateMapItemPaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
277
278
279
280
281
282qreal QDeclarativeGeoMapItemBase::mapItemOpacity()
const
285 return parentGroup_->mapItemOpacity() * opacity();
289void QDeclarativeGeoMapItemBase::setParentGroup(QDeclarativeGeoMapItemGroup &parentGroup)
291 parentGroup_ = &parentGroup;
293 connect(parentGroup_, &QDeclarativeGeoMapItemGroup::mapItemOpacityChanged,
294 this, &QDeclarativeGeoMapItemBase::mapItemOpacityChanged);
298bool QDeclarativeGeoMapItemBase::isPolishScheduled()
const
300 return QQuickItemPrivate::get(
this)->polishScheduled;
303void QDeclarativeGeoMapItemBase::polishAndUpdate()
static const double opacityRampMin
static const double opacityRampMax