OSGEarth绘制Geometry:绘多边形(三)
2015-07-09 22:38
369 查看
功能描述如下:
1. 鼠标多次点击的区域绘制多边形,为黄色;
2. 最近一次点击的点以及第一次点击的点和鼠标move到的点之间连线,为两条红色的虚线,表示下次即将绘制的区域块。
代码如下:drawpolygon.h
功能实现如下:drawpolygon.cpp
1. 鼠标多次点击的区域绘制多边形,为黄色;
2. 最近一次点击的点以及第一次点击的点和鼠标move到的点之间连线,为两条红色的虚线,表示下次即将绘制的区域块。
代码如下:drawpolygon.h
class DrawPolygon : public HandleAdapter { public: DrawPolygon(GraphicsView* view); ~DrawPolygon(); protected: virtual void slotPicked(osg::Vec3d pos); virtual void slotMoveing(osg::Vec3d pos); virtual void slotRightHandle(); private: std::vector<osg::Vec3d> m_vecPoints; // 多边形绘制 osgEarth::Symbology::Style m_polygonStyle; osgEarth::Annotation::FeatureNode* m_pFeatureNode; osgEarth::Annotation::FeatureEditor* m_pPolygonEdit; // 虚线 osgEarth::Symbology::Style m_stippleLineStyle; osgEarth::Annotation::FeatureNode* m_pStippleFeatureNode; };
功能实现如下:drawpolygon.cpp
DrawPolygon::DrawPolygon(GraphicsView* view) : HandleAdapter(view) { m_vecPoints.clear(); m_pFeatureNode = NULL; m_pStippleFeatureNode = NULL; m_pPolygonEdit = NULL; // 多边形的style m_polygonStyle.getOrCreate<osgEarth::Symbology::PolygonSymbol>() ->fill()->color() = osgEarth::Symbology::Color::Yellow; m_polygonStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>() ->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN; m_polygonStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>() ->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_DRAPE; m_polygonStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>() ->verticalOffset() = 0.1; // 线的style m_stippleLineStyle.getOrCreate<osgEarth::Symbology::LineSymbol>() ->stroke()->color() = osgEarth::Symbology::Color::Red; m_stippleLineStyle.getOrCreate<osgEarth::Symbology::LineSymbol>() ->stroke()->width() = 2.0; m_stippleLineStyle.getOrCreate<osgEarth::Symbology::LineSymbol>() ->tessellation() = 20.0; m_stippleLineStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>() ->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN; m_stippleLineStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>() ->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_DRAPE; m_stippleLineStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>() ->verticalOffset() = 0.1; m_stippleLineStyle.getOrCreate<osgEarth::Symbology::LineSymbol>() ->stroke()->stipple() = 255; } DrawPolygon::~DrawPolygon() { } void DrawPolygon::slotPicked(osg::Vec3d pos) { m_vecPoints.push_back(pos); if (m_vecPoints.size() <= 2) { return; } if (m_pPolygonEdit != NULL) { m_pPolygonEdit->removeChildren(0, m_pPolygonEdit->getNumChildren()); m_pPolygonEdit = NULL; } if (m_pFeatureNode == NULL) { osgEarth::Features::Feature* pFeature = new osgEarth::Features::Feature( new osgEarth::Symbology::Polygon, m_pMap3D->getSRS(), m_polygonStyle); m_pFeatureNode = new osgEarth::Annotation::FeatureNode( m_pMap3D->getMapNode(), pFeature); m_pLayerGroup->addChild(m_pFeatureNode); } osgEarth::Symbology::Geometry* pGeometry = m_pFeatureNode->getFeature()->getGeometry(); pGeometry->clear(); m_pFeatureNode->setStyle(m_polygonStyle); for (int i = 0; i < m_vecPoints.size(); ++i) { pGeometry->push_back(m_vecPoints[i]); } m_pFeatureNode->init(); if (m_pStippleFeatureNode != NULL) { m_pStippleFeatureNode->getFeature()->getGeometry()->clear(); } if (m_pPolygonEdit == NULL) { m_pPolygonEdit = new osgEarth::Annotation::FeatureEditor(m_pFeatureNode); m_pLayerGroup->addChild(m_pPolygonEdit); } } void DrawPolygon::slotMoveing(osg::Vec3d pos) { if (m_vecPoints.size() < 2) { return; } if (m_pStippleFeatureNode == NULL) { osgEarth::Features::Feature* pFeature = new osgEarth::Features::Feature( new osgEarth::Annotation::LineString, m_pMap3D->getSRS(), m_stippleLineStyle); m_pStippleFeatureNode = new osgEarth::Annotation::FeatureNode( m_pMap3D->getMapNode(), pFeature); m_pLayerGroup->addChild(m_pStippleFeatureNode); } osgEarth::Symbology::Geometry* pGeometry = m_pStippleFeatureNode->getFeature()->getGeometry(); pGeometry->clear(); m_pStippleFeatureNode->setStyle(m_stippleLineStyle); pGeometry->push_back(m_vecPoints[0]); pGeometry->push_back(pos); pGeometry->push_back(m_vecPoints[m_vecPoints.size() - 1]); m_pStippleFeatureNode->init(); } void DrawPolygon::slotRightHandle() { m_vecPoints.clear(); if (m_pStippleFeatureNode != NULL) { m_pStippleFeatureNode->getFeature()->getGeometry()->clear(); } // 确保下次绘制的多边形和这个没任何关系 m_pFeatureNode = nullptr; }
相关文章推荐
- 1. JavaScript 基础
- 使用Oracle sqlldr 快速批量导入文本文件
- EHCache入门系列(二)–在工程中单独使用
- 深入理解JAVA的多态性[转]
- 黑马程序员——高新技术---Java基础语法-循环结构和跳转语句
- mongodb 的 scala 驱动 -> casbah
- XML Schema-based configuration
- 封装自定义控件的sdk(创建静态库static library)
- Zabbix基于Proxy分布式部署实现Web监控
- EHCache入门系列(一)–简介及配置
- LigerUi之Grid使用详解(二)——数据编辑(计算每列之和之类的)
- JAVA的第一天
- 【周末作业】2015.7.9 第一周 html作业及答案
- 如何用C#检查硬盘是否是固态硬盘SSD
- 欢迎使用CSDN-markdown编辑器
- c语言第二周总结-程序存储区划分/动态申请内存/内存操作函数
- Netty通信网络参数配置
- Android酷炫实用的开源框架(UI框架)
- Photoshop常用快捷键(2)
- Contains Duplicate