Skip to content

Commit adc8ccc

Browse files
committed
Add additional query parameter options to CesiumViewer.
sourceType=czml/geojson/kml specifies the type of data to allow loading URLs which don't have a file extension (such as a web service). flyTo=false optionally disables the automatic flyTo after loading data.
1 parent 6a53d84 commit adc8ccc

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

Apps/CesiumViewer/CesiumViewer.js

+34-15
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,28 @@ define([
3232
'use strict';
3333

3434
/*
35-
* 'debug' : true/false, // Full WebGL error reporting at substantial performance cost.
36-
* 'lookAt' : CZML id, // The CZML ID of the object to track at startup.
37-
* 'source' : 'file.czml', // The relative URL of the CZML file to load at startup.
38-
* 'stats' : true, // Enable the FPS performance display.
39-
* 'theme' : 'lighter', // Use the dark-text-on-light-background theme.
40-
* 'scene3DOnly' : false // Enable 3D only mode
41-
* 'view' : longitude,latitude,[height,heading,pitch,roll]
42-
* // Using degrees and meters
43-
* // [height,heading,pitch,roll] default is looking straight down, [300,0,-90,0]
35+
Options parsed from query string:
36+
source=url The URL of a CZML/GeoJSON/KML data source to load at startup.
37+
Automatic data type detection uses file extension.
38+
sourceType=czml/geojson/kml
39+
Override data type detection for source.
40+
flyTo=false Don't automatically fly to the loaded source.
41+
tmsImageryUrl=url Automatically use a TMS imagery provider.
42+
lookAt=id The ID of the entity to track at startup.
43+
stats=true Enable the FPS performance display.
44+
inspector=true Enable the inspector widget.
45+
debug=true Full WebGL error reporting at substantial performance cost.
46+
theme=lighter Use the dark-text-on-light-background theme.
47+
scene3DOnly=true Enable 3D only mode.
48+
view=longitude,latitude,[height,heading,pitch,roll]
49+
Automatically set a camera view. Values in degrees and meters.
50+
[height,heading,pitch,roll] default is looking straight down, [300,0,-90,0]
51+
saveCamera=false Don't automatically update the camera view in the URL when it changes.
4452
*/
4553
var endUserOptions = queryToObject(window.location.search.substring(1));
4654

4755
var imageryProvider;
48-
if (endUserOptions.tmsImageryUrl) {
56+
if (defined(endUserOptions.tmsImageryUrl)) {
4957
imageryProvider = createTileMapServiceImageryProvider({
5058
url : endUserOptions.tmsImageryUrl
5159
});
@@ -108,13 +116,24 @@ define([
108116
var view = endUserOptions.view;
109117
var source = endUserOptions.source;
110118
if (defined(source)) {
111-
var loadPromise;
119+
var sourceType = endUserOptions.sourceType;
120+
if (!defined(sourceType)) {
121+
// autodetect using file extension if not specified
122+
if (/\.czml$/i.test(source)) {
123+
sourceType = 'czml';
124+
} else if (/\.geojson$/i.test(source) || /\.json$/i.test(source) || /\.topojson$/i.test(source)) {
125+
sourceType = 'geojson';
126+
} else if (/\.kml$/i.test(source) || /\.kmz$/i.test(source)) {
127+
sourceType = 'kml';
128+
}
129+
}
112130

113-
if (/\.czml$/i.test(source)) {
131+
var loadPromise;
132+
if (sourceType === 'czml') {
114133
loadPromise = CzmlDataSource.load(source);
115-
} else if (/\.geojson$/i.test(source) || /\.json$/i.test(source) || /\.topojson$/i.test(source)) {
134+
} else if (sourceType === 'geojson') {
116135
loadPromise = GeoJsonDataSource.load(source);
117-
} else if (/\.kml$/i.test(source) || /\.kmz$/i.test(source)) {
136+
} else if (sourceType === 'kml') {
118137
loadPromise = KmlDataSource.load(source, {
119138
camera: scene.camera,
120139
canvas: scene.canvas
@@ -134,7 +153,7 @@ define([
134153
var error = 'No entity with id "' + lookAt + '" exists in the provided data source.';
135154
showLoadError(source, error);
136155
}
137-
} else if (!defined(view)) {
156+
} else if (!defined(view) && endUserOptions.flyTo !== 'false') {
138157
viewer.flyTo(dataSource);
139158
}
140159
}).otherwise(function(error) {

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Change Log
1414
* Added support for Internet Explorer.
1515
* Added a `ClippingPlane` object to be used with `ClippingPlaneCollection`.
1616
* Updated `WebMapServiceImageryProvider` so it can take an srs or crs string to pass to the resource query parameters based on the WMS version. [#6223](https://github.com/AnalyticalGraphicsInc/cesium/issues/6223)
17+
* Added additional query parameter options to the CesiumViewer demo application:
18+
* sourceType specifies the type of data source if the URL doesn't have a known file extension.
19+
* flyTo=false optionally disables the automatic flyTo after loading the data source.
1720
* Added a multi-part CZML example to Sandcastle. [#6320](https://github.com/AnalyticalGraphicsInc/cesium/pull/6320)
1821

1922
##### Fixes :wrench:

0 commit comments

Comments
 (0)