在 WhirlyGlobe 中使用纹理作为标签

发布于 2024-12-09 09:10:47 字数 1635 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋心╮凉 2024-12-16 09:10:47

抱歉耽搁了。我需要为 stackoverflow 设置某种 feed。

不管怎样,简短的回答是没有一个很好的方法来做到这一点。我正在为客户端添加标记,但这要到 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;  

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:

Texture *theTex = new Texture(@"nameoftexture", @"png");  
theTex->setUsesMipmaps(true);  
theTexId = theTex->getId();  
scene->addChangeRequest(new AddTextureReq(theTex));  

And then to use it:

singleLabel.text = @"";  
singleLabel.iconTexture = theTexId;  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文