# Tiles as a layer

**URL:** <https://community.cesium.com/t/tiles-as-a-layer/7457>\
**Category:** CesiumJS\
**Created:** [September 18, 2018, 4:18pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457 "2018-09-18T16:18:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![maryam](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@maryam](https://community.cesium.com/u/maryam)\
**Post date:** [September 18, 2018, 4:18pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/1 "2018-09-18T16:18:51Z")

</div>

**1. A concise explanation of the problem you’re experiencing.**

Hi,

I create a tile. For instance:

var instance = new Cesium.GeometryInstance({  
geometry : new Cesium.RectangleGeometry({  
rectangle : Cesium.Rectangle.fromDegrees(-100.0, 20.0, -90.0, 30.0),  
vertexFormat : Cesium.EllipsoidSurfaceAppearance.VERTEX\_FORMAT  
})  
});

var ovcPrimitive =new Cesium.Primitive({  
geometryInstances : instance,  
appearance : new Cesium.EllipsoidSurfaceAppearance({  
})  
});

var layers = viewer.scene.imageryLayers;  
var blackMarble = layers.addImageryProvider(???);//???

I want to change the alpha of my instance for fade in and fade out.

My question is how my instance can be considered as a layer? I mean how I can pass my instance to layers.addImageryProvider.

Thanks

**2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.**

**3. Context. Why do you need to do this? We might know a better way to accomplish your goal.**

**4. The Cesium version you’re using, your operating system and browser.**

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [September 19, 2018, 1:21pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/2 "2018-09-19T13:21:03Z")

</div>

Hey Maryam,

If you’re just trying to set the alpha, you can do that in the material([https://cesiumjs.org/Cesium/Build/Documentation/Material.html](https://cesiumjs.org/Cesium/Build/Documentation/Material.html)) for the EllipsoidSurfaceAppearance.

You can also use an image as an Imagery Layer with the SingleTileImageryProvider ([https://cesiumjs.org/Cesium/Build/Documentation/SingleTileImageryProvider.html](https://cesiumjs.org/Cesium/Build/Documentation/SingleTileImageryProvider.html)).

If all you want is to fade in/out a polygon, an easier way to do that would be just using an entity:

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var color = new Cesium.Color(1.0, 0.0, 0.0, 1.0);

var counter = 0;

var redPolygon = viewer.entities.add({

name : ‘Red polygon on surface’,

id: ‘1’,

polygon : {

hierarchy : Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0,

-115.0, 32.0,

-107.0, 33.0,

-102.0, 31.0,

-102.0, 35.0]),

material : new Cesium.ColorMaterialProperty(

new Cesium.CallbackProperty(function(time, result) {

color.alpha = (Math.cos(counter) + 1) \* 0.5;

counter += 0.1;

return color;

}, false))

}

});

viewer.zoomTo(viewer.entities);

``

[Here’s a running example.](https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/#c=rVNdb5swFP0rFi8xKzOhUVWpodGm7HHTqnXay9iDay7BqrGRbajolP++CyQZpd2kqbtCFvf6nOOvc1tuSSvhASy5JhoeyBacbCr2bajRhRjSrdGeSw12Ea4znekWWcIoMyNt+xJN2DIiy9OA6ZTUaD+stTzVLOQ3RnU7o7E87oWB9tJLcIznOf2ZaYKheQXkiiy+QE7qAwE/19iCC1hEI0rmCEmO2RF3RQ4ifZQSLLei7LB83Dm3Hv+4XrHCmuoD7CyAe28t7+j3t0ly0Z9kdYnjb5l/jZPM+StllpeDzOq1MueDTPJ/ZPBoP8KJUMXxnSVXeMdzh3w6TN1YU4P1HX15+SmNK3XHxf2JUTRaeGk09bKCCC3kGuXD6SPPY7Ar46ouOdqM4h5KJoyjB0eG5IwkIXmDnr1Y/01l9O8ZGpglfwRa8I3V45ovgPYRKbhyEIbj3D7T+0OPjPZ/NKb6auisGcJ1EAWp852CzUh8J6vaWE8aqyhjsYeqVni5Lr5rxD14JpzrddP4SEpz2WKLXGfBrLGzgAjFncOZolHqVj5CFmzSGPFPaMrwXOrd5xas4l0PKZPNx7HIGEtjTJ+zvDH4fnai+As)

---

<div class="post-metadata">

**Author:** ![maryam](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@maryam](https://community.cesium.com/u/maryam)\
**Post date:** [September 19, 2018, 8:45pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/3 "2018-09-19T20:45:29Z")

</div>

Thanks Omar. Sorry I am new in this area and still I have a problem.  
I build a set of tiles (cube) then I want to fade in and fade out tiles.  
What I do is  
var ovcPrimitive = new Cesium.Primitive({  
geometryInstances: ovcInstances,  
asynchronous: false,  
vertexCacheOptimize: true,  
allowPicking: false,  
appearance: new Cesium.PerInstanceColorAppearance({  
closed: true,  
translucent: false,  
}),  
material : new Cesium.ColorMaterialProperty(  
new Cesium.CallbackProperty(function(time, result) {  
color.alpha =(Math.cos(counter) + 1) \* 0.5;  
counter += 0.1;  
return color;  
}, false))  
});

that.primitive.add(ovcPrimitive);  
Cesium.when(that.primitive.readyPromise).then(undisplayFunc);  
viewer.scene.primitives.add(that.primitive);

But nothing happen. Thank you so much

---

<div class="post-metadata">

**Author:** ![maryam](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@maryam](https://community.cesium.com/u/maryam)\
**Post date:** [September 19, 2018, 11:02pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/4 "2018-09-19T23:02:04Z")

</div>

Actually, I think I know what the problem is. What I am doing is building a set of tiles. Each tile can have some subsets. I wanna fade in and fade out tiles (or instances in the fades). If I want to apply

material : new Cesium.ColorMaterialProperty(  
new Cesium.CallbackProperty(function(time, result) {  
color.alpha =(Math.cos(counter) + 1) \* 0.5;  
counter += 0.1;  
return color;  
}, false))  
});

I need to apply the above code for each tile. It means there should be something like Cesium.ColorMaterialProperty but it does not have any material attribute. I would appreciate if you can help me.

Regards,

Maryam

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [September 19, 2018, 11:19pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/5 "2018-09-19T23:19:57Z")

</div>

I’m not sure exactly what you mean. The [Appearance](https://cesiumjs.org/Cesium/Build/Documentation/Appearance.html) does have a material property that you can supply.

Can you share a [Sandcastle example](https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/) of how your code works so far?

---

<div class="post-metadata">

**Author:** ![maryam](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@maryam](https://community.cesium.com/u/maryam)\
**Post date:** [September 23, 2018, 5:42pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/6 "2018-09-23T17:42:47Z")

</div>

Thanks Omar .  
In the PerInstanceColorAppearance, there is no option to change color (or alpha per instance). The all provided options are flat, faceForward,  
translucent, closed, vertexShaderSource, fragmentShaderSource, renderState.  
[https://cesiumjs.org/Cesium/Build/Documentation/PerInstanceColorAppearance.html#renderState](https://cesiumjs.org/Cesium/Build/Documentation/PerInstanceColorAppearance.html#renderState)

Could you please give me a simple code how you change alpha in perinstanceColotApperance.

In  
my case, I have an array of GeometryInstance (geometry, color, …) that makes a tile. I wanna change the alpha of each instance (that can different colors) frequently (fade in and fade out).

Thanks

Maryam

---

<div class="post-metadata">

**Author:** ![maryam](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@maryam](https://community.cesium.com/u/maryam)\
**Post date:** [September 24, 2018, 12:25pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/7 "2018-09-24T12:25:38Z")

</div>

In the following example, two GeometryInstancs are built and shown on the screen:

var viewer = new Cesium.Viewer(‘cesiumContainer’);  
var scene = viewer.scene;  
var counter =0;

var instance = new Cesium.GeometryInstance({  
geometry : new Cesium.RectangleGeometry({  
rectangle : Cesium.Rectangle.fromDegrees(-100.0, 20.0, -90.0, 30.0),  
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX\_FORMAT  
}),  
attributes : {  
color : new Cesium.ColorGeometryInstanceAttribute(0.0, 0.0, 1.0, 1)  
},

});

var anotherInstance = new Cesium.GeometryInstance({  
geometry : new Cesium.RectangleGeometry({  
rectangle : Cesium.Rectangle.fromDegrees(-85.0, 20.0, -75.0, 30.0),  
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX\_FORMAT  
}),  
attributes : {  
color : new Cesium.ColorGeometryInstanceAttribute(1.0, 0.0, 0.0,1)  
}  
});

scene.primitives.add(new Cesium.Primitive({  
geometryInstances : [instance, anotherInstance],  
appearance : new Cesium.PerInstanceColorAppearance()

}));

My problem is if the following part for changing the alpha. I mean using Cesium.Appearance and material are correct?

var arrowMaterialAppearance = **new Cesium.Appearance({  
material : new Cesium.ColorMaterialProperty({  
color : new Cesium.CallbackProperty(**

\_\_function (time, result){  
return Cesium.Color.fromAlpha(  
Cesium.Color.RED,  
(Math.cos(100) + 1) \* 0.5,  
result);

```
                    }, false)
                      
         }),
 });__

```

Also, where should I put it? I am just confused because in GeometryInstance there is no option for appearance (or something else that the alpha can be changed) and in Cesium.Primitivewe use  
PerInstanceColorAppearanc :((((

I really appreciate you if you can help me. I spent lots of time and could not fix it (new to cesium)

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [September 24, 2018, 1:03pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/8 "2018-09-24T13:03:29Z")

</div>

The color is stored as a vertex attribute for each instance. So to change it, you have to change it on the instance, like in Hannah’s example linked to earlier. [So this is what an example would look like. The blue rectangle fades in and out.](https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/#c=tVRtT9swEP4rVr/UGa3bgKpt9EVDvEyTQCDG0CSKJpNei7XErmwnrEP8953tuKSdkJg08sGR7/w8d/fc2RXXpBLwAJqMiYQHcghGlAW79jbazvz2UEnLhQTdToZTWSHGZCABIQHL/BZdwSmksVxmsEn5GVQBVq++1F76OJUEPzHbb6ftjtss6iNkvwm8hAwBixwiQ0Tq6MDz22fZXKviCBYawNBu2u+zfofs+rX70f/2cE06gakCbeHXidIFt89kF6BjsocqV/pguQSu3ZZdH19eHX//cXJ+eXZw5TieAhW3Vou70oJBmjrNzGE3S/J024IcRCz1+fkl9UviI3Scvk+Jl5kEpblU9v45y9cI/mYafxg0JH4/eDOJ/5fI6VpktwSNyVNgq1UOIi+1KIQVlZPXDzpbWwzjsxltxLyIHvpIXvs1uxLTdJXdxHvU2e7zbRCCr8XaLPxlUWmo0o1Rsr6umSql9Q9AfxgvMNbA8yPI+QrNqbPXlStjvy1n3IKr/LgCaU+FsejSdF7KzAolaRJvdpOm2x3W1jndcExIP8Exs6WWw9jLkNDOGDuT1saQqWvy+LkjbAH2xQ4biu9Kwjxo2JiSm71b5KBn3N6j09A6XELe4SQMyI5b3WZ3MKhh/x4PA8S4OEutTmtk7CqHSeD7JIql0paUOqeM9SwUyxwlNb27MvsJlmXGuPaMehE0mokKH8rxtLX1IE9bJMu5MeiZl3n+VfyGaWsy6uH5DViu+EzIxTneQtTcHblPJ6fByBgb9XD7N8oqld9x3WD8Aw)

---

<div class="post-metadata">

**Author:** ![maryam](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@maryam](https://community.cesium.com/u/maryam)\
**Post date:** [September 24, 2018, 11:37pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/9 "2018-09-24T23:37:49Z")

</div>

Thank you so much. It was really helpful. I have a error. When I try to use getGeometryInstanceAttributes, it gives me the error that "  
**getGeometryInstanceAttributes is not a function**

"

This a part of the code:

var load = function(viewer, callback) {

var cubes;  
req.onload = function(evt) {  
…  
that.primitive = …  
this.primitive = viewer.scene.primitives.add(that.primitive);  
callback(viewer, this.primitive  
, this.number\_cube);  
}

function callBackFunc (viewer, myPrimitive, cubes) {  
…

var i = 0;

var color = myPrimitive.getGeometryInstanceAttributes(i).color; **// ERROR: myPrimitive.getGeometryInstanceAttributes is not a function**  
color[3] = (Math.cos(counter) \* 0.5 + 0.5) \* 255;  
myPrimitive.getGeometryInstanceAttributes(i).color = color;  
});

}

I call the "  
getGeometryInstanceAttributes" over the variable containing  
viewer.scene.primitives.add(that.primitive). But still gives me an error.

I really appreciate your help.

Maryam

---

<div class="post-metadata">

**Author:** ![maryam](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@maryam](https://community.cesium.com/u/maryam)\
**Post date:** [September 25, 2018, 12:25am UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/10 "2018-09-25T00:25:40Z")

</div>

Sorry, I want to correct something. Ignore the previous post of mine. This is my issue

Thank you so much. It was really helpful. I have a error. When I try to use getGeometryInstanceAttributes, it gives me the error that "  
**getGeometryInstanceAttributes is not a function**

"

This a part of the code:

var load = function(viewer, callback) {

var cubes;  
req.onload = function(evt) {  
…  
that.primitive = …  
viewer.scene.primitives.add(that.primitive);  
callback(viewer,

that.primitive  
, this.number\_cube);  
}

function callBackFunc (viewer, myPrimitive, cubes) {  
…

var i = 0;

var color = myPrimitive.getGeometryInstanceAttributes(i).color; **// ERROR: myPrimitive.getGeometryInstanceAttributes is not a function**  
color[3] = (Math.cos(counter) \* 0.5 + 0.5) \* 255;  
myPrimitive.getGeometryInstanceAttributes(i).color = color;  
});

}

I call the "  
getGeometryInstanceAttributes" over the variable containing  
viewer.scene.primitives.add(that.primitive). But still gives me an error.

I really appreciate your help.

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [September 25, 2018, 1:11pm UTC](https://community.cesium.com/t/tiles-as-a-layer/7457/11 "2018-09-25T13:11:18Z")

</div>

If anyone else is following this thread, see the answer here: [https://groups.google.com/d/msg/cesium-dev/93GZVBcmlsk/-o9Tj1zZCgAJ](https://groups.google.com/d/msg/cesium-dev/93GZVBcmlsk/-o9Tj1zZCgAJ)
