import * as cesium from 'cesium'; import { Color, Credit, Cartesian3, HeightReference, PointPrimitive, CircleGeometry, BillboardGraphics, Billboard, LabelGraphics, Label, PolygonGeometry, PolylineGeometry, Viewer, Entity, Cartesian2, Event, BillboardCollection, LabelCollection, PointPrimitiveCollection, PrimitiveCollection, Primitive, PinBuilder, GeometryInstance, Resource } from 'cesium'; // Type definitions for non-npm package geojson 7946.0 // Project: https://geojson.org/ // Definitions by: Jacob Bruun // Arne Schubert // Jeff Jacobson // Ilia Choly // Dan Vanderkam // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 /** * The value values for the "type" property of GeoJSON Objects. * https://tools.ietf.org/html/rfc7946#section-1.4 */ type GeoJsonTypes = GeoJSON$1['type']; /** * Bounding box * https://tools.ietf.org/html/rfc7946#section-5 */ type BBox = [number, number, number, number] | [number, number, number, number, number, number]; /** * A Position is an array of coordinates. * https://tools.ietf.org/html/rfc7946#section-3.1.1 * Array should contain between two and three elements. * The previous GeoJSON specification allowed more elements (e.g., which could be used to represent M values), * but the current specification only allows X, Y, and (optionally) Z to be defined. */ type Position = number[]; // [number, number] | [number, number, number]; /** * The base GeoJSON object. * https://tools.ietf.org/html/rfc7946#section-3 * The GeoJSON specification also allows foreign members * (https://tools.ietf.org/html/rfc7946#section-6.1) * Developers should use "&" type in TypeScript or extend the interface * to add these foreign members. */ interface GeoJsonObject { // Don't include foreign members directly into this type def. // in order to preserve type safety. // [key: string]: any; /** * Specifies the type of GeoJSON object. */ type: GeoJsonTypes; /** * Bounding box of the coordinate range of the object's Geometries, Features, or Feature Collections. * The value of the bbox member is an array of length 2*n where n is the number of dimensions * represented in the contained geometries, with all axes of the most southwesterly point * followed by all axes of the more northeasterly point. * The axes order of a bbox follows the axes order of geometries. * https://tools.ietf.org/html/rfc7946#section-5 */ bbox?: BBox | undefined; } /** * Union of GeoJSON objects. */ type GeoJSON$1 = Geometry | Feature | FeatureCollection; /** * Geometry object. * https://tools.ietf.org/html/rfc7946#section-3 */ type Geometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon | GeometryCollection; /** * Point geometry object. * https://tools.ietf.org/html/rfc7946#section-3.1.2 */ interface Point extends GeoJsonObject { type: 'Point'; coordinates: Position; } /** * MultiPoint geometry object. * https://tools.ietf.org/html/rfc7946#section-3.1.3 */ interface MultiPoint extends GeoJsonObject { type: 'MultiPoint'; coordinates: Position[]; } /** * LineString geometry object. * https://tools.ietf.org/html/rfc7946#section-3.1.4 */ interface LineString extends GeoJsonObject { type: 'LineString'; coordinates: Position[]; } /** * MultiLineString geometry object. * https://tools.ietf.org/html/rfc7946#section-3.1.5 */ interface MultiLineString extends GeoJsonObject { type: 'MultiLineString'; coordinates: Position[][]; } /** * Polygon geometry object. * https://tools.ietf.org/html/rfc7946#section-3.1.6 */ interface Polygon extends GeoJsonObject { type: 'Polygon'; coordinates: Position[][]; } /** * MultiPolygon geometry object. * https://tools.ietf.org/html/rfc7946#section-3.1.7 */ interface MultiPolygon extends GeoJsonObject { type: 'MultiPolygon'; coordinates: Position[][][]; } /** * Geometry Collection * https://tools.ietf.org/html/rfc7946#section-3.1.8 */ interface GeometryCollection extends GeoJsonObject { type: 'GeometryCollection'; geometries: G[]; } type GeoJsonProperties = { [name: string]: any } | null; /** * A feature object which contains a geometry and associated properties. * https://tools.ietf.org/html/rfc7946#section-3.2 */ interface Feature extends GeoJsonObject { type: 'Feature'; /** * The feature's geometry */ geometry: G; /** * A value that uniquely identifies this feature in a * https://tools.ietf.org/html/rfc7946#section-3.2. */ id?: string | number | undefined; /** * Properties associated with this feature. */ properties: P; } /** * A collection of feature objects. * https://tools.ietf.org/html/rfc7946#section-3.3 */ interface FeatureCollection extends GeoJsonObject { type: 'FeatureCollection'; features: Array>; } type GeoJSONType = 'point' | 'line' | 'polygon' | 'mix'; type GeoJsonPrimitiveLayerOptions = { sourceUri?: string; markerSize: number; markerSymbol?: string; markerColor: Color; stroke: Color; strokeWidth: number; fill: Color; clampToGround: boolean; credit?: Credit | string; depthTest?: boolean; customMarker?: boolean; }; type PrimitiveItem = PointPrimitiveItem | BillboardPrimitiveItem | PolygonPrimitiveItem | PolylinePrimitiveItem | LabelPrimitiveItem | CirclePrimitiveItem; type GeoJsonFeatureItem = { id?: string; properties?: Record; center?: { cartesian3: Cartesian3; height?: number; }; }; type PointPrimitiveItem = { type: 'Point'; position: Cartesian3; style?: { pixelSize?: number; heightReference?: HeightReference; color?: Color; outlineColor?: Color; outlineWidth?: number; }; instance?: PointPrimitive; } & GeoJsonFeatureItem; type CirclePrimitiveItem = { type: 'Circle'; position: Cartesian3; style?: { color?: Color; extrudedHeight?: number; radius?: number; }; instance?: CircleGeometry; } & GeoJsonFeatureItem; type BillboardPrimitiveItem = { type: 'Billboard'; position: Cartesian3; style?: BillboardGraphics.ConstructorOptions; instance?: Billboard; } & GeoJsonFeatureItem; type LabelPrimitiveItem = { type: 'Label'; position: Cartesian3; style?: LabelGraphics.ConstructorOptions; instance?: Label; } & GeoJsonFeatureItem; type PolygonPrimitiveItem = { type: 'Polygon'; positions: Cartesian3[]; holes: Cartesian3[][]; style?: { material?: Color; /**The distance in meters between the polygon and the ellipsoid surface. */ height?: number; /**The distance in meters between the polygon's extruded face and the ellipsoid surface. */ extrudedHeight?: number; outlineColor?: Color; outlineWidth?: number; }; instance?: PolygonGeometry; } & GeoJsonFeatureItem; type PolylinePrimitiveItem = { type: 'Polyline'; positions: Cartesian3[]; style?: { material?: Color; width?: number; }; instance?: PolylineGeometry; } & GeoJsonFeatureItem; type CrsFunction = (coors: number[]) => Cartesian3; interface EventArgs { position?: Cartesian2; endPosition?: Cartesian2; startPosition?: Cartesian2; [name: string]: any; } type ListenCallback = (movement: EventArgs, substance: T) => void; type ExternalListenCallback = (movement: EventArgs, result: any) => void; type EventType = 'LEFT_DOWN' | 'LEFT_UP' | 'LEFT_CLICK' | 'LEFT_DOUBLE_CLICK' | 'RIGHT_DOWN' | 'RIGHT_UP' | 'RIGHT_CLICK' | 'MIDDLE_DOWN' | 'MIDDLE_UP' | 'MIDDLE_CLICK' | 'MOUSE_MOVE' | 'WHEEL' | 'PINCH_START' | 'PINCH_MOVE' | 'PINCH_END'; declare class Subscriber { private _viewer; private _handler; private _eventCollection; private _externalEventCollection; private readonly _eventTypeList; private _moveDebounce; private _lastTime; private _enablePickResult; private _lastResult; private _enable; private _isDestroy; /** * 是否被销毁 */ get isDestroy(): boolean; /** 是否执行监听回调 */ get enable(): boolean; set enable(val: boolean); constructor(viewer: Viewer, options?: { element?: HTMLCanvasElement; pickResult?: { enable: boolean; moveDebounce?: number; }; }); private _initListener; private _shouldUpdate; private _eventRegister; /** * @description 为Entity添加监听事件 * * @event * * @param {Function} callback 需要相应的事件 * * @param {EventType} eventType 事件类型 */ add(substances: Entity | Entity[], callback: ListenCallback, eventType: EventType): void; /** * @description 添加特定事件,与add不同在于该事件不会过滤Entity * @param callback 事件处理函数 * @param eventType 事件类型 * @return {string} Event Id 事件移除时需要提供事件ID */ addExternal(callback: ExternalListenCallback, eventType: EventType): string; /** *@description 移除指定Substance的相应事件 * @param substances 需要移除事件的Substance * @param eventType 需要移除的时间类型 */ remove(substances: T | T[], eventType: EventType): void; removeExternal(ids: string | string[], eventType?: EventType): void; private _searchExternal; removeNative(viewer: Viewer, eventType: EventType): void; private convertCesiumEventType; destroy(): void; } /** * GraphicLayer 基类 */ declare class BasicGraphicLayer { protected _changed: Event; private _subscriber; protected _subscribIds: string[]; constructor(options: { subscriber?: Subscriber; }); addSubscribers(callback: ExternalListenCallback, eventType: EventType): void; removeSubscribers(ids?: string | string[]): void; } declare class GeoJsonPrimitiveLayer extends BasicGraphicLayer { private _name; private _isLoading; private _error; private _loading; private _primitiveCollection; readonly _promises: Promise[]; private _credit; private _featureItems; private _pinBuilder; private _circleInstances; private _polygonInstances; private _polylineInstances; private _billboardCollection; private _labelCollection; private _pointCollection; private _circlePrimitive; private _polygonPrimitive; private _polylinePrimitive; private _isDestroyed; private _options; private _geojson; constructor(options?: { name?: string; subscriber?: Subscriber; options?: Partial; }); get billboardCollection(): BillboardCollection; get labelCollection(): LabelCollection; get pointPrimitiveCollection(): PointPrimitiveCollection; get primitiveCollection(): PrimitiveCollection; get polygonPrimitive(): Primitive | undefined; get circlePrimitive(): Primitive | undefined; get polylinePrimitive(): Primitive | undefined; get featureItems(): PrimitiveItem[]; get pinBuilder(): PinBuilder; /** * Gets or sets a human-readable name for this instance. * @type {String} */ get name(): string | undefined; set name(value: string | undefined); /** * Gets a value indicating if the data source is currently loading data. * @type {Boolean} */ get loading(): boolean; /** * Gets an event that will be raised when the underlying data changes. * @type {Event} */ get changedEvent(): Event<(...args: any[]) => void>; get credit(): Credit | undefined; /** * Gets an event that will be raised if an error is encountered during processing. * @type {Event} */ get errorEvent(): Event<(...args: any[]) => void>; /** * Gets an event that will be raised when the data source either starts or stops loading. * @type {Event} */ get loadingEvent(): Event<(...args: any[]) => void>; /** * Gets whether or not this data source should be displayed. * @type {Boolean} */ get show(): boolean; set show(value: boolean); /** * 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'. * @type {Object} */ get crsNames(): Record; /** * 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. * @type {Object} */ get crsLinkHrefs(): Record CrsFunction>; /** * 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. * @type {Object} */ get crsLinkTypes(): Record CrsFunction>; get isDestroyed(): boolean; get geojson(): GeoJSON$1 | undefined; private _generateId; addBillboard(item: BillboardPrimitiveItem): Billboard; addLabel(item: LabelPrimitiveItem): Label; addPoint(item: PointPrimitiveItem): cesium.PointPrimitive; addCircle(item: CirclePrimitiveItem): GeometryInstance; addPolygon(item: PolygonPrimitiveItem): GeometryInstance; addPolyline(item: PolylinePrimitiveItem, addFeature?: boolean): GeometryInstance; addFeatureItem(item: PrimitiveItem): PrimitiveItem; /** * 根据id获取FeatureItem * @param {string} id * @returns {PrimitiveItem | undefined} FeatureItem */ getFeatureItemById(id: string): PrimitiveItem | undefined; /** * remove featureItem from primitive collection * @param {string} id featureItem id */ removeFeatureItemById(id: string): boolean; /** * Asynchronously loads the provided GeoJSON or TopoJSON data, replacing any existing data. * * @param {Resource|String|Object} data A url, GeoJSON object to be loaded. * @param {Object} [options] An object with the following properties: * @param {String} [options.sourceUri] Overrides the url to use for resolving relative links. * @returns {Promise.} a promise that will resolve when the GeoJSON is loaded. */ static load(url: string | Resource | GeoJSON.GeoJSON, options?: Partial): Promise; preload(geoJson: GeoJSON.GeoJSON, layerOptions: Partial, sourceUri: string | undefined, clear: boolean): Promise; removeAllPrimitive(): void; reloadPrimitive(depthTest?: boolean): void; destroy(): boolean; } /** * 计算一组多边形坐标的质心 * @param positions 坐标串 */ declare function getPositionsCenter(positions: Cartesian3[], height?: number): { cartesian3: Cartesian3; height: number | undefined; }; export { type BillboardPrimitiveItem, type CirclePrimitiveItem, type GeoJSONType, type GeoJsonFeatureItem, GeoJsonPrimitiveLayer, type GeoJsonPrimitiveLayerOptions, type LabelPrimitiveItem, type PointPrimitiveItem, type PolygonPrimitiveItem, type PolylinePrimitiveItem, type PrimitiveItem, GeoJsonPrimitiveLayer as default, getPositionsCenter };