-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Cesium asset management; add new features
Reorganization of the CesiumWidget: - Move functions that create and update Cesium assets (e.g. imagery, terrain, 3Dtiles) from the CesiumWidget view to individual "Map Asset" models - Replace the Layer and Terrain model with a more generic MapAsset model. - Similarly, replace Layers and Terrains collections with a MapAssets collection that can be used in either case. New features: - Enable clicking on individual features in a 3D tileset lay to view more details - Add support for configuring the colours to use for 3D tilesets - colors can be set conditionally in the Cesium config based on feature properties. Only categorical color palettes are enabled at so far. - Add support for configuring 'vector filters' in the Cesium config. These filters conditionally show or hide features of a 3D tileset based on properties of the features. Relates to #1770, #1798, #1789, #1790, #1791, #1780, #1778, #1797
- Loading branch information
Showing
29 changed files
with
2,889 additions
and
1,032 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
'use strict'; | ||
|
||
define( | ||
[ | ||
'jquery', | ||
'underscore', | ||
'backbone', | ||
'models/maps/assets/MapAsset', | ||
'models/maps/assets/Cesium3DTileset', | ||
'models/maps/assets/CesiumImagery', | ||
'models/maps/assets/CesiumTerrain', | ||
], | ||
function ( | ||
$, | ||
_, | ||
Backbone, | ||
MapAsset, | ||
Cesium3DTileset, | ||
CesiumImagery, | ||
CesiumTerrain | ||
) { | ||
|
||
/** | ||
* @class MapAssets | ||
* @classdesc A MapAssets collection is a group of MapAsset models - models that | ||
* provide the information required to render geo-spatial data on a map, including | ||
* imagery (raster), vector, and terrain data. | ||
* @class MapAssets | ||
* @classcategory Collections/Maps | ||
* @extends Backbone.Collection | ||
* @since 2.x.x | ||
* @constructor | ||
*/ | ||
var MapAssets = Backbone.Collection.extend( | ||
/** @lends MapAssets.prototype */ { | ||
|
||
/** | ||
* Creates the type of Map Asset based on the given type. This function is | ||
* typically not called directly. It is used by Backbone.js when adding a new | ||
* model to the collection. | ||
* @param {object} attrs - A literal object that contains the attributes to pass | ||
* to the model | ||
* @param {object} options - A literal object of additional options to pass to the | ||
* model | ||
* @returns {Cesium3DTileset|CesiumImagery|CesiumTerrain} Returns a MapAsset model | ||
*/ | ||
model: function (attrs, options) { | ||
try { | ||
|
||
// Supported types: Matches each 'type' attribute to the appropriate MapAsset | ||
// model. See also CesiumWidgetView.mapAssetRenderFunctions | ||
var mapAssetTypes = [ | ||
{ | ||
types: ['Cesium3DTileset'], | ||
model: Cesium3DTileset | ||
}, | ||
{ | ||
types: ['BingMapsImageryProvider'], | ||
model: CesiumImagery | ||
}, | ||
{ | ||
types: ['CesiumTerrainProvider'], | ||
model: CesiumTerrain | ||
} | ||
]; | ||
|
||
var type = attrs.type | ||
var modelOption = _.find(mapAssetTypes, function (option) { | ||
return option.types.includes(type) | ||
}) | ||
|
||
// Don't add an unsupported type to the collection | ||
if (modelOption) { | ||
return new modelOption.model(attrs, options) | ||
} | ||
|
||
} | ||
catch (error) { | ||
console.log( | ||
'Failed to add a new model to a MapAssets collection' + | ||
'. Error details: ' + error | ||
); | ||
} | ||
}, | ||
|
||
/** | ||
* Executed when a new MapAssets collection is created. | ||
*/ | ||
initialize: function () { | ||
try { | ||
|
||
// Only allow one Map Asset in the collection to be selected at a time. When a | ||
// Map Asset model's 'selected' attribute is changed to true, change all of the | ||
// other models' selected attributes to false. | ||
this.stopListening(this, 'change:selected'); | ||
this.listenTo(this, 'change:selected', function (changedAsset, newValue) { | ||
if (newValue === true) { | ||
var otherModels = this.reject(function (assetModel) { | ||
return assetModel === changedAsset | ||
}) | ||
otherModels.forEach(function (otherModel) { | ||
otherModel.set('selected', false) | ||
}) | ||
} | ||
}) | ||
} | ||
catch (error) { | ||
console.log( | ||
'There was an error initializing a MapAssets collection' + | ||
'. Error details: ' + error | ||
); | ||
} | ||
}, | ||
|
||
} | ||
); | ||
|
||
return MapAssets; | ||
|
||
} | ||
); |
Oops, something went wrong.