Image as material in polygon entity

1,332 views
Skip to first unread message

Jerrold Siegel

unread,
Jul 14, 2015, 2:53:59 PM7/14/15
to cesiu...@googlegroups.com
I am trying to fill a polygon with an image. The following code runs without error but fills the polygon with white rather than the image.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    var thebox=viewer.entities.add({
                                   name : 'Area Boundary',
                                   polygon :{
                                   hierarchy : Cesium.Cartesian3.fromDegreesArray([-90.19603946178125,38.65097916825561,-90.19506083993582,38.65128341836232,-90.19537416776143,38.65190098014632,-90.19635468452998,38.65159820073161,-90.19603946178125,38.65097916825561]),
                                   outline : true,
                                   outlineColor : Cesium.Color.BLACK,
                                   height : 0}
                                   }
                                  );
   thebox.material = new Cesium.Material({
      fabric : {
                 type : 'Image',
                 uniforms :{ image : '../../SampleData/models1125/eastwestalley.jpg'}
               }

      });
----------------------------------------------------------------------------------------

Any help would be appreciated.

Matthew Amato

unread,
Jul 14, 2015, 3:01:31 PM7/14/15
to cesiu...@googlegroups.com
You can just assign an entity material via a url directly: thebox.material = '../../SampleData/models1125/eastwestalley.jpg';

Or better yet, just add "material: thebox.material ='../../SampleData/models1125/eastwestalley.jpg'" as a constructor option like you have for the other parameters.

I would recommend you check out the Visualizing Spatial Data tutorial which covers this and a lot of other standard features of the Entity API.

--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jerrold Siegel

unread,
Jul 14, 2015, 3:52:27 PM7/14/15
to cesiu...@googlegroups.com

That was easy
That was easy. Much Thanks.

I will definitely go though the tutorial as you suggest.  

Jerrold Siegel

unread,
Jul 15, 2015, 10:26:32 AM7/15/15
to cesiu...@googlegroups.com

Hi,

Another minor issue, It seems that the image is being drawn horizontally. Is there some way to draw it with bottom along the first side of the polygon?
Thanks,
  

Matthew Amato

unread,
Jul 15, 2015, 10:57:48 AM7/15/15
to cesiu...@googlegroups.com
You can rotate the polygon using the stRotation property on PolygonGraphics.  This rotation is counter-clockwise from north.  If you want it to align with a specific edge, you should just be able to compute the angle of rotation based on the two points making up the edge you want to align with.  I through together this quick and dirty example but the math is not completely correct (I'm still not completely awake :).  Also keep in mind that at some point the curvature of the earth will probably come into play.

var viewer = new Cesium.Viewer('cesiumContainer');

var entity = viewer.entities.add({
    name : 'Blue polygon with holes and outline',
    polygon : {
        hierarchy : {
            positions : Cesium.Cartesian3.fromDegreesArray([-99.0, 39.0,
                                                            -98.95, 38.95,
                                                            -98.95, 39.0,
                                                            -99.0, 39.0])
        },
        material : '../images/checkerboard.png'
    }
});

var cartographicStart = Cesium.Cartographic.fromDegrees(-99.0, 39.0);
var cartographicEnd = Cesium.Cartographic.fromDegrees(-98.95, 38.95);
var deltaY = cartographicEnd.latitude - cartographicStart.latitude;
var deltaX = cartographicEnd.longitude - cartographicStart.longitude;
entity.polygon.stRotation = -Math.atan2(deltaY, deltaX);

viewer.zoomTo(viewer.entities);

Hope that helps.


--

Jerrold Siegel

unread,
Jul 15, 2015, 1:24:11 PM7/15/15
to cesiu...@googlegroups.com
Thanks again,

I think the problem is sort of the reverse. We are porting some Google Earth stuff and are getting down to the last elements. The polygons in question are city blocks and in this case the specific image is the underlying street with an ally running down the middle. I attached an image of a GE view. We need the alley to run down the middle of the block. The geography of the block is fixed. I can rotate the street image on a block by block basis, but being able to align the street image with a side would make life much easier.


analley.jpg

swapn...@gmail.com

unread,
Feb 23, 2017, 7:32:44 AM2/23/17
to cesium-dev
I have the same issue, when I try to add image to polygon I see white, but not image.

Below is simple code which I'm trying. Did I miss any syntax or do I've to set Repeat property somewhere?


var greenPolygon = viewer.entities.add({
name : 'Green extruded polygon',
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([-108.0, 42.0,
-100.0, 42.0,
-104.0, 40.0]),
extrudedHeight: 500000.0,
/*material : Cesium.Color.GREEN,*/
material : "https://cesiumjs.org/Cesium/Build/Documentation/images/CesiumLogo.png",
closeTop : false,
closeBottom : false
}
});

Hannah Pinkos

unread,
Feb 23, 2017, 9:30:41 AM2/23/17
to cesium-dev, swapn...@gmail.com
Hello,

The image material is working properly for me with the code example you provided.  For polygons, we extrude the texture down the wall of the polygon, so it may look differently than you expect.
If you're going to have both closeTop and closeBottom = false, you may want to consider using a wall instead: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Wall.html&label=Geometries
The image will wrap around the sides of a wall.

Best,

Hannah 

swapn...@gmail.com

unread,
Feb 23, 2017, 9:54:52 AM2/23/17
to cesium-dev, swapn...@gmail.com
Thanks,
I see screenshot as : https://snag.gy/KJ6yqp.jpg


Is there anything by which we resize image on that polygon? I want to see that image on side of the polygon. I want to use polygon only. Any suggestions?

Hannah Pinkos

unread,
Feb 23, 2017, 10:30:32 AM2/23/17
to cesium-dev, swapn...@gmail.com
In order to achieve this for a polygon you will have to change the way the texture coordinates are computed.  Using a Wall instead is the best solution here.

-Hannah

swapn...@gmail.com

unread,
Feb 24, 2017, 3:12:24 PM2/24/17
to cesium-dev, swapn...@gmail.com
Wall works well for Image material. Can we use youtube URL as material?

Hannah Pinkos

unread,
Feb 27, 2017, 9:32:12 AM2/27/17
to cesium-dev, swapn...@gmail.com
We do have support for video materials.  See this example: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Video.html&label=Showcases

-Hannah
Reply all
Reply to author
Forward
0 new messages