osgearth setText 如何换行
本帖最后由 liyihongcug 于 2020-3-23 10:53 编辑<label text="Draped Polygon111111111111111111111111111111111111111111111111" lat="45" long="-98"/>
如何换行?
(实际需求:
上面行 Draped Polygon11111111111111111111111
下面行 11111111111111111111111111111ll
如果是html 《br》换行osgearthsetText 如何换行
)
提示: 这个问题必须使用js脚本来实现。 使用外挂dll 嵌套html 还真不如自己做
referrence:
文本Text
文字符号(SDK:TextSymbol)控制文本标签的存在和外观。
Property Description
text-fill Foreground color of the text (HTML color)
text-size Size of the text (float, pixels)
text-font Name of the font to use (system-dependent). For example, use “arialbd” on Windows for Arial Bold.
text-halo Outline color of the text; Omit this propery altogether for no outline. (HTML Color)
text-halo-offset Outline thickness (float, pixels)
text-offset-x The x offset of the text in pixels
text-offset-y The y offset of the text in pixels
text-align
Alignment of the text string relative to its anchor point:
left-top
left-center
left-bottom
left-base-line
left-bottom-base-line
center-top
center-center
center-bottom
center-base-line
center-bottom-base-line
right-top
right-center
right-bottom
right-base-line
right-bottom-base-line
base-line
text-layout
Layout of text:
ltr
rtl
vertical
text-content The actual text string to display (string-expr)
text-encoding
Character encoding of the text content:
utf-8
utf-16
utf-32
ascii
text-declutter Activate decluttering for this icon. osgEarth will attempt to automatically show or hide things so they don’t overlap on the screen. (boolean)
text-occlusion-cull Whether to occlusion cull the text so they do not display when line of sight is obstructed by terrain
text-occlusion-cull-altitude The viewer altitude (MSL) to start occlusion culling when line of sight is obstructed by terrain 本帖最后由 liyihongcug 于 2020-3-23 20:13 编辑
box oriented
总算搞定!这个就是弹窗功能
<model name="cities" driver="feature_geom">
<features name="cities" driver="ogr">
<srs>wgs84</srs>
<geometry>
POINT(-120 34)
</geometry>
</features>
<styles>
<script language="javascript" profile="full">
function getName2() {
return 'sdfsdf' + '\n' + 'sdfsdfsd';
}
</script>
<style type="text/css">
cities {
icon: "../data/placemark32.png";
icon-placement: centroid;
icon-scale: 1.0;
icon-occlusion-cull: false;
icon-occlusion-cull-altitude: 8000;
icon-declutter: true;
text-align: left_center;
text-size: 18;
text-declutter: true;
text-halo: #777;
text-bbox-fill: #00FF0033;
text-bbox-margin: 3;
text-bbox-border: #FFFFFFFF;
text-bbox-border-width: 1;
text-offset-x:200;
text-content:getName2();
altitude-offset: 100;
altitude-clamping: terrain;
altitude-technique: scene;
}
</style>
</styles>
</model>
How to add text label has multiple line
错误的text-content: "TEXT
" + +"
"+ + "\n \r \A \D" + ; OSGEarth中加入大量标签时不可避免在某些视角下会出现标签遮挡的情况,一般情况下,为了规避在某个坐标区域内集中显示一堆标签,可以对不重要的标签进行裁剪不让其显示。OSGEarth中osgEarth::Symbology::IconSymbol和osgEarth::Symbology::TextSymbol等样式类中,默认就是遮挡情况下,自动裁剪的。
通常,我们在OSGEarth中增加标志时的代码如下:
//获得地图坐标系
const osgEarth::SpatialReference* geoSRS = cOSG::earthmapNode->getMapSRS()->getGeographicSRS();
osgEarth::Symbology::Style pm;
//设置标志的图标
pm.getOrCreate<osgEarth::Symbology::IconSymbol>()->url()->setLiteral(UnicodeToAscii(_ele.icopath));
//设置文字颜色
pm.getOrCreate<osgEarth::Symbology::TextSymbol>()->halo() = osgEarth::Symbology::Color(_ele.color);
//设置要显示的文字编码
pm.getOrCreate<osgEarth::Symbology::TextSymbol>()->encoding() = osgEarth::Symbology::TextSymbol::ENCODING_UTF8;
//设置字体
pm.getOrCreate<osgEarth::Symbology::TextSymbol>()->font() = "simhei.ttf";
//设置文字大小
pm.getOrCreate<osgEarth::Symbology::TextSymbol>()->size() = _ele.size;
//按照高程地形裁剪
//pm.getOrCreate<osgEarth::Symbology::TextSymbol>()->occlusionCull() = true;
//pm.getOrCreate<osgEarth::Symbology::TextSymbol>()->occlusionCullAltitude() = 10000;
//pm.getOrCreate<osgEarth::Symbology::IconSymbol>()->occlusionCull() = true;
//pm.getOrCreate<osgEarth::Symbology::IconSymbol>()->occlusionCullAltitude() = 10000;
//构造节点,在地图的某个坐标点位置,构造指定字符串和指定配置的标志
osgEarth::Annotation::PlaceNode* _placenode = new osgEarth::Annotation::PlaceNode(cOSG::earthmapNode, osgEarth::GeoPoint(geoSRS, _ele.position.x(), _ele.position.y()), UnicodeToUtf8(_ele.text), pm);
addChild(_placenode);
以上代码加入到OSGEarth的位置标志,默认就带有自动遮挡裁剪的功能,如果某个坐标位置有一大堆文字标志和图标,将会自动进行遮挡裁剪,成图后效果如下:
如果我们不需要遮挡自动裁剪,则需要在代码增加两行,去掉默认设置的自动元素间的遮挡裁剪即可:
//去掉文字和标签的密集隐藏属性
pm.getOrCreate<osgEarth::Symbology::TextSymbol>()->declutter() = false;
pm.getOrCreate<osgEarth::Symbology::IconSymbol>()->declutter() = false; #include <osg/Camera>
#include <osgDB/ReadFile>
#include <osgText/Font>
#include <osgText/Text>
#include <osgViewer/Viewer>
www-cnblogs-com pezy p 3868666.html
osg::ref_ptr<osgText::Font> g_font = osgText::readFontFile("fonts/arial.ttf");
osg::Camera* createHUDCamera( double left, double right, double bottom, double top )
{
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
camera->setClearMask( GL_DEPTH_BUFFER_BIT );
camera->setRenderOrder( osg::Camera::POST_RENDER );
camera->setAllowEventFocus( false );
camera->setProjectionMatrix(
osg::Matrix::ortho2D(left, right, bottom, top) );
return camera.release();
}
osgText::Text* createText( const osg::Vec3& pos, const std::string& content, float size )
{
osg::ref_ptr<osgText::Text> text = new osgText::Text;
text->setFont( g_font.get() );
text->setCharacterSize( size );
text->setAxisAlignment( osgText::TextBase::XY_PLANE );
text->setPosition( pos );
text->setText( content );
return text.release();
}
int main()
{
osg::ref_ptr<osg::Geode> textGeode = new osg::Geode;
textGeode->addDrawable( createText(
osg::Vec3(150.0f, 500.0f, 0.0f),
"The Cessna monoplane",
20.0f)
);
textGeode->addDrawable( createText(
osg::Vec3(150.0f, 450.0f, 0.0f),
"Six-seat, low-wing and twin-engined",
15.0f)
);
osg::Camera* camera = createHUDCamera(0, 1024, 0, 768);
camera->addChild( textGeode.get() );
camera->getOrCreateStateSet()->setMode(
GL_LIGHTING, osg::StateAttribute::OFF );
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild( osgDB::readNodeFile("cessna.osg") );
root->addChild( camera );
osgViewer::Viewer viewer;
viewer.setUpViewInWindow(40, 40, 800, 600);
viewer.setSceneData( root.get() );
return viewer.run();
}
页:
[1]