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];
还是个问题,贴图已经加载到内存中了,但是没有出现。将字符串作为文本在标签的第一个字符上创建一个空白方 block
最佳答案
抱歉耽搁了。我需要为 stackoverflow 设置某种提要。
无论如何,简短的回答是没有很好的方法来做到这一点。我正在为客户添加标记,但要到 1.2 才会发布。现在,您应该能够使标签显示纹理。这就是您在那里显示的 iconTexture。
要创建纹理,请执行以下操作:
Texture *theTex = new Texture(@"nameoftexture", @"png");
theTex->setUsesMipmaps(true);
theTexId = theTex->getId();
scene->addChangeRequest(new AddTextureReq(theTex));
然后使用它:
singleLabel.text = @"";
singleLabel.iconTexture = theTexId;
关于iphone - 在 WhirlyGlobe 中使用纹理作为标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7743562/