在 WhirlyGlobe 中使用纹理作为标签
WhirlyGlobe 是一个非常有用的框架,我想显示国家国旗而不是每个国家的名称。 当查看LabelLayer.h时,似乎可以用图片覆盖从文本标签生成的图标纹理:
@interface SingleLabel : NSObject {
NSString *text;
WhirlyGlobe::GeoCoord loc;
NSDictionary *desc; // If set, this overrides the top level description
WhirlyGlobe::SimpleIdentity iconTexture; // If non-zero, this is the texture to use as an icon }
但我没有找到任何使用标签进行图片显示的方法。
有人可以帮助我了解如何用图片标签替换文本标签吗?
以下@Mousebird第一个答案是我实现的:
// This describes how our labels will look
NSDictionary *labelDesc =
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],@"enable",
[UIColor clearColor],@"backgroundColor",
[UIColor whiteColor],@"textColor",
[UIFont boldSystemFontOfSize:16.0],@"font",
[NSNumber numberWithInt:4],@"drawOffset",
[NSNumber numberWithFloat:0.08],@"height",
[NSNumber numberWithFloat:0.08],@"width",
nil];
// Build up an individual label
NSMutableArray *labels = [[[NSMutableArray alloc] init] autorelease];
SingleLabel *texLabel = [[[SingleLabel alloc] init] autorelease];
Texture *theTex = new Texture(@"icon", @"png");
theTex->setUsesMipmaps(true);
texLabel.text = @"";
texLabel.iconTexture = theTex->getId();
theScene->addChangeRequest(new AddTextureReq(theTex));
[texLabel setLoc:GeoCoord::CoordFromDegrees(5, -3)];
[labels addObject:texLabel];
[self.labelLayer addLabels:labels desc:labelDesc];
仍然是一个问题,纹理已加载到内存中但没有出现。将字符串作为文本在标签的第一个字符上创建一个空白方块
WhirlyGlobe is a very useful framework and I would like to display Country Flags instead of names for each countries.
When looking at LabelLayer.h it seems possible to overwrite the icontexture generated from Text label by a picture:
@interface SingleLabel : NSObject {
NSString *text;
WhirlyGlobe::GeoCoord loc;
NSDictionary *desc; // If set, this overrides the top level description
WhirlyGlobe::SimpleIdentity iconTexture; // If non-zero, this is the texture to use as an icon }
But I didn't find any way to use label for picture display.
Can someone please help me understand how to replace Text label by Picture label?
Following @Mousebird first answer here is what I"ve implemented:
// This describes how our labels will look
NSDictionary *labelDesc =
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],@"enable",
[UIColor clearColor],@"backgroundColor",
[UIColor whiteColor],@"textColor",
[UIFont boldSystemFontOfSize:16.0],@"font",
[NSNumber numberWithInt:4],@"drawOffset",
[NSNumber numberWithFloat:0.08],@"height",
[NSNumber numberWithFloat:0.08],@"width",
nil];
// Build up an individual label
NSMutableArray *labels = [[[NSMutableArray alloc] init] autorelease];
SingleLabel *texLabel = [[[SingleLabel alloc] init] autorelease];
Texture *theTex = new Texture(@"icon", @"png");
theTex->setUsesMipmaps(true);
texLabel.text = @"";
texLabel.iconTexture = theTex->getId();
theScene->addChangeRequest(new AddTextureReq(theTex));
[texLabel setLoc:GeoCoord::CoordFromDegrees(5, -3)];
[labels addObject:texLabel];
[self.labelLayer addLabels:labels desc:labelDesc];
Still a problem, the texture is loaded in memory but didn't appear. Putting a string as a text create a Blank square on the first character of the label
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉耽搁了。我需要为 stackoverflow 设置某种 feed。
不管怎样,简短的回答是没有一个很好的方法来做到这一点。我正在为客户端添加标记,但这要到 1.2 才会发布。现在,您应该能够使标签显示纹理。这就是您在那里显示的 iconTexture。
要创建纹理,请执行以下操作:
然后使用它:
Sorry for the delay. I need to set up some sort of feed for stackoverflow.
Anyway, the short answer is there isn't a great way to do it. I'm adding Markers for a client, but that won't be out until 1.2. For now, you should be able to make a label display a texture. That's the iconTexture you're showing there.
To create a texture, do the following:
And then to use it: