Skip to content

Commit

Permalink
[ArcGIS REST] Fix broken browser data items
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jul 4, 2016
1 parent e4afb2f commit f861ed2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/providers/arcgisrest/qgsafsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ QVector<QgsDataItem*> QgsAfsConnectionItem::createChildren()
{
return layers;
}
QString authid = QgsArcGisRestUtils::parseSpatialReference( serviceData["spatialReference"].toMap() ).authid();

foreach ( const QVariant& layerInfo, serviceData["layers"].toList() )
{
QVariantMap layerInfoMap = layerInfo.toMap();
QString id = layerInfoMap["id"].toString();
QgsAfsLayerItem* layer = new QgsAfsLayerItem( this, mName, mUrl + "/" + id, layerInfoMap["name"].toString() );
QgsAfsLayerItem* layer = new QgsAfsLayerItem( this, mName, mUrl + "/" + id, layerInfoMap["name"].toString(), authid );
layers.append( layer );
}

Expand Down Expand Up @@ -146,10 +147,10 @@ void QgsAfsConnectionItem::deleteConnection()

///////////////////////////////////////////////////////////////////////////////

QgsAfsLayerItem::QgsAfsLayerItem( QgsDataItem* parent, const QString &name, const QString &url, const QString &title )
QgsAfsLayerItem::QgsAfsLayerItem( QgsDataItem* parent, const QString &name, const QString &url, const QString &title, const QString& authid )
: QgsLayerItem( parent, title, parent->path() + "/" + name, QString(), QgsLayerItem::Vector, "arcgisfeatureserver" )
{
mUri = url;
mUri = QString( "crs='%1' url='%2'" ).arg( authid ).arg( url );
setState( Populated );
mIconName = "mIconConnect.png";
}
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsafsdataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class QgsAfsConnectionItem : public QgsDataCollectionItem
class QgsAfsLayerItem : public QgsLayerItem
{
public:
QgsAfsLayerItem( QgsDataItem* parent, const QString& name, const QString &url, const QString& title );
QgsAfsLayerItem( QgsDataItem* parent, const QString& name, const QString &url, const QString& title , const QString &authid );
};

#endif // QGSAFSDATAITEMS_H
25 changes: 22 additions & 3 deletions src/providers/arcgisrest/qgsamsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,30 @@ QVector<QgsDataItem*> QgsAmsConnectionItem::createChildren()
return layers;
}

QString authid = QgsArcGisRestUtils::parseSpatialReference( serviceData["spatialReference"].toMap() ).authid();
QString format = "jpg";
bool found = false;
QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
foreach ( const QString& encoding, serviceData["supportedImageFormatTypes"].toString().split( "," ) )
{
foreach ( const QByteArray& fmt, supportedFormats )
{
if ( encoding.startsWith( fmt, Qt::CaseInsensitive ) )
{
format = encoding;
found = true;
break;
}
}
if ( found )
break;
}

foreach ( const QVariant& layerInfo, serviceData["layers"].toList() )
{
QVariantMap layerInfoMap = layerInfo.toMap();
QString id = layerInfoMap["id"].toString();
QgsAmsLayerItem* layer = new QgsAmsLayerItem( this, mName, mUrl + "/" + id, layerInfoMap["name"].toString() );
QgsAmsLayerItem* layer = new QgsAmsLayerItem( this, mName, mUrl, id, layerInfoMap["name"].toString(), authid, format );
layers.append( layer );
}

Expand Down Expand Up @@ -143,10 +162,10 @@ void QgsAmsConnectionItem::deleteConnection()

///////////////////////////////////////////////////////////////////////////////

QgsAmsLayerItem::QgsAmsLayerItem( QgsDataItem* parent, const QString &name, const QString &url, const QString &title )
QgsAmsLayerItem::QgsAmsLayerItem( QgsDataItem* parent, const QString& name, const QString &url, const QString& id, const QString& title, const QString& authid, const QString& format )
: QgsLayerItem( parent, title, parent->path() + "/" + name, QString(), QgsLayerItem::Raster, "arcgismapserver" )
{
mUri = url;
mUri = QString( "crs='%1' format='%2' layer='%3' url='%4'" ).arg( authid ).arg( format ).arg( id ).arg( url );
setState( Populated );
mIconName = "mIconAms.svg";
}
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsamsdataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class QgsAmsConnectionItem : public QgsDataCollectionItem
class QgsAmsLayerItem : public QgsLayerItem
{
public:
QgsAmsLayerItem( QgsDataItem* parent, const QString& name, const QString &url, const QString& title );
QgsAmsLayerItem( QgsDataItem* parent, const QString& name, const QString &url, const QString& id, const QString& title, const QString& authid, const QString& format );
};

#endif // QGSAMSDATAITEMS_H

0 comments on commit f861ed2

Please sign in to comment.