Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More WMS improvements:
* The "Identify" map tool now works on queryable map layers.
* The raster Properties/Metadata tab now shows if layers are queryable or not.
Errors fixed:
* Raster Properties/Metadata no longer repeats the details per layer.
Errors known:
* Layers that are non-queryable are not tested for when the Identify tool is invoked - the WMS server has to report the error instead.
* The pixel identified is not highlighted.
* Errors are not handled correctly; the window appears but no useful information is shown.



git-svn-id: http://svn.osgeo.org/qgis/trunk@5066 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Mar 19, 2006
1 parent 5373fae commit 07d23be
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 133 deletions.
15 changes: 15 additions & 0 deletions src/core/qgsrasterdataprovider.h
Expand Up @@ -93,6 +93,21 @@ class QgsRasterDataProvider : public QgsDataProvider
*/
virtual QString getMetadata() = 0;

/**
* \brief Identify details from a server (e.g. WMS) from the last screen update
*
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
*
* \retval An HTML document containing the return from the WMS server
*
* \note WMS Servers prefer to receive coordinates in image space, therefore
* this function expects coordinates in that format.
*
* \note The arbitraryness of the returned document is enforced by WMS standards
* up to at least v1.3.0
*/
virtual QString identifyAsHtml(const QgsPoint& point) = 0;

/**
* \brief Returns the caption error text for the last error in this provider
*
Expand Down
103 changes: 90 additions & 13 deletions src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/
/* $Id$ */

#include "qgsmessageviewer.h"
#include "qgsmaptoolidentify.h"
#include "qgsmapcanvas.h"
#include "qgsvectordataprovider.h"
Expand All @@ -30,10 +31,13 @@
#include <QMessageBox>
#include <QCursor>
#include <QPixmap>
#include <QObject>


