Is it possible to add custom materials to each side of a polygon if it is created by calling viewer.dataSources.add(data) ?
I was originally using the extrudedHeight property to set different heights of my objects, but I learned that this limits the ability to set a material on any side except for the top of the polygon.
If I select the entity afterwards using the entities.getById function, I am able to reset the extrudedHeight property to 0, and THEN set the height property of the polygon which allows it to keep the same height without relying on the extrudedHeight property. As far as I can tell, however, the entity still behaves the same way when I try to set the material again.
Is there no difference between the height and extrudedHeight properties? In any case, is there a way that I can have my custom material on the outter edges of the polygon, rather than the top, without having to build a custom polygon for each of my objects (which, in this case, are buildings)?
My code:
var viewer = new Cesium.Viewer('cesiumContainer', {
imageryProvider : new Cesium.createOpenStreetMapImageryProvider({
url : 'http://tile.stamen.com/watercolor/'
}),
baseLayerPicker : false
});
var dataSource = Cesium.GeoJsonDataSource.load('../data/mDataSource.json').then(function(data) {
viewer.dataSources.add(data);
viewer.zoomTo(data);
var entities = data.entities.values;
var colorHash = {};
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
var name = entity.name;
var color = colorHash[name];
if (!color) {
color = Cesium.Color.fromRandom({
alpha : 1.0
});
colorHash[name] = color;
}
entity.polygon.material = '../data/img/myMaterial.png';
entity.polygon.extrudedHeight = 10;
}
var mEntity = viewer.dataSources.get(0).entities.getById("mId");
mEntity.polygon.extrudedHeight = 0;
mEntity.polygon.height = 10;
mEntity.polygon.material = '../data/img/myMaterial.png';
});
EDIT: I've also heard that in order to achieve what I'm looking for, I would need to design my own custom polygon. If this is the case, is it possible to use custom polygons with data sets brought in through the Cesium.GeoJsonDataSource method?
Related
Is there a way to get the bounding rectangle (screen position) of Google Map API markers? I am using an Angular 2 wrapper, so I don't construct the markers like you would normally with the API (mostly irrelevant here though).
Or are they on an internal canvas with no way to pull position like you would with an html element?
I have tried something like this, but getBoundingRectangle() comes back with zero values:
var googleMapContent = document.getElementsByClassName("sebm-google-map-content")[0];
var markerList = googleMapContent.getElementsByTagName("sebm-google-map-marker");
if( markerList.length > 0 ) {
for (var i = 0; i < markerList.length; i++ ){
var marker = markerList[i];
var markerLabel = marker.getAttribute("ng-reflect-label");
var boundingRectangle = marker.getBoundingClientRect();
}
}
P.S. I have access to map center lat/lng + zoom and marker lat/lng, so I can "math" this, but that's pretty dirty.
The Marker class hasn't got either a getBoundingRectangle or
getBoundingClientRect method.
It has got getPosition() and getShape() though, which in combination might give you the information you need.
This will be a simple clock. I've been using AS2 since I learned Flash in early 2000s. It's time to move on.
for (a=1; a<60; a++) {
duplicateMovieClip("dot0", "dot"+a, 10+a);
_root["dot"+a]._rotation = a*6;
_root["dot"+a].gotoAndStop(1);
}
Adobe published ActionScript 2.0 Migration that helped me tremendously back in the day.
Some specifics related to your code:
Properties aren't prefixed with underscores, ex _rotation is now rotation, and _root is now root.
root is not global, it is a property of display objects, and it is null if the display object is not in the display list.
duplicateMovieClip does not exist anymore. You should export your symbol to a class and use new operator and addChild() to create an instance and add it to the display, ex:
var dot:Dot = new Dot();
addChild(dot);
Display objects created in code are not automatically given a name and assigned to a property on its parent when added to the display. You can set the name and use getChildByName on its parent. Example:
var dot:Dot = new Dot();
dot.name = "dot" + i;
addChild(dot);
var n:int = 10;
var dot10:Dot = getChildByName("dot" + n) as Dot;
But this is a bit cumbersome, so in most cases it makes more sense to just store your display objects in your own array and reference them by index:
var dots:Array = [];
var dot:Dot = new Dot();
addChild(dot);
dots.push(dot);
var firstDot:Dot = dots[0];
That should get you started.
Thanks to help here and elsewhere, this is what works for me:
var i:Number = 1;
var dots:Array = [];
for (i=0; i<60; i++) {
var dot:Dot = new Dot;
addChild(dot);
dots.push(dot);
dot.x=683;
dot.y=436;
dot.rotation = i*6;
dot.gotoAndStop(1);
}
The clock I'm making don't have hands but the dots change color for the hours minutes and seconds. Thanks everybody who helped
I am applying filters to a bitmap using something like:
TweenLite.to(origBitmap,0,{colorMatrixFilter:{saturation:2,brightness:3});
and that works fine.
I need to somehow apply a sharpen filter to origBitmap which I have successfully achieved using a ConvolutionFilter. The problem is after I've ran the above tweenlite call, then create a convolution filter and apply it to origBitmap, it removes the initial saturation and brightness filters and just keeps the sharpen filter
private function applyEffects(effects:Array):void
{
currentEffects = effects;
var props:Object = {};
for (var i:String in effects)
{
props[effects[i].effect] = effects[i].amount;
}
TweenLite.to(bitmap,0,{colorMatrixFilter:props});
//-- props could look like {saturation:2,brightness:3}
//-- This will sharpen the container sprite
var matrix:Array = [0, -1, 0,
-1, 5, -1,
0, -1, 0];
var conv:ConvolutionFilter = new ConvolutionFilter();
conv.matrixX = 3;
conv.matrixY = 3;
conv.matrix = matrix;
conv.divisor = 1;
bitmap.filters = [conv]; //-- this removes the above filters and just sharpens the image
}
Is there a way to also incorporate the ConvolutionFilter in that TweenLite call above? I've searched quite a bit and found some guy made a class called TweenMan which was based around your class where ConvolutionFilter is incorporated: https://github.com/danro/tweenman-as3
Nothing to do with TweenMax here since your code is the one making the mistake. This correctly removes all current filter and apply only one:
bitmap.filters = [conv];
Since filters property is either null or is an Array. To add a filter to the list you use array operation and reapply the array:
var filters:Array = bitmap.filters;
if(!filters)
{
filters = [];
}
filters.push(conv);
bitmap.filters = filters;
EDIT: starting over since I think I understand what you are trying to do. You are avoiding creating the filter yourself and let TwennLite do it for you even tough you don't need to tween anything. Don't do that, you are making everything harder for yourself. Instead create your filter that way:
var props:Object = {};
var colorMatrix:ColorMatrixFilter = new ColorMatrixFilter();
for (var i:String in effects)
{
colorMatrix[effects[i].effect] = effects[i].amount;
}
bitmap.filters = [colorMatrix];
//etc .... then
var filters:Array = bitmap.filters;
filters.push(conv);
bitmap.filters = filters;
If you need to animate multiple filters remember that most tween engine can tween easily array values so you can just do that and then apply those array values to your filters.
I have an RTMP stream that I need to take a screenshot of. I got a security error using bitmapData.draw() since it was coming from AWS S3 so I found a workaround that allows me to take a screenshot of the video:
var bitmap = new Bitmap();
var graphicsData : Vector.<IGraphicsData>;
graphicsData = container.graphics.readGraphicsData(); //-- container is a sprite that holds my video element
bitmap.bitmapData = GraphicsBitmapFill(graphicsData[0]).bitmapData;
var image:ByteArray = new JPGEncoder(85).encode(bitmap.bitmapData);
At this point, I send the ByteArray to PHP, create a JPG out of the ByteArray and save it to the server. That all works great.
The issue is I apply filters realtime to the container sprite which alters the look of the video like brightness, contrast, saturation etc, but when saving to the server, the saved image doesn't contain the filters I had applied.
I tried reapplying the filters to bitmap, graphicsData and bitmap.bitmapData, but nothing worked.
How can I either retain the filters applied or reapply the filters to the above code?
EDIT
Here is how I initially apply the filters:
private function applyEffects(effects:Array):void
{
currentEffects = effects;
var props:Object = {};
for (var i:String in effects)
{
props[effects[i].effect] = effects[i].amount;
}
TweenLite.to(container,0,{colorMatrixFilter:props});
}
props object could look something like: {contrast:0.5,saturation:1}
Ok, I have solved this on my own with a little suggestion Jack Doyle (GSAP Author) gave me. I have described what I did differently in the comments of my code:
var graphicsData:Vector.<IGraphicsData>;
graphicsData = container.graphics.readGraphicsData();
var origBitmap:Bitmap = new Bitmap();
origBitmap.bitmapData = GraphicsBitmapFill(graphicsData[0]).bitmapData;
//-- at this point I have a screenshot of the video
var props:Object = {};
for (var i:String in currentEffects)
{
props[currentEffects[i].effect] = currentEffects[i].amount;
}
TweenLite.to(origBitmap,0,{colorMatrixFilter:props});
//-- at this point I've reapplied the effects.
//-- originally, sending bitmap.bitmapData to the encoder didn't retain the filters so I went 1 step further
//-- create a new bitmapData and draw the reapplied filter'd bitmap
var filteredBitmapData:BitmapData = new BitmapData(640,360);
var filteredBitmap:Bitmap = new Bitmap(filteredBitmapData);
filteredBitmapData.draw(origBitmap);
//-- encode the new bitmap data
var image:ByteArray = new JPGEncoder(85).encode(filteredBitmapData); //-- filteredBitmapData is now filtered and I can send this to the server
Is that possible to check the type of a google map overlay.
var polygon = new G.Polygon();
var rectangle = new G.Rectangle();
var circle = new G.Circle();
var shape;
Now, my code will dynamically assign these overlay to shape variable.
But how can I detect or check the type of an overlay named shape? I can't find the solution using Google.
You can use instanceof, but I'd advise against it. It's not part of the API and could break any time in the future.
It would be better to assign an attribute upon initialization.
var polygon = new G.Polygon();
polygon.type = 'polygon';
var rectangle = new G.Rectangle();
polygon.type = 'rectangle';
var circle = new G.Circle();
polygon.type = 'circle';
console.log(shape.type);
You can check the class via the Javascript instanceof operator:
var polygon = new G.Polygon();
var rectangle = new G.Rectangle();
var circle = new G.Circle();
var shape = selectShape(polygon, rectangle, circle); // your dynamic selection funktion
if (shape instanceof G.Polygon) {
alert("found Polygon");
}
I wrote a function that returns the type of shape it was given. It supports circle and polygon but I'm sure someone can figure out how to add rectangle. It simply checks for unique properties of each.
function typeOfShape(shape){
if(typeof shape.getPath === "function"){
return "polygon";
}else if(typeof shape.getRadius === "function"){
return "circle";
}else{
return "unknown";
}
}