How to make ol draw interaction only accept drawings that snaps to a given feature - openlayers-3

How would i make the Draw interaction do the following:
Draw a linestring, but only accept the first point when it is snapped (connected) to an existing feature/geometry?
Is there a way to cancel the mouse click, start draw when a condition is not true?

Related

Swift SceneKit - I am trying to figure out if a Node object goes off the screen

Using SceneKit
I want to make the gray transparent box to disappear and only show the colored boxes when the user zooms in.
So I want to detect when that box's edges are starting to fall off the screen as I zoom, so I can hide the gray box accordingly.
First thoughts, but there may be better solutions:
You could do an unprojectPoint on the node and check against screen coordinates, do the +/- math on object size and skip Z. I "think" that would work
You can do some physics based collision detection against an invisible box or plane geometries that acts as your screen edges, has some complexity if your view is changing, but testing would be easy - just leave visible until you get what you want, then isVisible=false
isNode(insideFrustomof: ) - returns boolean on whether it "might" be visible. I'm assuming "might" means obscured by other geometry which in your case, shouldn't matter (edit) on second thought, that doesn't solve your problem but I'll leave it in here for reference.

How to split an image into polygons

Similar to some coloring apps that fill a certain region with selected color when tapped, I would like to convert a png image to polygons which could be tapped in order to perform a certain action. An example picture is posted below.
For this example, I would like to implement the logic to divide the image into regions 1, 2, 3, and 4 (not necessarily in this order) so when the user taps on the upper-left rectangle, action1, for upper-right rectangle action2, for the ellipse actions, and for the rest action3 is executed.
Does anyone know how to do it by using SpriteKit?
You don't need to split the image into regions. Attach a tap gesture recognizer to your image view.
In the action of the tap gesture recognizer, take the coordinates of the tap and figure out which region it falls into.
Rectangular regions are really easy. You just see if the coordinates fall within the x/y bounds of the rectangle.
For more complex shapes, you can create UIBezierPath shapes and use the UIBezierPath contains(_:) method to see if the tap point falls in a particular path.
The simplest way to structure your code would be an array of structs each of which contains a UIBezierPath and a closure to invoke if a tap lands in that path. You can then invoke the closure when a tap lands in one of those paths.

Overlapping Circular Buttons and Hit/Tap Testing

I am trying to create a Tabla drum app (a Table is a pair of small hand drums attached together). To do this I want to use a button for each section of the drum by putting one on top of another. Like so:
I've tried using a circular image for the button but the surrounding area are a rectangle. That means when the user would hit parts of the green circle it plays the sound for the orange circle (I hope that makes sense).
How can I ensure the sound for the green pad is played when the user taps in the green pad, and the sound for the orange pad is played when the user taps the orange pad?
There is no "simple way" to limit the tap-detection area. You are perfectly correct: the button's tap-detection area is its rectangle, and that's all it knows about. Therefore, you can't use the button's simple tap-detection to do the work for you. You are going to have to detect the tap yourself, look at where it is, and use that knowledge plus your knowledge of where the drawings of the circles are to decide which section of the drum the user tapped in.
Look at UITapGestureRecognizer for a way to find out that the user tapped and where.
Look at UIBezierPath for a way to do hit detection with respect to a shape (e.g. a circle, answering the question, "is this point in this circle").
Your best bet might be to modify the built-in hit-testing, i.e. a UIButton or UIView subclass in which you override pointInside:withEvent: to return YES only if the point is within the interior circle, e.g.:
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
UIBezierPath* p = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
return [p containsPoint:point];
}
That is about as "simple" as it's going to get, I'm afraid.

Rotating UIImageView on fixed point

In my app I wanted to position in the center of the screen a UIImage, with the shape of a circle. Then I wanted the user to be able to rotate the image buy touching one specific point on the circumference of the circle, and dragging, just like a wheel, but I have no idea where to start form.
I know I can use the touches began, moved, and ended, but how can I fix a point?
You can adjust the origin property of your UIView. This should force the rotation around that point.

How to draw a free hand polygon by one finger touch on top of mkmapview?

I would like to draw a free hand polygon with one finger on top of a Mkmapview. I know how to draw a free hand polygon on a UIView and I know how to bring up a mkmapview.
I don't know if I can use the overlay function because I need to draw the polygon when my finger moved. I assume that this involves multitouch event and drawRect but i can not make it work when I put them together.
Thanks in advance if someone can help.

Resources