Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+325
@@ -0,0 +1,325 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* MapLayer
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
// Own
|
||||
#include "map_layer.h"
|
||||
#include <MapImpl/map_impl.h>
|
||||
#include <MapImpl/layer_factory_impl.h>
|
||||
#include <Map/situation_map_utils.h>
|
||||
|
||||
|
||||
// ESRI
|
||||
#include <arcgis/Layer.h>
|
||||
#include <arcgis/GraphicsOverlay.h>
|
||||
#include <arcgis/ArcGISTiledLayer.h>
|
||||
|
||||
|
||||
// Qt
|
||||
// #include <QDebug>
|
||||
|
||||
namespace SituationMap
|
||||
{
|
||||
|
||||
MapLayer::MapLayer(const QString &logicalName,
|
||||
LayerType layerType)
|
||||
: m_name(logicalName)
|
||||
, m_layerType(layerType)
|
||||
{
|
||||
}
|
||||
|
||||
bool MapLayer::isValid() const
|
||||
{
|
||||
return ((m_layerType != LayerType::Undefined) && (!m_name.isEmpty()));
|
||||
}
|
||||
|
||||
QString MapLayer::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
LayerType MapLayer::type() const
|
||||
{
|
||||
return m_layerType;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool MapLayerOrderedList::addLayer(const QString &name,
|
||||
LayerType layerType)
|
||||
{
|
||||
if (name.isEmpty() || layerType == LayerType::Undefined)
|
||||
return false;
|
||||
|
||||
// Do NOT allow same names for different LayerTypes:
|
||||
if (contains(name, LayerType::Undefined))
|
||||
return false;
|
||||
|
||||
MapLayer temp(name, layerType);
|
||||
if (!temp.isValid())
|
||||
return false;
|
||||
|
||||
if (layerType == LayerType::Basemap)
|
||||
{
|
||||
// Basemap -> bottom;
|
||||
int cnt = this->count(LayerType::Basemap);
|
||||
m_mapLayerList.insert(cnt, temp);
|
||||
}
|
||||
else if (layerType == LayerType::Overlay)
|
||||
{
|
||||
// Overlay -> directly above Basemap;
|
||||
int cntBM = this->count(LayerType::Basemap);
|
||||
int cntOVL = this->count(LayerType::Overlay);
|
||||
m_mapLayerList.insert(cntBM + cntOVL, temp);
|
||||
}
|
||||
else
|
||||
m_mapLayerList.append(temp);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MapLayerOrderedList::contains(const QString &name,
|
||||
LayerType layerType) const
|
||||
{
|
||||
bool found = false;
|
||||
for (const MapLayer &layer : m_mapLayerList)
|
||||
{
|
||||
if (layerType == LayerType::Undefined)
|
||||
{
|
||||
if (layer.name().compare(name) == 0)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((layer.type() == layerType) && (layer.name().compare(name) == 0))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
MapLayer MapLayerOrderedList::getLayer(const QString &name) const
|
||||
{
|
||||
for (const MapLayer &layer : m_mapLayerList)
|
||||
{
|
||||
if (layer.name().compare(name) == 0)
|
||||
return layer;
|
||||
}
|
||||
return MapLayer();
|
||||
}
|
||||
|
||||
bool MapLayerOrderedList::removeLayer(const QString &name)
|
||||
{
|
||||
// since a layername has to be unique independent it´s layertype:
|
||||
|
||||
// QMutableListIterator does not realy work, Problems with MapLayer ???
|
||||
// QMutableListIterator<MapLayer> contIt(m_mapLayerList);
|
||||
|
||||
// while (contIt.hasNext());
|
||||
// {
|
||||
// contIt.next();
|
||||
// const MapLayer & layer = contIt.value();
|
||||
// if (layer.name().compare(name) == 0)
|
||||
// {
|
||||
// contIt.remove();
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
for (int i = 0; i < m_mapLayerList.size(); ++i)
|
||||
{
|
||||
const MapLayer &layer = m_mapLayerList[i];
|
||||
if (layer.name().compare(name) == 0)
|
||||
{
|
||||
m_mapLayerList.removeAt(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int MapLayerOrderedList::count(LayerType layerType) const
|
||||
{
|
||||
if (layerType == LayerType::Undefined)
|
||||
return m_mapLayerList.size();
|
||||
|
||||
|
||||
int counter = 0;
|
||||
for (const MapLayer &mapLayer : qAsConst(m_mapLayerList))
|
||||
{
|
||||
if (mapLayer.type() == layerType)
|
||||
++counter;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
||||
QStringList MapLayerOrderedList::layernamesOfType(const QStringList &layernames, LayerType layerType)
|
||||
{
|
||||
QStringList layerCont;
|
||||
for (const QString &lName : layernames)
|
||||
{
|
||||
const MapLayer &ml = getLayer(lName);
|
||||
if (!ml.isValid())
|
||||
continue;
|
||||
if (ml.type() == layerType)
|
||||
layerCont.push_back(lName);
|
||||
}
|
||||
return layerCont;
|
||||
}
|
||||
QStringList MapLayerOrderedList::layernamesOfTypeOther(const QStringList &layernames)
|
||||
{
|
||||
QStringList layerCont;
|
||||
for (const QString &lName : layernames)
|
||||
{
|
||||
const MapLayer &ml = getLayer(lName);
|
||||
if (!ml.isValid())
|
||||
continue;
|
||||
if (
|
||||
(ml.type() != LayerType::Basemap) &&
|
||||
(ml.type() != LayerType::Overlay) &&
|
||||
(ml.type() != LayerType::Operational) &&
|
||||
(ml.type() != LayerType::EmergencyCall) &&
|
||||
(ml.type() != LayerType::Undefined)
|
||||
)
|
||||
layerCont.push_back(lName);
|
||||
}
|
||||
return layerCont;
|
||||
}
|
||||
QStringList orderStringListPerType(const QStringList &slToOrder, const QStringList &slRequested)
|
||||
{
|
||||
//
|
||||
// !!!do not lose one layer existing in slToOrder!!!
|
||||
//
|
||||
|
||||
QStringList slNew = slToOrder;
|
||||
|
||||
int newIdx = 0;
|
||||
for (const QString &name : slRequested)
|
||||
{
|
||||
int idx = slNew.indexOf(name);
|
||||
if (idx >= 0)
|
||||
{ // found
|
||||
slNew.move(idx, newIdx++);
|
||||
}
|
||||
}
|
||||
return slNew;
|
||||
}
|
||||
|
||||
|
||||
bool MapLayerOrderedList::orderLayerTo(const QStringList &orderedLayernamesReq, bool *bRequestedOrderIsValid)
|
||||
{
|
||||
// cur =ArcGISTiledLayer_URL_0;ArcGISTiledLayer_URL_1;ArcGISTiledLayer_URL_2;OverlayLayer_1001;OverlayLayer_1002;...;JumpPoints;SnaphotOverlay
|
||||
// should=ArcGISTiledLayer_URL_0;ArcGISTiledLayer_URL_1;ArcGISTiledLayer_URL_2;OverlayLayer_1002;OverlayLayer_1001;...;JumpPoints
|
||||
|
||||
QStringList slMapLayerList;
|
||||
slMapLayerList.reserve(m_mapLayerList.size());
|
||||
for (const MapLayer &ml : qAsConst(m_mapLayerList))
|
||||
slMapLayerList.push_back(ml.name());
|
||||
|
||||
//
|
||||
// !!!do not lose one layer existing in the m_mapLayerList!!!
|
||||
//
|
||||
|
||||
QStringList slBasemapNew;
|
||||
{
|
||||
QStringList slCur = layernamesOfType(slMapLayerList, LayerType::Basemap);
|
||||
QStringList slReq = layernamesOfType(orderedLayernamesReq, LayerType::Basemap);
|
||||
slBasemapNew = orderStringListPerType(slCur, slReq);
|
||||
}
|
||||
|
||||
QStringList slOverlayNew;
|
||||
{
|
||||
QStringList slCur = layernamesOfType(slMapLayerList, LayerType::Overlay);
|
||||
QStringList slReq = layernamesOfType(orderedLayernamesReq, LayerType::Overlay);
|
||||
slOverlayNew = orderStringListPerType(slCur, slReq);
|
||||
}
|
||||
|
||||
QStringList slOperationalNew;
|
||||
{
|
||||
QStringList slCur = layernamesOfType(slMapLayerList, LayerType::Operational);
|
||||
QStringList slReq = layernamesOfType(orderedLayernamesReq, LayerType::Operational);
|
||||
slOperationalNew = orderStringListPerType(slCur, slReq);
|
||||
}
|
||||
|
||||
QStringList slOtherNew;
|
||||
{
|
||||
QStringList slCur = layernamesOfTypeOther(slMapLayerList);
|
||||
QStringList slReq = layernamesOfTypeOther(orderedLayernamesReq);
|
||||
slOtherNew = orderStringListPerType(slCur, slReq);
|
||||
}
|
||||
|
||||
// Emergency should stay on top
|
||||
QStringList slEmergencyCallNew;
|
||||
{
|
||||
QStringList slCur = layernamesOfType(slMapLayerList, LayerType::EmergencyCall);
|
||||
QStringList slReq = layernamesOfType(orderedLayernamesReq, LayerType::EmergencyCall);
|
||||
slEmergencyCallNew = orderStringListPerType(slCur, slReq);
|
||||
}
|
||||
|
||||
// put all basemapLayer to front, then overlayLayers, then others and finally EmergencyCall on top
|
||||
const QStringList &slMapLayerListNEW = slBasemapNew + slOverlayNew + slOperationalNew + slOtherNew + slEmergencyCallNew;
|
||||
|
||||
const bool localRequestedOrderIsValid = slMapLayerListNEW == orderedLayernamesReq;
|
||||
|
||||
if (bRequestedOrderIsValid)
|
||||
{
|
||||
// just request, do NOT modify !!!
|
||||
*bRequestedOrderIsValid = localRequestedOrderIsValid;
|
||||
} else {
|
||||
QList<MapLayer> mlListNEW;
|
||||
for(const QString &lName : slMapLayerListNEW)
|
||||
{
|
||||
const MapLayer &ml = getLayer(lName);
|
||||
if (!ml.isValid())
|
||||
continue;
|
||||
mlListNEW.push_back(ml);
|
||||
}
|
||||
m_mapLayerList = mlListNEW;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int MapLayerOrderedList::count() const
|
||||
{
|
||||
return m_mapLayerList.count();
|
||||
}
|
||||
|
||||
QStringList MapLayerOrderedList::layerNamesOrdered() const
|
||||
{
|
||||
QStringList ll;
|
||||
ll.reserve(m_mapLayerList.size());
|
||||
for (const MapLayer &layer : m_mapLayerList)
|
||||
ll.append(layer.name());
|
||||
return ll;
|
||||
}
|
||||
|
||||
QStringList MapLayerOrderedList::layerNamesOrdered(LayerType layerType) const
|
||||
{
|
||||
QStringList ll;
|
||||
for (const MapLayer &layer : m_mapLayerList)
|
||||
{
|
||||
if (layer.type() == layerType)
|
||||
ll.append(layer.name());
|
||||
}
|
||||
return ll;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace SituationMap
|
||||
Reference in new issue
Block a user