Hi,I have a geojson file within 8000+ datas and i want to render them with different colors.
I use two ways(primitive and entity) to add the datas but find it takes a long time(entity using 9 seconds and primitive using at least 40 seconds).
My question is how to add large geojson data quickly?
Below is my codes
PS:in the primitive code, if i set asynchronous to true,the application will broken and show below error message
【DeveloperError: _workerName must be defined for asynchronous geometry.】
function entity() {
Cesium.GeoJsonDataSource.load('data/姜山云龙现状.geojson', config).then(function(data){
data.name = 'mydata';
viewer.dataSources.add(data);
const entities = data.entities.values;
entities.forEach(entity => {
let color = getColor(entity.properties.Type.toString());
entity.polygon.fill = true;
entity.polygon.material = Cesium.Color.fromCssColorString(color);
entity.polygon.outline = true;
entity.polygon.outlineColor = Cesium.Color.WHITE;
});
});
}
function primitive() {
viewer.dataSources.remove('mydata');
$.get('data/姜山云龙现状.geojson', function(data)
{
const features = data.features;
addDataToGlobe(features);
})
}
function addDataToGlobe(features)
{
const instances = [];
for(let i=0; i<features.length; i++)
{
let feature = features[i];
for(let j=0; j<feature.geometry.coordinates[0][0].length; j++)
{
let arr = feature.geometry.coordinates[0][0];
let newArr = new Array();
arr.forEach(item => {
// item = [item[0],item[1]];
newArr.push(item[0]);
newArr.push(item[1]);
})
const polygon = new Cesium.PolygonGeometry({
polygonHierarchy : new Cesium.PolygonHierarchy(
Cesium.Cartesian3.fromDegreesArray(newArr)
),
vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
});
const geometry = Cesium.PolygonGeometry.createGeometry(polygon);
instances.push(new Cesium.GeometryInstance({
geometry : geometry,
attributes :
{
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString(getColor(feature.properties.Type.toString()))),
}
}));
}
}
const primitive = new Cesium.Primitive({
geometryInstances : instances,
appearance : new Cesium.PerInstanceColorAppearance({ // 为每个instance着色
translucent : true,
closed : false
}),
asynchronous : false, // 确定基元是异步创建还是阻塞直到准备就绪
});
viewer.scene.primitives.add(primitive);
}