React leaflet draw - deleting layer doesn't work if overlapped with another layer of higher z-index - z-index

I am using React leaflet draw and facing an issue while deleting drawn layer when it is overlapped with another layer of a higher z-index. Is it possible to control the z-index of react-leaflet-draw's FeatureGroup/EditControl to render the drawn layer at the extreme top?
I can delete the layers programmatically like below or by clicking on clear all layers, but I want to be able to click to delete individual layers based on the requirement.
//To programmatically delete:
const mapObject = useMap();
drawnLayers.forEach((layer) => { //drawnLayers = array storing the layers received in onCreated handler
mapObject.removeLayer(layer);
});

Related

Steps to integrate fabricjs into existing application

There exists legacy application having 3 canvas. First canvas to display objects which is stored in container, second canvas when object is selected and third one when object is moved or added for editing. I want to use the text and image feature of fabricJS into my existing application. While creating fabricJS canvas, i provided editing canvas object then all the mouse events bind to the editing canvas stopped working. So does there exists way to use fabricJS into existing application only for using the text and image feature of fabricJS.
You should be able to dynamically assign a z-index value to a canvas layer to expose or hide the layer to mouse events.
For the layers that you want to hide mouse events from, set z-index value to -1. For the layer that you want to expose to mouse events, set z-index value to 1.
var textLayer = document.getElementById("text-layer");
textLayer.style["z-index"] = 1;

How to resolve overlapping issue with joint js links

I need a solution to resolve the over lapping issue with joint js links.
For example
Image1
to
Image2
I'm implementing a process flow diagram in JointJS where the user can delete elements as well as add new ones, and re-link things in a variety of orderings. The graph is using the auto-layout features of the joint.layout.DirectedGraph library with Dagre to re-organize the graph each time something is deleted, added, unlinked or re-linked. One odd issue has cropped up and I'm not sure yet how to handle it.
Say I have a "fork" process with two out ports, one on each side, and a single in port at the top. Depending on the ordering of the elements in the array, the auto layout can sometimes place the child element of the left-hand port to the right of the child element of the right-hand port, so the resulting links are crossed.
Is there some straightforward way to influence the rank ordering in the layout?
I have tried the below soluiton
joint.layout.DirectedGraph.layout(this.graph, {
setLinkVertices: true,
ranker: 'longer-path',
rankDir: 'TB',
dagre: dagre,
rankSep: parseInt(70, 10),
edgeSep: parseInt(30, 10),
marginX: 100,
marginY: 270
});

Particles generated behind sprite

I just started out with Phaser.
I have a simple sprite in the middle of the screen, and whenever I click the sprite, I emit a particle at the clicked x,y coordinates.
My problem is that the particles are generated behind the sprite. I have tried setting z on the sprite to 1 and the emitter to 1000 without luck.
What am I missing?
var emitter = game.add.emitter(game.world.centerX, game.world.centeryY);
emitter.makeParticles('phaser');
var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser');
sprite.scale.setTo(2, 2);
sprite.inputEnabled = true;
sprite.events.onInputDown.add(function(sender, pointer){
emitter.emitX = pointer.x;
emitter.emitY = pointer.y;
emitter.emitParticle();
}, this);
http://phaser.io/sandbox/cxBVeHrx
EDIT
My actual code is based on the Phaser-ES6-Boilerplate. Even though BdRs answer solves the issue in the sandbox code, I'm not able to utilize this in my real code.
I have uploaded both the code and a running example. Hopefully someone can tell me where I have screwed things up...
Separate Phaser items don't have a z-order, instead it just depends on the order you create and add them to game. Each new sprite or emitter or group etc. will be displayed on top of all previously added items.
So, simply changing your code to something like this should work.
// first the sprite
var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser');
sprite.scale.setTo(2, 2);
// then the particles in front of sprite
var emitter = game.add.emitter(game.world.centerX, game.world.centeryY);
emitter.makeParticles('phaser');
// then maybe text in front of particles and sprite
var mytest = game.add.bitmapText(10, 20, 'myfont', 'Level 1', 16);
// etc.
Btw sprites do have a .z value but that only used when it's part of a Phaser.Group, it will then be used as the display z-order but only within that group of sprites.
By default, phaser will not sort objects that get added to any group, it will just render them in the order that they get added. In your case, you can just add the emitter to the group after you add the sprite (the group in this case is the 'game' object).
Of course, having to add objects in the drawing order is not ideal, and if you need to have them sorted dynamically, not possible.
Another way is you can sort objects within a group using the 'sort' function, in which you give it the name of a parameter to sort by, and you sort whenever you need to (in some cases, in the Update callback).
Sorting every frame can be a performance hit though, especially if you have a lot of objects. Another way you could go about this is by adding groups, sorting those groups in draw order (think of them like layers), and then adding objects to those groups in any order. Any group that needs sorting within itself you can sort as well. This way, you can choose to have (for example) a background layer not needing to be sorted but everything added to that layer will be behind every other layer.
Good answers from everybody, but you are missing that every GameObject has a depth property which serves exactly the z-index purpose. This way you do not need to rely on the order of objects creation.
There is also an official
example.
Hope this helps.

