2

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.

Michel
  • 10,303
  • 17
  • 82
  • 179

1 Answers1

0

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.

Adam
  • 32,900
  • 16
  • 126
  • 153
  • Thanks for this reply. Actually yes I can cast it to a CAShapeLayer. But I still do not reach the final goal which is hilighting the area. I edited my question to reflect what I did. I presume the CAShapeLayer that I get has already got the right path to be used as an adequate mask. Is this wrong? I am kind of lost here. I thought using SVGKit would make things rather easy, but obviously this is not the case, at least for start. – Michel Dec 27 '12 at 11:14
  • You need to read the Apple API Documentation ... your code above makes no sense. You can't use a layer as a mask of itself! – Adam Dec 27 '12 at 17:45