QgsMapToolIdentify::QgsMapToolIdentify(QgsMapCanvas* canvas)
: QgsMapTool(canvas), mResults(NULL)
: QgsMapTool(canvas),
mResults(0),
mViewer(0)
{
// set cursor
QPixmap myIdentifyQPixmap = QPixmap((const char **) identify_cursor);
Expand All @@ -42,7 +46,15 @@ QgsMapToolIdentify::QgsMapToolIdentify(QgsMapCanvas* canvas)

QgsMapToolIdentify::~QgsMapToolIdentify()
{
delete mResults;
if (mResults)
{
delete mResults;
}

if (mViewer)
{
delete mViewer;
}
}

void QgsMapToolIdentify::canvasMoveEvent(QMouseEvent * e)
Expand All @@ -61,24 +73,38 @@ void QgsMapToolIdentify::canvasReleaseEvent(QMouseEvent * e)

if (layer)
{
// convert screen coordinates to map coordinates
QgsPoint idPoint = mCanvas->getCoordinateTransform()->toMapCoordinates(e->x(), e->y());

if (layer->type() == QgsMapLayer::VECTOR)
// In the special case of the WMS provider,
// coordinates are sent back to the server as pixel coordinates
// not the layer's native CRS. So identify on screen coordinates!
if (
(layer->type() == QgsMapLayer::RASTER)
&&
(dynamic_cast<QgsRasterLayer*>(layer)->providerKey() == "wms")
)
{
identifyVectorLayer(dynamic_cast<QgsVectorLayer*>(layer), idPoint);
}
else if (layer->type() == QgsMapLayer::RASTER)
{
identifyRasterLayer(dynamic_cast<QgsRasterLayer*>(layer), idPoint);
identifyRasterWmsLayer(dynamic_cast<QgsRasterLayer*>(layer), QgsPoint(e->x(), e->y()) );
}
else
{
// convert screen coordinates to map coordinates
QgsPoint idPoint = mCanvas->getCoordinateTransform()->toMapCoordinates(e->x(), e->y());

if (layer->type() == QgsMapLayer::VECTOR)
{
identifyVectorLayer(dynamic_cast<QgsVectorLayer*>(layer), idPoint);
}
else if (layer->type() == QgsMapLayer::RASTER)
{
identifyRasterLayer(dynamic_cast<QgsRasterLayer*>(layer), idPoint);
}
else
{
#ifdef QGISDEBUG
std::cout << "identify: unknown layer type!" << std::endl;
std::cout << "QgsMapToolIdentify::canvasReleaseEvent: unknown layer type!" << std::endl;
#endif
}
}

}
else
{
Expand Down Expand Up @@ -124,6 +150,34 @@ void QgsMapToolIdentify::identifyRasterLayer(QgsRasterLayer* layer, const QgsPoi
}


void QgsMapToolIdentify::identifyRasterWmsLayer(QgsRasterLayer* layer, const QgsPoint& point)
{
if (!layer)
{
return;
}

QString html = layer->identifyAsHtml(point);

if (html.isEmpty())
{
showError(layer);
return;
}

if (!mViewer)
{
mViewer = new QgsMessageViewer();
}

mViewer->setCaption( layer->name() );
mViewer->setMessageAsPlainText( html );
// mViewer->setMessageAsHtml( html );

// mViewer->exec();
mViewer->show();
}


void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoint& point)
{
Expand Down Expand Up @@ -313,3 +367,26 @@ void QgsMapToolIdentify::identifyVectorLayer(QgsVectorLayer* layer, const QgsPoi
}
dataProvider->reset();
}


void QgsMapToolIdentify::showError(QgsMapLayer * mapLayer)
{
// QMessageBox::warning(
// this,
// mapLayer->errorCaptionString(),
// tr("Could not draw") + " " + mapLayer->name() + " " + tr("because") + ":\n" +
// mapLayer->errorString()
// );

QgsMessageViewer * mv = new QgsMessageViewer();
mv->setCaption( mapLayer->errorCaptionString() );
mv->setMessageAsPlainText(
QObject::tr("Could not identify objects on") + " " + mapLayer->name() + " " + QObject::tr("because") + ":\n" +
mapLayer->errorString()
);
mv->exec();
delete mv;

}

// ENDS
53 changes: 40 additions & 13 deletions src/gui/qgsmaptoolidentify.h
Expand Up @@ -23,12 +23,14 @@
#define MapTool_Identify "identify"

class QgsIdentifyResults;
class QgsMessageViewer;
class QgsMapLayer;
class QgsRasterLayer;
class QgsVectorLayer;

/**
\brief Map tool for identifying features in current layer
after selecting a point shows dialog with identification results
- for raster layers shows value of underlying pixel
- for vector layers shows feature attributes within search radius
Expand All @@ -38,31 +40,56 @@ class QgsMapToolIdentify : public QgsMapTool
{
public:
QgsMapToolIdentify(QgsMapCanvas* canvas);

~QgsMapToolIdentify();

//! Overridden mouse move event
virtual void canvasMoveEvent(QMouseEvent * e);

//! Overridden mouse press event
virtual void canvasPressEvent(QMouseEvent * e);

//! Overridden mouse release event
virtual void canvasReleaseEvent(QMouseEvent * e);

virtual QString toolName() { return MapTool_Identify; }

private:

//! function for identifying raster layer

/**
* \brief function for identifying pixel values at a coordinate in a non-OGC-WMS raster layer
*
* \param point[in] The coordinate (as the CRS of the raster layer)
*/
void identifyRasterLayer(QgsRasterLayer* layer, const QgsPoint& point);

//! function for identifying vector layer

/**
* \brief function for identifying a pixel in a OGC WMS raster layer
*
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
*
* \note WMS Servers prefer to receive coordinates in image space not CRS space, therefore
* this special variant of identifyRasterLayer.
*/
void identifyRasterWmsLayer(QgsRasterLayer* layer, const QgsPoint& point);

/**
* \brief function for identifying features at a coordinate in a vector layer
*
* \param point[in] The coordinate (as the CRS of the vector layer)
*/
void identifyVectorLayer(QgsVectorLayer* layer, const QgsPoint& point);

//! Pointer to the identify results dialog
//! show whatever error is exposed by the QgsMapLayer.
void showError(QgsMapLayer * mapLayer);


//! Pointer to the identify results dialog for name/value pairs
QgsIdentifyResults *mResults;


//! Pointer to the identify results dialog for WMS XML files
QgsMessageViewer * mViewer;

};

#endif

0 comments on commit 07d23be

Please sign in to comment.