GeoJsonDataSource

new Cesium.GeoJsonDataSource(name)

A DataSource which processes both GeoJSON and TopoJSON data. simplestyle-spec properties will also be used if they are present.
Name Type Description
name String optional The name of this data source. If undefined, a name will be taken from the name of the GeoJSON file.
Example:
const viewer = new Cesium.Viewer('cesiumContainer');
viewer.dataSources.add(Cesium.GeoJsonDataSource.load('../../SampleData/ne_10m_us_states.topojson', {
  stroke: Cesium.Color.HOTPINK,
  fill: Cesium.Color.PINK,
  strokeWidth: 3,
  markerSymbol: '?'
}));
Demo:

Members

static Cesium.GeoJsonDataSource.clampToGround : Boolean

Gets or sets default of whether to clamp to the ground.
Default Value: false

static Cesium.GeoJsonDataSource.crsLinkHrefs : Object

Gets an object that maps the href property of a crs link to a callback function which takes the crs properties object and returns a Promise that resolves to a function that takes a GeoJSON coordinate and transforms it into a WGS84 Earth-fixed Cartesian. Items in this object take precedence over those defined in crsLinkHrefs, assuming the link has a type specified.

static Cesium.GeoJsonDataSource.crsLinkTypes : Object

Gets an object that maps the type property of a crs link to a callback function which takes the crs properties object and returns a Promise that resolves to a function that takes a GeoJSON coordinate and transforms it into a WGS84 Earth-fixed Cartesian. Items in crsLinkHrefs take precedence over this object.

static Cesium.GeoJsonDataSource.crsNames : Object

Gets an object that maps the name of a crs to a callback function which takes a GeoJSON coordinate and transforms it into a WGS84 Earth-fixed Cartesian. Older versions of GeoJSON which supported the EPSG type can be added to this list as well, by specifying the complete EPSG name, for example 'EPSG:4326'.

static Cesium.GeoJsonDataSource.fill : Color

Gets or sets default color for polygon interiors.
Default Value: Color.YELLOW

static Cesium.GeoJsonDataSource.markerColor : Color

Gets or sets the default color of the map pin created for each point.
Default Value: Color.ROYALBLUE

static Cesium.GeoJsonDataSource.markerSize : Number

Gets or sets the default size of the map pin created for each point, in pixels.
Default Value: 48

static Cesium.GeoJsonDataSource.markerSymbol : String

Gets or sets the default symbol of the map pin created for each point. This can be any valid Maki identifier, any single character, or blank if no symbol is to be used.

static Cesium.GeoJsonDataSource.stroke : Color

Gets or sets the default color of polylines and polygon outlines.
Default Value: Color.BLACK

static Cesium.GeoJsonDataSource.strokeWidth : Number

Gets or sets the default width of polylines and polygon outlines.
Default Value: 2.0

avoidSelfOverlap : Boolean

Billboard或者Label对象重叠检测,开启此项会动态计算、优先显示更靠近视角的billboard或者label,被遮挡的对象不予显示。
Gets an event that will be raised when the underlying data changes.
This DataSource only defines static data, therefore this property is always undefined.
Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.
Gets the credit that will be displayed for the data source
Gets the collection of Entity instances.
Gets an event that will be raised if an error is encountered during processing.
重叠检测参数,Billboard或者Label类型对象包围盒的外延像素大小
Gets a value indicating if the data source is currently loading data.
Gets an event that will be raised when the data source either starts or stops loading.
Gets or sets a human-readable name for this instance.
Gets whether or not this data source should be displayed.

Methods

static Cesium.GeoJsonDataSource.load(data, options)Promise.<GeoJsonDataSource>

Creates a Promise to a new instance loaded with the provided GeoJSON or TopoJSON data.
Name Type Description
data Resource | String | Object A url, GeoJSON object, or TopoJSON object to be loaded.
options GeoJsonDataSource.LoadOptions optional An object specifying configuration options
Returns:
A promise that will resolve when the data is loaded.

getVisibleAtViewport(index)

