How to orient a specific point in a cesium pointprimitivecollection?
I am working on how to show / hide points in order to filter the data that I show in a PointPrimitiveCollection on a cesium globe. I know you can specify the index number, but I'm wondering if there is a way to add some kind of metadata to the points so that I can adjust based on those values?
source to share
You can add the property after creating the point (this line:) points.add({
position : Cesium.Cartesian3.fromDegrees(longitude, latitude),
color : color
}).customId = [longitude, latitude];
.
Here's the code that works:
var viewer = new Cesium.Viewer('cesiumContainer');
var points = viewer.scene.primitives.add(new Cesium.PointPrimitiveCollection());
for (var longitude = -180; longitude < 180; longitude++) {
var color = Cesium.Color.PINK;
if ((longitude % 2) === 0) {
color = Cesium.Color.CYAN;
}
for (var latitude = -90; latitude < 90; latitude++) {
points.add({
position : Cesium.Cartesian3.fromDegrees(longitude, latitude),
color : color
}).customId = [longitude, latitude];
}
}
var red = false;
setInterval(function() {
var myPoints = points._pointPrimitives.filter(function(point){return point.customId[1] > -20 && point.customId[1] < 20;});
red = !red;
myPoints.forEach(function(point) {
point.color = red ? Cesium.Color.GREEN : Cesium.Color.RED;
})
}, 2000);
This code toggles the color of the dots from -20 to 20 in latitude. You can set any custom property you want and play around with it (note - this code is not optimal anyway and is for demonstration purposes only). Working example: http://plnkr.co/edit/DxWMwfdr4L5pfHRlVmlX?p=preview
source to share