forked from TerriaJS/TerriaMap
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05d716b
commit d54f6fd
Showing
2 changed files
with
79 additions
and
0 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
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; |
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,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; |