在绘制polyline或polygon时,QgsRubberBand类提供一种透明的widget用以追踪鼠标。它可以在map上绘制临时的feature。
创建对象并初始化:
QgsRubberBand *pRubberBand = new QgsRubberBand(pMapCanvas, QGis::Line);
pRubberBand->setColor(QColor(255, 0, 0));
pRubberBand->setWidth(2);
添加点并绘制
QPoint point = pMapCanvas->mouseLastXY();
QgsPoint pos = pMapCanvas->getCoordinateTransform()->toMapCoordinates(point);
bool preVisible = pRubberBand->isVisible();//当给QgsRubberBand添加点后,先前处于隐藏状态也会自动显示。
pRubberBand->addPoint(pos);
pRubberBand->setVisible(preVisible);

2092

被折叠的 条评论
为什么被折叠?



