It is possible to make the interior color of a polygon completely transparent, leaving only the outline visible and clickable. However, there are some drawbacks to this method that I will address below. First, here is an example of how you can achieve this:
var czml = [{
"id" : "document",
"name" : "CZML Geometries: Polygon",
"version" : "1.0"
}, {
"id" : "outlinedPolygon",
"name" : "Outlined Polygon",
"polygon" : {
"positions" : {
"cartographicDegrees" : [
-108.0, 25.0, 0,
-100.0, 25.0, 0,
-100.0, 30.0, 0,
-108.0, 30.0, 0
]
},
"material" : {
"solidColor" : {
"color" : {
"rgba" : [0, 0, 0, 0]
}
}
},
"extrudedHeight" : 0,
"perPositionHeight" : true,
"outline" : true,
"outlineColor" : {
"rgba" : [255, 255, 0, 255]
}
}
}];
var viewer = new Cesium.Viewer('cesiumContainer');
var dataSource = Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(dataSource);
viewer.zoomTo(dataSource);
However, there are issues with this approach. Many Windows-based systems and other WebGL implementations do not support line widths other than exactly 1.0
pixels, resulting in a thin outline on those systems.
Additionally, rendering may still process and discard the transparent fragments from the polygon's interior, leading to potential performance issues.
To overcome these problems, consider using a Polyline instead of a Polygon for outlining. Cesium offers a custom-built system for drawing screen-space polygons as polylines, bypassing the 1-pixel line limitations common in many WebGL implementations. Furthermore, Polylines do not attempt to fill enclosed areas.
To fully enclose an area using polylines, you need to repeat the first point as the last point. Here is an example:
var czml = [{
"id" : "document",
"name" : "CZML Geometries: Polyline",
"version" : "1.0"
}, {
"id" : "outlinedPolygon",
"name" : "Outlined Polygon",
"polyline" : {
"positions" : {
"cartographicDegrees" : [
-108.0, 25.0, 0,
-100.0, 25.0, 0,
-100.0, 30.0, 0,
-108.0, 30.0, 0,
-108.0, 25.0, 0
]
},
"width": 5,
"material" : {
"solidColor" : {
"color" : {
"rgba" : [255, 255, 0, 255]
}
}
}
}
}];
var viewer = new Cesium.Viewer('cesiumContainer');
var dataSource = Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(dataSource);
viewer.zoomTo(dataSource);