GUI -- Sketched out MapService.
- implemented ID to URL adjustment, and object caching behaviors.
Change-Id: I5a30b59be01761d9a6475f7707db947dd2304dc5
diff --git a/web/gui/src/main/webapp/app/fw/svg/map.js b/web/gui/src/main/webapp/app/fw/svg/map.js
index 0b3088d..c736149 100644
--- a/web/gui/src/main/webapp/app/fw/svg/map.js
+++ b/web/gui/src/main/webapp/app/fw/svg/map.js
@@ -19,17 +19,81 @@
@author Simon Hunt
*/
+
+/*
+ The Map Service caches GeoJSON maps, which can be loaded into the map
+ layer of the Topology View.
+
+ A GeoMap object can be fetched by ID. IDs that start with an asterisk
+ identify maps bundled with the GUI. IDs that do not start with an
+ asterisk are assumed to be URLs to externally provided data (exact
+ format to be decided).
+
+ e.g. var geomap = MapService.fetchGeoMap('*continental-us');
+
+ The GeoMap object encapsulates topology data (features), and the
+ D3 projection object.
+
+ Note that, since the GeoMap instance is cached / shared, it should
+ contain no state.
+ */
+
(function () {
'use strict';
- var $log;
+ // injected references
+ var $log, fs;
+
+ // internal state
+ var maps = d3.map(),
+ msgMs = 'MapService.',
+ bundledUrlPrefix = 'data/map/';
+
+ function getUrl(id) {
+ if (id[0] === '*') {
+ return bundledUrlPrefix + id.slice(1) + '.json';
+ }
+ return id + '.json';
+ }
angular.module('onosSvg')
- .factory('MapService', ['$log', function (_$log_) {
+ .factory('MapService', ['$log', 'FnService',
+
+ function (_$log_, _fs_) {
$log = _$log_;
+ fs = _fs_;
+
+ function clearCache() {
+ maps = d3.map();
+ }
+
+ function fetchGeoMap(id) {
+ if (!fs.isS(id)) {
+ return null;
+ }
+
+ var geomap = maps.get(id);
+
+ if (!geomap) {
+ // need to fetch the data and build the object...
+ geomap = {
+ id: id,
+ url: getUrl(id),
+ wasCached: false
+ };
+ // TODO: use $http service to load map data asynchronously
+
+ maps.set(id, geomap);
+ } else {
+ geomap.wasCached = true;
+ }
+
+ return geomap;
+ }
return {
- tbd: function () {}
+ clearCache: clearCache,
+ fetchGeoMap: fetchGeoMap
};
}]);