RMProjectedRect to CGRcet - ios

I want to draw bounding box shape for RMProjectedRect structs.
I need to convert RMProjectedRect to CGRect and and then create a shape and add it to superview.
does anyone know how to do this conversion?

You will want to use the RMMapView routines under Converting Map Coordinates here:
https://www.mapbox.com/mapbox-ios-sdk/api/Classes/RMMapView.html
You can convert corners of the RMProjectedRects into pixels coordinates for a given map viewport.

thanks for your hint.
Here is what I did:
CGRect frameRect = {[self.mapView projectedPointToPixel:gridMapRect.origin], [self.mapView projectedSizeToViewSize:gridMapRect.size]};

Related

Convert openCV Rect coordinates into CGRect coordinates in iOS

I want to convert openCV rectangle coordinates into CGRect so I can draw image using this.
rectangle(frame, box, Scalar(0,0,255));
In the below code I create the rectangle with these parameters as frame is mat type ,box is CGRect type.
In openCV it display rectangle correctly but I need to create UIImage with same frame.
Any help will be appreciated.
Thanks.

Drag and sacale a rectangle drawn using UIBezierPath IOS/Swift

I am developing a program which identifies a rectangle in an image and draws a path on the border of that identified rectangle. Now I want to reposition that path in case if it is not on the exact position. For an example look at this image
In cases like this i need to drag the corners of the path and reposition it as it fits the rectangle.
To draw the path I used CAShapeLayer and UIBezierPath. Here is the code I used to draw the path.
// imgView is the UIImageView which contains the image with the rectangle
let line: CAShapeLayer = CAShapeLayer();
line.frame = imgView.bounds;
let linePath: UIBezierPath = UIBezierPath();
linePath.moveToPoint(CGPointMake(x1, y1);
linePath.addLineToPoint(CGPointMake(x2, y2);
linePath.addLineToPoint(CGPointMake(x3, y3);
linePath.addLineToPoint(CGPointMake(x4, y4);
linePath.addLineToPoint(CGPointMake(x1, y1);
linePath.closePath();
line.lineWidth = 5.0;
line.path = linePath.CGPath;
line.fillColor = UIColor.clearColor().CGColor;
line.strokeColor = UIColor.blueColor().CGColor;
imgView.layer.addSublayer(line);
The thing is I tried to add a gesture to UIBezierPath. But there is nothing like that as I noticed. Couldn't find anything regarding this. So can someone please let me know a way to get my work done. Any help would be highly appreciated.
You are right that there is no way to attach a gesture recognizer to a UIBezierPath. Gesture recognizers attach to UIView objects, and a UIBezierPath is not a view object.
There is no built-in mechanism to do this. You need to do it yourself. I would suggest building a family of classes to handle it. Create a rectangle view class. It would use a bezier path internally, as well as placing 4 corner point views on the vertexes and installing pan gesture recognizers each corner point view.
Note that Cocoa rectangles (CGRects) can't be rotated. You'll need to use a series of connected line segments and write logic that forces it to stay square.

MKMapView Zoom to Fit Overlays

I have an circle overlay on my MKMap, which the user can change the radius of. How can I make it so when the radius is changed the Map will automatically zoom to fit the new radius size.
I have tried:
_mapView.visibleMapRect = circleOverlay.boundingMapRect;
But it zooms in too far and the stroke around my circle overlay is cut off at the top and bottom. Can someone give me any help on how to fix this please?
Try:
_mapView.visibleMapRect = [_mapView mapRectThatFits:circleOverlay.boundingMapRect];
or even mapRectThatFits:edgePadding: to get a little extra space around the edges.
In addition to David Berry's answer, this lets you animate the zoom:
[self.mapView setVisibleMapRect:[self.mapView mapRectThatFits:circleOverlay.boundingMapRect] edgePadding:UIEdgeInsetsMake(5.0f, 5.0f, 5.0f, 5.0f) animated:YES];

How do i rotate an image inside a drawn polygon

I am a beginner programmer and this is my first app(I am still learning). I have overlaid a polygon onto a map view. I have set its fill color to an image because I'm trying to match an image to a satellite picture. I want to rotate it so that the polygon contents match the map. Is it possible to rotate the image? If not, is there an easier way to overlay an image onto a map view that I could use.
Here is my code:
-(MKOverlayView*)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay {
MKPolygonView *polyView = [[MKPolygonView alloc] initWithOverlay:overlay];
polyView.strokeColor = [UIColor whiteColor];
polyView.fillColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Campus-map labels.jpg"]];
return polyView;
}
Here's what I'm trying to do, if it helps:
http://i.stack.imgur.com/x53HU.jpg
The road which is circled in red should match up. I know that the polygon isn't in the right position -- this is to illustrate how the polygon needs to be rotated.
You can modify the transform property of the polyView object. For example:
polyView.transform = CGAffineTransformMakeRotation(M_PI_4);
will rotate the polygon by pi/4 radians (45 degrees), in a clockwise direction.
You might need to change the polygon's center property to get the effect you want. The center property determines the center of rotation around which the transform rotation takes place.

Convert MKPolygon to UIView

I have a MKMapView with a Polygon overlay that I need to convert into a UIView. I have the reference to the MKMapView and the MKPolygon, but I can't seem to find a way to pull the coordinates of the MKPolygon and convert them back into screen coordinates for the UIView.
You can convert polygon points to view coordinates (if that is what you need) like this:
iPhone SDK: Convert MKMapPoint to CGPoint

Resources