查询视口是否显示
Name Type Description
index Number 视口索引号,最大值为8,索引号从下到上,左右往返排序

load(data, options)Promise.<GeoJsonDataSource>

Asynchronously loads the provided GeoJSON or TopoJSON data, replacing any existing data.
Name Type Description
data Resource | String | Object A url, GeoJSON object, or TopoJSON object to be loaded.
options GeoJsonDataSource.LoadOptions optional An object specifying configuration options
Returns:
a promise that will resolve when the GeoJSON is loaded.

process(data, options)Promise.<GeoJsonDataSource>

Asynchronously loads the provided GeoJSON or TopoJSON data, without replacing any existing data.
Name Type Description
data Resource | String | Object A url, GeoJSON object, or TopoJSON object to be loaded.
options GeoJsonDataSource.LoadOptions optional An object specifying configuration options
Returns:
a promise that will resolve when the GeoJSON is loaded.

setVisibleAtViewport(index, visible)

数据显示视口设置
Name Type Description
index Number 视口索引号,最大值为8,索引号从下到上,左右往返排序
visible Boolean 是否显示,默认值为true

setVisibleAtViewportOnly(index, visible)

多视口显示设置,可设置该数据仅在指定的视口索引显示或隐藏,index可以为具体值也可为数组,当index为undefined时,该数据在所有窗口显示或隐藏
Name Type Description
index Number | Array 视口的索引值
visible Boolean 显示/隐藏,默认为ture
Example:
obj.setVisibleAtViewportOnly([0,2,4], false);//设置对象仅在0,2,4视口隐藏,其他窗口显示
obj.setVisibleAtViewportOnly([0,1,2,6], true);//设置对象仅在0,1,2,6视口显示,其他窗口隐藏
obj.setVisibleAtViewportOnly(undefined, true);//设置对象仅在所有视口都显示

update(time)Boolean

Updates the data source to the provided time. This function is optional and is not required to be implemented. It is provided for data sources which retrieve data based on the current animation time or scene state. If implemented, update will be called by DataSourceDisplay once a frame.
Name Type Description
time JulianDate The simulation time.
Returns:
True if this data source is ready to be displayed at the provided time, false otherwise.

Type Definitions

Cesium.GeoJsonDataSource.describe(properties, nameProperty)

This callback is displayed as part of the GeoJsonDataSource class.
Name Type Description
properties Object The properties of the feature.
nameProperty String The property key that Cesium estimates to have the name of the feature.

Cesium.GeoJsonDataSource.LoadOptions

Initialization options for the load method.
Properties:
Name Type Attributes Default Description
sourceUri String <optional>
Overrides the url to use for resolving relative links.
describe GeoJsonDataSource.describe <optional>
GeoJsonDataSource.defaultDescribeProperty A function which returns a Property object (or just a string).
markerSize Number <optional>
GeoJsonDataSource.markerSize The default size of the map pin created for each point, in pixels.
markerSymbol String <optional>
GeoJsonDataSource.markerSymbol The default symbol of the map pin created for each point.
markerColor Color <optional>
GeoJsonDataSource.markerColor The default color of the map pin created for each point.
stroke Color <optional>
GeoJsonDataSource.stroke The default color of polylines and polygon outlines.
strokeWidth Number <optional>
GeoJsonDataSource.strokeWidth The default width of polylines and polygon outlines.
fill Color <optional>
GeoJsonDataSource.fill The default color for polygon interiors.
clampToGround Boolean <optional>
GeoJsonDataSource.clampToGround true if we want the geometry features (polygons or linestrings) clamped to the ground.
credit Credit | String <optional>
A credit for the data source, which is displayed on the canvas.
options.avoidSelfOverlap Boolean <optional>
false Billboard或者Label对象重叠检测,开启此项会动态计算、优先显示更靠近视角的billboard或者label,被遮挡的对象不予显示.
options.interval Number <optional>
1.0 重叠检测参数,Billboard或者Label类型对象包围盒的外延像素大小.
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.