Search code examples
ios4svgcalayercashapelayer

Geographical maps with SVGKIT


I am trying to find my way using SVGKit (https://github.com/SVGKit/SVGKit) for an iOS project dealing with geographical maps.

At this point, I can access a particular area on a map using a CALayer object. That lets me access the rectangle surrounding the area.

Here is the code I use for this:

CALayer *layer=[svgView.document layerWithIdentifier:@"myLayerID"];
[layer setBackgroundColor:[UIColor orangeColor].CGColor];

if( [layer isKindOfClass:[CAShapeLayer class]] )
{
    CAShapeLayer* shapeLayer = (CAShapeLayer*) layer;
    NSLog(@"That is good so far!");
    layer.mask=shapeLayer;
}

But I need to access the precise area of the map; not only the surrounding rectangle, in order to highlight it. I have kind of read I should use the CGPathRef and a mask.

How exactly can I do this?

Thanks for any tip.


Solution

  • When you find the CALayer, cast it to a CAShapeLayer (if you can; if you have the right layer, this should work fine).

    if( [layer isKindOfClass:[CAShapeLayer class]] )
    {
       CAShapeLayer* shapeLayer = (CAShapeLayer*) layer;
    
       // Now you have access to lots more Apple methods
    }
    

    Then you can chnage the line width, fill color, etc - all sorts of funky stuff.

    Also look into CALayer.shadow* - various features from Apple there that will automatically hilight the visible parts of a layer.