After Effects: centering Layer by Expression - position

Iam trying zo position a Layer by expression. I need exacly the center of the Layer.
w=thisComp.width; //x
h=thisComp.height;//y
w2=w/2;
h2=h/2;
??

Ok i think i got it!
var w=thisComp.width;
var h=thisComp.height;
var w2=w/2;
var h2=h/2;
[w2,h2]

Related

Unexpected behaviour of geometry in Earth Engine

I am analysing solar farms and have defined two areas of geometry. In the example below, for a site called 'Stateline', I have drawn the boundary of the site and saved the geometry as a variable 'Stateline_boundary'. I have drawn around the solar panels within the boundary, which exist in two distinct groups and saved the geometry as a variable 'Stateline_panels'.
Stateline_panels has two co-ordinate lists (as there are two areas of panels).
When I try to subtract the area covered by the panels from the area within the boundary only the first of the two lists in the 'Stateline_panels' geometry is used (see code below and attached image).
var mask = Stateline_boundary
var mask_no_panels = mask.difference(Stateline_panels);
Map.addLayer(mask_no_panels,{},'Stateline_mask_no_panels',false);
I don't understand the behaviour of the geometry. Specifically why when adding the 'Stateline_panels' geometry to the map it displays in its entirety, but when used as a mask breaks the geometry and only uses the first of two lists of coordinates.
I was going to write a longer question asking why the geometry variables seem to behave differently when they are imported into the script rather than listed within the script (which I don't think should make a difference, but it does). However I think this is an earlier manifestation of whatever is going on.
The methodology that I found worked in the end was to create geometry assets individually with the polygon tool in the Earth Engine IDE - ensuring that each is on a different layer (using the line tool, then converting to polygons never worked).
Not only was this more flexible, it was also easier to manage on Earth Engine as editing geometries is not easy. I read about the importance of winding clockwise - though never determined if that was part of the issue here. If I always drew polygons clockwise the issue never occured.
I ended up with my aoi covered in polygons like this (each colour a different named layer/geometry object):
Once this was done, manipulating each geometry object in the code editor was relatively straightforward. They can be converted to FeatureCollections and merged (or subtracted) using simple code - see below for my final code.
It was also then easy to share them between scripts by importing the generated code.
I hope that helps someone - first attempt at answering a question (even if its my own). :)
// Convert panel geometries to Feature Collections and merge to create one object.
var spw = ee.FeatureCollection(stateline_panels_west);
var spe = ee.FeatureCollection(stateline_panels_east);
var stateline_panels = spw.merge(spe);
// Convert 'features to mask' geometries to Feature Collections.
var gc = ee.FeatureCollection(golf_course);
var sp = ee.FeatureCollection(salt_pan);
var sc = ee.FeatureCollection(solar_concentrator);
var h1 = ee.FeatureCollection(hill_1);
var h2 = ee.FeatureCollection(hill_2);
var h3 = ee.FeatureCollection(hill_3);
var mf = ee.FeatureCollection(misc_features);
// Merge geometries to create mask
var features_to_mask = gc.merge(sp).merge(sc).merge(h1).merge(h2).merge(h3).merge(mf);
// Convert 'Features_to_mask' to geometry (needed to create mask)
var features_to_mask = features_to_mask.geometry();
// Change name
var mask = features_to_mask
///// If site has other solar panels nearby need to add these separately & buffer by 1km
var extra_mask = ee.Feature(solar_concentrator);
var extra_mask = extra_mask.buffer(1000);
var extra_mask = extra_mask.geometry();
///// Join mask & extra mask into single feature using .union()
// Geometry objects
var mask = mask.union(extra_mask);

Getting arbitrary paths to animate by moving the shortest distance in Snap.svg

I have a canvas.
In this canvas I have a closed path, and I am trying to morph this path into a different path.
Paths can have any number of points(>=3).
I have two paths:
var path1 = "M50,50L200,50,200,200,50,200z"
var path2 = "M300,200L50,200,50,50,200,50z"
This is what I'm using to animate the morphing:
var path = paper.path(path1).attr({'stroke':'black','fill':'white'})
var currentPath = 1
path.click(function () {
if(currentPath==1) {
path.stop().animate({d: path2},2000, function () {
currentPath=2
})
}
else {
path.stop().animate({d: path1},2000,function () {
currentPath=1
})
}
})
This is the situation I want to achieve:
http://jsfiddle.net/MichaelSel/vgw3qxpg/7/
This is the situation I want to avoid.
http://jsfiddle.net/MichaelSel/vgw3qxpg/6/
Is there any way to tell snap to do the animation by using the shortest distance to each point?
Note: I cannot just 'rewrite' the paths in reverse order (which would fix them) because it's the client who positions the points arbitrarily.
What can I do?
I would love to add more details if my question is unclear.
Thank you all.
No, there is no way to do this (other than coding your own complex morphing with checks).
It uses basic interpolation between the points, so its important to get the devs to move the points in their svg creation rather than just creating a new svg from scratch that could have points start from any position.
There is no reason though to my knowledge why you couldn't still rotate the path points with a bit of clever code though, even if the client has positioned them arbitrarily, but I don't think thats simple.