iPhone SDK building an Omnigraffle like app

I have been trying to find an example or some hints on how to create an app that I could drag, resize, rotate images onto a UIView and then save the individual pieces (including their size, rotation and placement) and the entire UIView into CoreData. Kind of like the omnigraffle app.
Any tutorials, examples or anything on any piece of the app would be greatly appreciated.
for dragging a view
http://www.cocoacontrols.com/platforms/ios/controls/tkdragview
for roting a view http://www.cocoacontrols.com/platforms/ios/controls/ktonefingerrotationgesturerecognizer
for resizing a view
http://www.cocoacontrols.com/platforms/ios/controls/spuserresizableview
What respects to core data, its actually pretty straightforward just, gather the classes in one view, see the properties you need to save, and the new one you will need for your app and thats it.
Like:
Object Canvas containing a many relationship to morphlingViews wich contain all the properties as center, color, width, height, angle, UIPath (if you plan to create custom shapes) layer position (so it gets drawn correctly) and if you plan to connect the views as omnigraffle add a many realtionship to self (in morphlingViews) so you can take the center of different morphlingViews and add a simple line between them. (and a string if you plan to add drawInRect method to allow users to write in the objects, then it will be a good idea to add the text properties as well).
You can also add Quartz Composer drawing styles properties to the object, as shadow, shadowColor, shadowOffset, or add patterColor to add resizable background.

iOS iBooks like store animation

Anyone know how Apple does the transition to the store in the iBooks app? I know they are using a Modal View Controller with the UIModalTransitionStyleFlipHorizontal transition style set but I don't see how they are showing the "depth" of the "bookcase" when they do the transition.
I'm supposing that the animation works something like this:
A 'snapshot' image is taken of the
bookshelf and set to the contents of
a CALayer.
The bookshelf view is
removed from its superview.
The newly created CALayer (the bookshelf
layer) with the image of the
bookshelf is added to the layer of
some existing (or newly created)
UIView
Another layer (the side
layer) is created and an image of
the side of the bookshelf is used as
its contents. This layer is added
to the UIView The side layer is
positioned at the right edge of the
bookshelf layer.
The side layer's
transform is set to rotate it M_PI_2
rads about the y-axis. This
essentially makes it invisible as it
is perpendicular to the device
screen
The bookshelf and side layers
have an animation added to them that
transforms each with an M_PI_2
rotation about the y axis. At the
conclusion of this animation, the
bookshelf will be perpendicular to
the device screen and the side layer
will be fully in view.
A new layer (the store layer) is created and a snapshot image of the store is added as the contents of the new layer, it is transformed and positioned so that it will appear correctly when . . .
The side layer and store layer have an animation added that transforms each with an M_PI_2 rotation about the y axis.
All of the layers are removed and the store UIView is displayed.
I don't have any inside knowledge of the iBooks app, but if I were trying to duplicate this effect, this is how I'd go about it. FWIW, once you get the hang of positioning and transforming the CALayers, its kinda fun to mess around with animations like this.

Resources