I’d like to have some similar controls/functionalities as my
Openlayers map, but I don’t know if Cesium can do those or has plans to do those
or if you have some suggestions for things like :
Add a Map Scale or a Scale Bar;
Edit/update a Polygon: This would mean two kind
of updates:
2.1 Pure
code update, for example: If I add lots of geometry instances to a primitive,
from the Cesium API, now I can get a geometry
of a geometry instance from the primitive, but then I couldn’t get the vertices
(or the positions, holes of a polygon) from the geometry, and not able to update
them. Please see my sample code below:
function
addTest1000Polygons(primitives, ellipsoid){
var
child = new Cesium.CompositePrimitive();
primitives.add(child);
child.show = true;
var x =-180;
var y = -90;
var delta = 1;
var polyInstances = [];
for (var i = 0; i < 1000; ++i) {
if (y>90)
{
return;
}
if (x > 180) {
x = -180;
y = y + 2*delta;
}
var positions =
ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(x,
y),
Cesium.Cartographic.fromDegrees(x,
y + delta),
Cesium.Cartographic.fromDegrees(x
-
delta, y + delta),
Cesium.Cartographic.fromDegrees(x
-
delta, y),
Cesium.Cartographic.fromDegrees(x,
y)
]);
var polyInstance = new
Cesium.GeometryInstance({
geometry :
Cesium.PolygonGeometry.fromPositions({
positions :
positions,
vertexFormat
: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
}),
attributes: {
color:
Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED)
}
});
polyInstances.push(polyInstance);
x = x + 2*delta;
}
// create a nested polygon with holes outline
var polygonWithHole = new Cesium.PolygonGeometry({ polygonHierarchy : {
positions :
ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(-109.0,
30.0),
Cesium.Cartographic.fromDegrees(-95.0,
30.0),
Cesium.Cartographic.fromDegrees(-95.0,
40.0),
Cesium.Cartographic.fromDegrees(-109.0,
40.0) ]),
holes : [{
positions :
ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(-107.0,
31.0),
Cesium.Cartographic.fromDegrees(-107.0,
39.0),
Cesium.Cartographic.fromDegrees(-97.0,
39.0),
Cesium.Cartographic.fromDegrees(-97.0,
31.0) ]),
holes : [{
positions :
ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(-105.0,
33.0),
Cesium.Cartographic.fromDegrees(-99.0,
33.0),
Cesium.Cartographic.fromDegrees(-99.0,
37.0),
Cesium.Cartographic.fromDegrees(-105.0,
37.0) ]),
holes : [{
positions :
ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(-103.0,
34.0),
Cesium.Cartographic.fromDegrees(-101.0,
34.0),
Cesium.Cartographic.fromDegrees(-101.0,
36.0),
Cesium.Cartographic.fromDegrees(-103.0,
36.0) ])
}]
}]
}]
}});
var holegeometry = Cesium.PolygonGeometry.createGeometry(polygonWithHole);
var holePolygonInstance = new Cesium.GeometryInstance({
geometry : holegeometry,
attributes: {
color:
Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.GREEN)
}
});
polyInstances.push(holePolygonInstance);
child.add(new Cesium.Primitive({
geometryInstances : polyInstances,
appearance : new
Cesium.PerInstanceColorAppearance({
closed : true,
translucent : true
})
}));
var allGeoInstances = child.get(0).geometryInstances;
var len = allGeoInstances.length;
//Just use the last one as an example
var myLastGeoIns = allGeoInstances[len-1];
console.log('myLastGeoIns:' + myLastGeoIns);
var myLastGeo = myLastGeoIns.geometry;
console.log('myLastGeo' + myLastGeo);
//myLastGeo is an object of Geometry, ref. : http://cesiumjs.org/Cesium/Build/Documentation/Geometry.html?classFilter=Geometrry&show=all
//how can I get my parts (exterior and holes) or coordinates
from this object and change them?
var att = myLastGeo.attributes;
console.log('attributes:' + att);
var pos = att.position;
console.log('position:' + pos);
//I couldn't go further from this point
}
2.2 Edit
a Polygon on the MAP directly, I would like I can edit any polygon in any
primitives displayed to the map by javascript,( for example using the above
code) (not only the ones drawn by the
DrawHelper plugin tool).
Select a polygon and export it to a shape file?
Import a shape file?
About the layer switcher which openlayers
provide, the thing is for Cesium, looks like it doesn’t have the kind of “overlay
layers” concept: the geometries added on
the fly by js to the map are hold into a primitive/composite instead of a “layer
in openlayers”. This is ok, but the Primitive/Composite API looks like
lack of operations support for users easy to manipulate them for things like
layer switcher, and operations depends on a layer. etc.
Map Context menu that openlayers supports? (right-click
and depends on where you click and what underneath – layer, geometry etc), you’ll
get a different context menu?
Sorry I through so many things once to you, but as I’m thinking about these things now and would like to know your suggestions.
Thanks a lot for help.
Cathy