Select to view content in your preferred language

Get image for legend

1106
4
Jump to solution
09-03-2012 01:08 AM
c_f_ong
Deactivated User
Hello

I've been trying to show a legend with info from a AGSUniqueValueRenderer as follows:

            AGSUniqueValueRenderer *renderer = (AGSUniqueValueRenderer *)featLayer.renderer;
            int num = [renderer.uniqueValues count];
            for (int j = 0 ; j < num ; j++)
            {
                LegendInfo *info = [[[LegendInfo alloc] init] autorelease];
                AGSUniqueValue *value = [renderer.uniqueValues objectAtIndex:j];
                if ([value.symbol isKindOfClass:[AGSPictureMarkerSymbol class]])
                {
                    AGSPictureMarkerSymbol *pms = (AGSPictureMarkerSymbol *)value.symbol;
                    info.image = [pms swatchForGeometryType:featLayer.geometryType size:CGSizeMake(24, 24)];                
                }
                else
                {
                    info.image = [value.symbol swatchForGeometryType:featLayer.geometryType size:CGSizeMake(20, 20)];                   
                }
                info.name = value.label;
                [self.legendInfos addObject:info];
            }

And to show the details in a table view. The 'value.label' is listed correctly. Images from AGSPictureMarkerSymbol do NOT appear but image from a AGSSimpleMarkerSymbol shows correctly.

Anyone knows how to make the images from AGSPictureMarkerSymbol to show correctly in a table view? The webmap is showing AGSGraphic using the correct symbols accordingly.

Thanks.

Rgds
Ong CF
0 Kudos
1 Solution

Accepted Solutions
c_f_ong
Deactivated User
Hi Nimesh

I've used AGSPictureMarkerSymbol's image property but still its imageData was null. So I went back to the hosted feature service to reset the unique values again. And after that, AGSPictureMarkerSymbol's imageData is no longer null and can now be displayed in a legend.

Thanks.

Rgds
Ong CF

View solution in original post

0 Kudos
4 Replies
c_f_ong
Deactivated User
Hello

I've checked for more details as follows:

            // Check the renderer of feature layer
            if ([featLayer.renderer isKindOfClass:[AGSUniqueValueRenderer class]])
            {
                NSLog(@"AGSUniqueValueRenderer");
                AGSUniqueValueRenderer *renderer = (AGSUniqueValueRenderer *)featLayer.renderer;
                int num = [renderer.uniqueValues count];
                for (int j = 0 ; j < num ; j++)
                {
                    LegendInfo *info = [[[LegendInfo alloc] init] autorelease];
                    AGSUniqueValue *value = [renderer.uniqueValues objectAtIndex:j];
                    if ([value.symbol isKindOfClass:[AGSPictureMarkerSymbol class]])
                    {
                        NSLog(@"j %d; label %@; AGSPictureMarkerSymbol", j, value.label);
                        AGSPictureMarkerSymbol *pms = (AGSPictureMarkerSymbol *)value.symbol;
                        info.image = [pms swatchForGeometryType:featLayer.geometryType size:CGSizeMake(8, 8)];
                        NSLog(@"symbol: %@", [value.symbol encodeToJSON]);
                    }
                    else
                    {
                        NSLog(@"j %d; label %@; NOT AGSPictureMarkerSymbol", j, value.label);
                        info.image = [value.symbol swatchForGeometryType:featLayer.geometryType size:CGSizeMake(20, 20)];                   
                        NSLog(@"symbol: %@", [value.symbol encodeToJSON]);
                    }
                    info.name = value.label;
                    [self.legendInfos addObject:info];
                }               
            }

Notes:
1. For AGSPictureMarkerSymbol:
symbol: {
    angle = 0;
    color = "<null>";
    height = 12;
    imageData = "<null>";
    imageName = "<null>";
    type = esriPMS;
    width = 12;
    xoffset = 0;
    yoffset = 0;
}

2. For NON-AGSPictureMarkerSymbol:
symbol: {
    angle = 0;
    color =     (
        0,
        0,
        128,
        128
    );
    outline =     {
        color =         (
            0,
            0,
            128,
            255
        );
        style = esriSLSSolid;
        type = esriSLS;
        width = 1;
    };
    rotateAroundOffset = false;
    size = 12;
    style = esriSMSDiamond;
    type = esriSMS;
    xoffset = 0;
    yoffset = 0;
}

So, it seems that AGSPictureMarkerSymbol is not returning an image unlike AGSSimpleMarkerSymbol. Is there any way to get the image for AGSPictureMarkerSymbol?

Thanks.

Rgds
Ong CF
0 Kudos
NimeshJarecha
Esri Regular Contributor
Why are you not using AGSPictureMarkerSymbol's image property?

Regards,
Nimesh
0 Kudos
c_f_ong
Deactivated User
Hi Nimesh

I've used AGSPictureMarkerSymbol's image property but still its imageData was null. So I went back to the hosted feature service to reset the unique values again. And after that, AGSPictureMarkerSymbol's imageData is no longer null and can now be displayed in a legend.

Thanks.

Rgds
Ong CF
0 Kudos
NimeshJarecha
Esri Regular Contributor
Glad to know that. Probabaly, null image was the reason for not generating swatch for picture marker symbol.

Regards,
Nimesh
0 Kudos