GeoJsonPrimitive
Cesium v1.147 · 中文

轻量级的 GeoJSON 加载器,可将特征直接转换为 BufferPointCollection、BufferPolylineCollection 和 BufferPolygonCollection。 与 GeoJsonDataSource 不同,此路径不会创建实体。 而是提供高吞吐量的缓冲原始要素集合,可直接添加到 Scene#primitives 中。

new Cesium.GeoJsonPrimitive(options)

Name Type Description
options GeoJsonPrimitiveConstructorOptions optional
Examples:
// 加载 GeoJSON
const loader = await Cesium.GeoJsonPrimitive.fromUrl("./data.geojson");
viewer.scene.primitives.add(loader);
// 访问 GeoJSON 特征和属性
loader.points;     // BufferPointCollection | undefined
loader.polylines;  // BufferPolylineCollection | undefined
loader.polygons;   // BufferPolygonCollection | undefined
loader.ids;        // 源特征 ID
loader.properties; // 源特征属性
// 设置 GeoJSON 样式
const material = new Cesium.BufferPolylineMaterial({
color: Cesium.Color.RED,
width: 4,
});

const polyline = new Cesium.BufferPolyline();
const count = primitive.polylines.primitiveCount;
for (let i = 0; i < count; i++) {
primitive.polylines.get(i, polyline);

const properties = primitive.getProperties(polyline.featureId);
if (properties.myCustomProperty === true) {
polyline.setMaterial(material);
  }
}
Experimental

This 该特征尚未最终确定,可能根据 Cesium 的标准弃用政策发生变化。

Members

readonly featureCount : number

加载集合所代表的特征数量。

readonly ids : Array.<(string|number|undefined)>

由 GeoJsonPrimitive 生成的整数 ID 到 GeoJSON 源中的整数或字符串特征 ID 的映射表。
点几何数据的缓冲点集合。
多边形几何数据的缓冲多边形集合。
线状几何数据的缓冲多线集合。

readonly properties : Array.<Record.<string, unknown>>

按生成的整数 ID 索引的源 GeoJSON 属性。

readonly url : string|undefined

通过 GeoJsonPrimitive.fromUrl 创建时的加载源 URL。

Methods

static Cesium.GeoJsonPrimitive.fromGeoJson(geoJson, options) → GeoJsonPrimitive

从解析后的 GeoJSON 对象直接创建加载器。
Name Type Description
geoJson object
options GeoJsonPrimitiveConstructorOptions optional
Returns:

async static Cesium.GeoJsonPrimitive.fromUrl(url, options) → Promise.<GeoJsonPrimitive>

从 URL 或 Resource 加载 GeoJSON。
Name Type Description
url Resource | string
options GeoJsonPrimitiveConstructorOptions optional
Returns:
Name Type Description
featureId number
Name Type Description
featureId number
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.