项目作者: openlayers

项目描述 :
OpenLayers - Cesium integration
高级语言: JavaScript
项目地址: git://github.com/openlayers/ol-cesium.git
创建时间: 2014-07-11T15:45:47Z
项目社区:https://github.com/openlayers/ol-cesium

开源协议:BSD 2-Clause "Simplified" License

下载


OpenLayers - Cesium library

OLCS is an opensource JS library for making OpenLayers and CesiumJS works together, in the same application.
It addresses several use-cases:

See live examples.

The npm package is called olcs.
Note that CesiumJS is accessed through the global window.Cesium object.

Features

Switch smoothly between 2D and 3D and synchronize:

  • Map context (bounding box and zoom level);
  • Raster data sources;
  • Vector data sources in 2D and 3D;
  • Map selection (selected items);
  • Animated transitions between map and globe view.

The library is configurable and extensible and allows:

  • Lazy or eager loading of Cesium
  • Limiting Cesium resource consumption (idle detection)

For synchronization of maps in projections other than EPSG:4326 and EPSG:3857 you need 2 datasets, see the customProj example.

Adding 3D to an existing OpenLayers map

  1. // Create an OpenLayers map or start from an existing one.
  2. import Map from 'ol/Map.js';
  3. const ol2dMap = new Map({
  4. ...
  5. });
  6. ol2dMap.addLayer(....)
  1. // Pass the map to the OL-Cesium constructor
  2. // OL-Cesium will create and synchronize a 3D CesiumJs globe from your layers and data.
  3. import OLCesium from 'olcs';
  4. const ol3d = new OLCesium({map: ol2dMap});
  1. ol3d.setEnabled(true); // switch to 3D - show the globe
  2. ol3d.setEnabled(false); // switch to 2D - show the map

Build with your prefered bundler.

You can use any version of CesiumJS: latest upstream, a fork…
Simply provide it as window.Cesium global:

  1. <script src="https://cesium.com/downloads/cesiumjs/releases/1.113/Build/Cesium/Cesium.js"></script>

Extending CesiumJS with new capabilities

  1. // Start from a CesiumJS globe
  2. const viewer = getYourCesiumJSViewer();
  3. // Add OpenLayers imagery provider
  4. import {OLImageryProvider} from 'olcs';
  5. viewer.scene.imageryLayers.addImageryProvider(new OLImageryProvider(...));
  6. // Add Mapbox MVT imagery provider (client side rendering)
  7. import {MVTImageryProvider} from 'olcs';
  8. viewer.scene.imageryLayers.addImageryProvider(new MVTImageryProvider(...));

This is a bit limited at the moment but idea would be to implement:

  • client side reprojection;
  • full client side MVT rendering;
  • GeoTIFF rendering;
  • … any feature available in OpenLayers.

Cherry-picking the pieces you need

Specific low level functionnalities can be cherry-picked from the library.
For example:

  1. // GoogleMap rotating effect
  2. import {rotateAroundBottomCenter} from 'olcs';
  3. rotateAroundBottomCenter(viewer.scene, someAngle);
  1. // convert OpenLayers Vector Layer to CesiumJS primitives
  2. import {FeatureConverter} from 'olcs';
  3. const converter = new FeatureConverter(viewer.scene);
  4. const featurePrimitiveMap: Record<number, PrimitiveCollection> = {};
  5. const counterpart: VectorLayerCounterpart = this.converter.olVectorLayerToCesium(olLayer, view, featurePrimitiveMap);
  6. const csPrimitives = counterpart.getRootPrimitive();
  7. viewer.scene.primitives.add(csPrimitives);
  1. // Even more powerful, use a synchronizer
  2. import {VectorSynchronizer} from 'olcs';
  3. const synchronizer = new VectorSynchronizer(ol2dMtheap, viewer.scene);

If you think some low level features should be spotlited here, open an issue and let’s discuss it.

Configuration

Use properties to control specific aspects of OL-Cesium integration, see the PROPERTIES.MD.

Also, check the api doc.

Limitations due to OpenLayers

There are a few limitations due to decisions on

Contributing

See CONTRIBUTING.md.