blob: 69716d850b6354eadc36c362c39cfa442a2cdf96 [file] [log] [blame]
Steven Burrowse3a18842016-09-22 15:33:33 +01001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 ONOS GUI -- Topology Map Module.
19 Defines behavior for loading geographical maps into the map layer.
20 */
21
22(function () {
23 'use strict';
24
Steven Burrowsd576f642016-09-26 10:40:51 -070025 // Injected Services
Simon Hunt95f4b422017-03-03 13:49:05 -080026 var $log, $loc, ps, ms, flash, sus, countryFilters;
Steven Burrowsd576f642016-09-26 10:40:51 -070027
28 // Injected Classes
29 var MapSelectionDialog;
Steven Burrowse3a18842016-09-22 15:33:33 +010030
31 // internal state
Steven Burrowsea1d1ec2017-02-23 15:39:25 +000032 var instance, mapG, zoomLayer, zoomer;
Steven Burrowse3a18842016-09-22 15:33:33 +010033
Steven Burrows1c5c8612016-10-05 13:45:13 -050034 function init(_zoomLayer_, _zoomer_) {
35 zoomLayer = _zoomLayer_;
36 zoomer = _zoomer_;
Simon Hunt95f4b422017-03-03 13:49:05 -080037 // This function no longer returns a promise.
38 // TODO: call setUpMap() when we know which map we want (not from here)
39 // return setUpMap.bind(this)();
Steven Burrowse3a18842016-09-22 15:33:33 +010040 }
41
Simon Hunt95f4b422017-03-03 13:49:05 -080042 // TODO: to be re-worked: map-id, filePath, scale/pan to be passed as params
Steven Burrows1c5c8612016-10-05 13:45:13 -050043 function setUpMap() {
Steven Burrowse3a18842016-09-22 15:33:33 +010044 var prefs = currentMap(),
45 mapId = prefs.mapid,
46 mapFilePath = prefs.mapfilepath,
Steven Burrows86b74fc2017-02-22 00:15:16 +000047 mapScale = prefs.mapscale || 1,
Steven Burrowsd576f642016-09-26 10:40:51 -070048 loadMap = ms.loadMapInto,
Steven Burrowse3a18842016-09-22 15:33:33 +010049 promise, cfilter;
50
Simon Hunt95f4b422017-03-03 13:49:05 -080051 mapG = d3.select('#topo2-map');
Steven Burrowse3a18842016-09-22 15:33:33 +010052
53 if (mapG.empty()) {
Simon Hunt95f4b422017-03-03 13:49:05 -080054 mapG = zoomLayer.append('g').attr('id', 'topo2-map');
Steven Burrowse3a18842016-09-22 15:33:33 +010055 } else {
Steven Burrowsea1d1ec2017-02-23 15:39:25 +000056 mapG.each(function () {
Steven Burrowse3a18842016-09-22 15:33:33 +010057 d3.selectAll(this.childNodes).remove();
58 });
59 }
60
Simon Hunt95f4b422017-03-03 13:49:05 -080061 if (!ps.getPrefs('topo2_prefs')[this.prefs.visible]) {
Steven Burrowsea1d1ec2017-02-23 15:39:25 +000062 this.hide();
63 }
64
Steven Burrowse3a18842016-09-22 15:33:33 +010065 if (mapFilePath === '*countries') {
Steven Burrowse3a18842016-09-22 15:33:33 +010066 cfilter = countryFilters[mapId] || countryFilters.uk;
Steven Burrowse7cc3082016-09-27 11:24:58 -070067 loadMap = ms.loadMapRegionInto;
Steven Burrowse3a18842016-09-22 15:33:33 +010068 }
69
Steven Burrowsd576f642016-09-26 10:40:51 -070070 promise = loadMap(mapG, mapFilePath, mapId, {
71 countryFilters: cfilter,
72 adjustScale: mapScale,
73 shading: ''
74 });
75
Steven Burrowse3a18842016-09-22 15:33:33 +010076 return promise;
77 }
78
Simon Hunt95f4b422017-03-03 13:49:05 -080079 // TODO: deprecated - the layout will tell us which map
80 // no longer stored in user preferences
Steven Burrowse3a18842016-09-22 15:33:33 +010081 function currentMap() {
82 return ps.getPrefs(
Simon Hunt95f4b422017-03-03 13:49:05 -080083 'topo2_mapid',
Steven Burrowse3a18842016-09-22 15:33:33 +010084 {
85 mapid: 'usa',
86 mapscale: 1,
87 mapfilepath: '*continental_us',
88 tint: 'off'
89 },
90 $loc.search()
91 );
92 }
93
Simon Hunt95f4b422017-03-03 13:49:05 -080094 // TODO: deprecated - maps are defined per layout on the server side.
Steven Burrowse3a18842016-09-22 15:33:33 +010095 function setMap(map) {
Simon Hunt95f4b422017-03-03 13:49:05 -080096 ps.setPrefs('topo2_mapid', map);
Steven Burrowsea1d1ec2017-02-23 15:39:25 +000097 return setUpMap.bind(this)();
Steven Burrowse3a18842016-09-22 15:33:33 +010098 }
99
Simon Hunt95f4b422017-03-03 13:49:05 -0800100 // TODO: deprecated - map selection does not make sense in Topo2
Steven Burrowsd576f642016-09-26 10:40:51 -0700101 function openMapSelection() {
Simon Hunt95f4b422017-03-03 13:49:05 -0800102 $log.warn('openMapSelection DISABLED');
Steven Burrowsd576f642016-09-26 10:40:51 -0700103
Simon Hunt95f4b422017-03-03 13:49:05 -0800104 // MapSelectionDialog.prototype.currentMap = currentMap;
105 //
106 // new MapSelectionDialog({
107 // okHandler: function (preferences) {
108 // setMap(preferences);
109 // }
110 // }).open();
Steven Burrowsd576f642016-09-26 10:40:51 -0700111 }
112
Steven Burrows1c5c8612016-10-05 13:45:13 -0500113 function resetZoom() {
114 zoomer.reset();
115 }
116
Steven Burrowse3a18842016-09-22 15:33:33 +0100117 angular.module('ovTopo2')
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000118 .factory('Topo2MapService', [
Simon Hunt95f4b422017-03-03 13:49:05 -0800119 '$log', '$location', 'Topo2ViewController', 'PrefsService',
120 'MapService', 'FlashService', 'SvgUtilService', 'Topo2CountryFilters',
121 'Topo2MapDialog',
Steven Burrowse3a18842016-09-22 15:33:33 +0100122
Simon Hunt95f4b422017-03-03 13:49:05 -0800123 function (_$log_, _$loc_, ViewController, _ps_,
124 _ms_, _flash_, _sus_, _t2cf_,
125 _t2md_) {
Steven Burrowse3a18842016-09-22 15:33:33 +0100126
Simon Hunt95f4b422017-03-03 13:49:05 -0800127 $log = _$log_;
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000128 $loc = _$loc_;
129 ps = _ps_;
130 ms = _ms_;
131 flash = _flash_;
132 sus = _sus_;
133 countryFilters = _t2cf_;
134 MapSelectionDialog = _t2md_;
Steven Burrows86b74fc2017-02-22 00:15:16 +0000135
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000136 var MapLayer = ViewController.extend({
Steven Burrows1c5c8612016-10-05 13:45:13 -0500137
Simon Hunt95f4b422017-03-03 13:49:05 -0800138 id: 'topo2-map',
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000139 displayName: 'Map',
Steven Burrowse3a18842016-09-22 15:33:33 +0100140
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000141 init: init,
142 setMap: setMap,
143 openMapSelection: openMapSelection,
144 resetZoom: resetZoom
145 });
146
147 return instance || new MapLayer();
148 }
149 ]);
Steven Burrowse3a18842016-09-22 15:33:33 +0100150})();