Skip to content

Commit

Permalink
move files from TerriaJS
Browse files Browse the repository at this point in the history
  • Loading branch information
rsignell-usgs authored Nov 8, 2018
1 parent 05d716b commit d54f6fd
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/ViewModels/createAustraliaBaseMapOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

/*global require*/
var ArcGisMapServerCatalogItem = require('../Models/ArcGisMapServerCatalogItem');
var BaseMapViewModel = require('./BaseMapViewModel');

var createAustraliaBaseMapOptions = function(terria) {
var result = [];

var australianTopo = new ArcGisMapServerCatalogItem(terria);
australianTopo.url = 'http://services.ga.gov.au/gis/rest/services/NationalMap_Colour_Topographic_Base_World_WM/MapServer';
australianTopo.opacity = 1.0;
australianTopo.isRequiredForRendering = true;
australianTopo.name = 'Australian Topography';
australianTopo.allowFeaturePicking = false;

result.push(new BaseMapViewModel({
image: require('../../wwwroot/images/australian-topo.png'),
catalogItem: australianTopo,
contrastColor: '#000000'
}));

return result;
};

module.exports = createAustraliaBaseMapOptions;
53 changes: 53 additions & 0 deletions lib/ViewModels/selectBaseMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

/*global require*/
var defined = require('terriajs-cesium/Source/Core/defined');
var knockout = require('terriajs-cesium/Source/ThirdParty/knockout');

/**
* Selects a base map by name from a list of base map options. The name is specified by `terria.baseMapName`, or,
* if that property is undefined, by the specified `defaultBaseMapName`. In addition to setting `terria.baseMap`,
* this function subscribes to be notified when `terria.baseMapName` changes and updates `terria.baseMap`
* accordingly. If a base map with the name is not in the `baseMaps` list, this method leaves the
* `terria.baseMap` property unmodified.
*
* @param {Terria} terria The TerriaJS application.
* @param {BaseMapViewModel[]} baseMaps The list of possible base maps.
* @param {string} defaultBaseMapName The name of the base map to search for.
* @param {boolean} useStoredPreference If true, look for and use a localStorage preference instead.
* @returns {BaseMapViewModel} The matching base map, or undefined if not found.
*/
var selectBaseMap = function(terria, baseMaps, defaultBaseMapName, useStoredPreference) {
function updateBaseMap(baseMapName) {
if (!defined(baseMapName)) {
return undefined;
}

for (var i = 0; i < baseMaps.length; ++i) {
if (baseMaps[i].catalogItem.name === baseMapName) {
terria.baseMap = baseMaps[i].catalogItem;
terria.baseMapContrastColor = baseMaps[i].contrastColor;
return terria.baseMap;
}
}
return undefined;
}

knockout.getObservable(terria, 'baseMapName').subscribe(function() {
updateBaseMap(terria.baseMapName);
});

if (baseMaps.length === 0) {
return undefined;
}

var baseMap;
if (useStoredPreference) {
baseMap = updateBaseMap(terria.getLocalProperty('basemap'));
}
baseMap = baseMap || updateBaseMap(terria.baseMapName) || updateBaseMap(defaultBaseMapName) || updateBaseMap(baseMaps[0].catalogItem.name);
return baseMap;

};

module.exports = selectBaseMap;

0 comments on commit d54f6fd

Please sign in to comment.