Manually fire the Mapbox-GL-Draw drawing mode - mapbox-gl-js

I'd like to use Mapbox-GL-Draw in an app, but want to trigger polygon drawing from a button that exists outside the Mapbox map container, and not display the normal drawing control.
A hacky way to do this would be to simply move the button after it's created, but is there a simple, cleanish way to start the drawing process?

Oh, it looks like the answer is as simple as:
drawControl.changeMode('draw_polygon');

Related

iPhone iOS how to create interactive drag, rotate, resize, delete view control?

I got an app that allows users to add content to a canvas. I would like to be able to offer the user an ability to move, rotate, resize, reflect this content. Currently I'm doing this with gestures, but would like to know if there is some sort of open-source widget that draws a box around the view and adds 4 buttons to do these functions:
rotate 90 degrees
rotate freely
resize
delete
Can anyone think of an open source framework that I can add to my project to create controls like the ones displayed?
I can probably build this by hand, but debugging gesture recognizers and view rotation is not the most fun thing, so I'm looking for something more polished.
Thank you!
Here's a link to an open source control on cocoa controls that looks like something you could use: TDResizerView.
"TDResizerView is used to resize and rotate an imageview with single finger"
Sounds like a good place to start from, even if you need to modify it.
I've never used this particular control though, so take my word for what it's worth.
edit: Also keep in mind that on iOS, users generally expect gestures. Forcing them to use the handles instead of pinching or rotating may be bad for your user experience, depending on why you want the handles instead.

How can I create a tile, overlay for a scene in Cocos2d?

I'm new to Cocos2d, but I can't seem to find the answer to this. I want to add an image that is mostly transparent as an overlay to my application. The image is overlayed on the app, and does not respond to screen taps. All gestures should "pass through" to the application.
The overlay image should actually be tiled. It's a small image that should repeat both horizontally and vertically.
How can I do this? In fact, this is an overlay that I would like to display for the duration of the entire application-- not just one specific scene. Is there a simple way to do this?
The point of my overlay is that I'd like to create a pseudo-scan line affect for a game which has an "8-bit" tone. The scan lines will be generated by applying the overlay to the game. The overlay is non-interactive and should always exist. So, this isn't a "tile based game", but I do need a tiling affect for this functionality.
You should be able to create a layer in each scene, set the zOrder to something large so that it overlays everything else, and set its isTouchEnabled attribute to NO. You can then add whatever you want to the layer, which could be your patterned image. To change the alpha, just set the opacity attribute of your image. The only issue that I can foresee is that the overlay might disable touch events for layers below it.

How to use widget curent render as drag and drop image

I have wary annoying problem with dnd dragging image. When I start dragging some widget, it shows some default icon as it moves. I just want that this icon is actually widget looks itself. So it should look just as I move widget by dragging.
Is there easy way to accomplish this?
I started to look around and all I found is to set image using pixbuf
pixbuf = gtk.gdk.pixbuf_new_from_xpm_data(xpm)
myWidget.drag_source_set_icon_pixbuf(pixbuf)
This way it works, but I need to use current looks of widget, because there are themes and overlay of few images.
You can get the Cairo context of the widget, then copy it to a pixbuf:
cr = widget.window.cairo_create()
surface = cr.get_target()
surface.write_to_png('test.png')
pixbuf = gtk.gdk.pixbuf_new_from_file('test.png')
context.set_icon_pixbuf(pixbuf, 0, 0)
Here I'm going through an intermediary file to save and load the image data. There's probably a direct way to do that, but after going through the Cairo documentation and trying out various weird things, I gave up.

How to add overlays designed by user on button click in a map

I am interested in adding an option to my GIS Map application, the ability to draw Polygon, circle, polyroutes overlays for the user to search data within.The problem is that I've read and tested codes of how to draw an overlay, but they are always static.I want it to be dynamic, with dynamic center and points (or radius) set by the user on click.A mystery for me.(I'm a beginner in iPhone programming, this is my first app.)And I'm not using and don't want to use things like ArcGIS API for iPhone.I would appreciate any help.
To let the user "draw" an arbitrary polygon on the map, one approach is to use draggable annotations that represent the corners of the polygon. Provide an "Add Corner" button and some kind of Remove Corner button on each annotation.
See my answer to User creating a box on MKMapView for some more details. On that question though, the OP actually ended up using another solution described in the comments which would work well if the polygons are always rectangles.
For implementing a button in an annotation view (if you want a "Remove Corner" button on the annotations), see my answer to How to get click event from a button added over MKAnnotationView.
Once you a have a polygon or other overlay on the map, dragging it by direct touches may only be possible by adding a gesture recognizer to the map (with its own scrolling turned off) and using a custom MKOverlay and MKOverlayView that allow coordinate changes. Adding a gesture recognizer directly to an MKOverlayView doesn't seem to work and the built-in overlay classes don't allow changes to coordinates.
An alternative to moving by direct touches is putting some controls on the side (Up/Down/Left/Right/etc buttons) that modify the custom overlay.
The Apple sample app Breadcrumb gives an example of a custom overlay/view for a path. In WWDC 2010, the sample app LocationReminders gives an example of a custom overlay/view for a circle that can move and resize.
Finally, when you do a search for businesses, you could use the overlay's boundingMapRect (which is always a rectangle regardless of the overlay's shape) as the bounding box for the initial search and then check if the coordinate of each business found is in the overlay's actual shape using the answer to How to determine if an annotation is inside of MKPolygonView (iOS).

Recreating streetview effect in my own iPhone App

My app allows you too "look" around a room in every similar manner to how you can "look" around a street when you are in streetview in the Maps application. Does anyone know of a simple way to recreate this effect?
I do have an image (like the streetview image) that I would like users to look around in.
Some ideas I have:
1) Put the image in a scroll view and let users pan and zoom. This doesn't seem like it would have the same effect as when you pan around the streetview, objects near the edges stretch to give you a "lens" type effect.
2) Apply a transform to the image before drawing it in a scroll view, and reapply the transform during scrolling. This transform would create the lens effect on the currently viewed part of the image.
3) Use open GL to create a hollow sphere and apply the image as a texture on the inside of the sphere.
doesn't seem like it would work
seems like my best option but I don't know what transform to use in quartz to create this effect. I like this though because it uses a scroll view and I don't have to recreate the panning, flicking and pinching code.
seems like overkill and too much work
Any ideas?