Check which Kinetic.Layer is on top

I have one stage and multiple layers which are superposed. I refer to each layer with a button. I must allow the user to draw on those multiple layers whenever he clicks on one button, and swap between them. How can I check which layer is on top of the others?
I tried layer.getAbsoluteZIndex() but it's not obvious. Is there a method that actually return true/false for example, maybe like .isOnTop()?
EDIT :
Well, I had to implement it by my own and it was okay I guess. The easiest solution was to add a boolean attribute isOnTop in the definition of each layer and make the appropriate tests and treatments.
First add a new method on the Kinetic.Stage:
Kinetic.Stage.prototype.getTopLayer=function(){
var layers=stage.find('Layer');
var topLayerIndex=-100;
var topLayer;
for(var i=0;i<layers.length;i++){
var index=layers[i].getAbsoluteZIndex();
if(index>topLayerIndex){
topLayerIndex=index;
topLayer=layers[i];
}
}
return(topLayer);
}
Then you can get the layer with the highest z-index like this:
var myTopLayer = stage.getTopLayer();

How to get reference to SVG (child) elements nested in another SVG element (parent) using D3?

I have several groups (SVG G elements) nested in another group and I would like to get their ID's. I used the D3 javascript library to create the SVG and the code looks similar to this.
var body = d3.select("body");
var svg = body.append("svg")
.attr("width", '100%')
.attr("height", '100%')
var outerG = svg.append("g")
.attr('id','outerG')
var innerG1 = outerG.append('g')
.attr('id','innerG1')
var innerG2 = outerG.append('g')
.attr('id','innerG2')
I tried to use childNodes attribute, but console.log(outerG[0].childNodes) gives me undefined. Could not find the right answer searching with google, could please someone give me a hint how to do that ?
This will work:
console.log(outerG[0][0].childNodes);
See jsFiddle here
The reason you need two nested indices is that all selections are grouped implicitly. If you'd like to know the deeper reasons for this, or want to understand selections better in general, see this article

Monotouch - Draw a MKPolyline on Map

I've a MKPolyline made of CLLocationCoordinate2D array (Points). That's all fine.
I added this line to the Map as an overlay, like so: Map.AddOverlay(line);
I event set this: Map.SetVisibleMapRect(line.BoundingMapRect, true);
But the line does not show up although the Map bounds are correct.
I'm looking into MKPolylineView, but can't get it to work.
Anyone knows to set colour and line width?
Thanks
After much head scratching, here is how to display a MKPolyline on a MKMapView:
Step 1: Create a delegate method for Map GetViewForOverlay
Map.GetViewForOverlay = Map_GetViewForOverlay;
Where Map is the MKMapView.
MKOverlayView Map_GetViewForOverlay(MKMapView mapView, NSObject overlay)
{
if(overlay.GetType() == typeof(MKPolyline))
{
MKPolylineView p = new MKPolylineView((MKPolyline)overlay);
p.LineWidth = 2.0f;
p.StrokeColor = UIColor.Green;
return p;
}
else
return null;
}
Step 2: Create a new instance of MKPolyline
MKPolyline line = MKPolyline.FromCoordinates(polyPoints);
Where polyPoints is an Array of CLLocationCoordinate2D.
Step 3: Add the overlay to the map
Map.AddOverlay(line);
Step 4: Use code below to zoom and change Map bounds to fit route
Map.SetVisibleMapRect(line.BoundingMapRect, true);
I'm pretty sure if your intent is to dynamically draw a map over the MapView given a backing model object that indicates two coordinates you want to take a look at my project here:
https://github.com/anujb/MapWithRoutes
This will allow you to overlay a path and it will update as the map changes. It's a modified version of an obj-C port that makes use of background threads so it's not blocking.
Thanks,
Anuj

Resources