开发者

Using Texture as label in WhirlyGlobe

开发者 https://www.devze.com 2023-04-12 08:29 出处:网络
WhirlyGlobe is a very useful framework and I would like to display Country Flags i开发者_运维技巧nstead of names for each countries.

WhirlyGlobe is a very useful framework and I would like to display Country Flags i开发者_运维技巧nstead 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


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;  
0

精彩评论

暂无评论...
验证码 换一张
取 消