blob: aa9766edd42fd979d45a905b389e6ddcc9325957 [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
Steven Burrowsc7146612016-12-27 13:50:03 +000026 var $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_;
Steven Burrowsea1d1ec2017-02-23 15:39:25 +000037 return setUpMap.bind(this)();
Steven Burrowse3a18842016-09-22 15:33:33 +010038 }
39
Steven Burrows1c5c8612016-10-05 13:45:13 -050040 function setUpMap() {
Steven Burrowse3a18842016-09-22 15:33:33 +010041 var prefs = currentMap(),
42 mapId = prefs.mapid,
43 mapFilePath = prefs.mapfilepath,
Steven Burrows86b74fc2017-02-22 00:15:16 +000044 mapScale = prefs.mapscale || 1,
Steven Burrowsd576f642016-09-26 10:40:51 -070045 loadMap = ms.loadMapInto,
Steven Burrowse3a18842016-09-22 15:33:33 +010046 promise, cfilter;
47
48 mapG = d3.select('#topo-map');
49
50 if (mapG.empty()) {
51 mapG = zoomLayer.append('g').attr('id', 'topo-map');
52 } else {
Steven Burrowsea1d1ec2017-02-23 15:39:25 +000053 mapG.each(function () {
Steven Burrowse3a18842016-09-22 15:33:33 +010054 d3.selectAll(this.childNodes).remove();
55 });
56 }
57
Steven Burrowsea1d1ec2017-02-23 15:39:25 +000058 if (!ps.getPrefs('topo_prefs')[this.prefs.visible]) {
59 this.hide();
60 }
61
Steven Burrowse3a18842016-09-22 15:33:33 +010062 if (mapFilePath === '*countries') {
Steven Burrowse3a18842016-09-22 15:33:33 +010063 cfilter = countryFilters[mapId] || countryFilters.uk;
Steven Burrowse7cc3082016-09-27 11:24:58 -070064 loadMap = ms.loadMapRegionInto;
Steven Burrowse3a18842016-09-22 15:33:33 +010065 }
66
Steven Burrowsd576f642016-09-26 10:40:51 -070067 promise = loadMap(mapG, mapFilePath, mapId, {
68 countryFilters: cfilter,
69 adjustScale: mapScale,
70 shading: ''
71 });
72
Steven Burrowse3a18842016-09-22 15:33:33 +010073 return promise;
74 }
75
Steven Burrowse3a18842016-09-22 15:33:33 +010076 function currentMap() {
77 return ps.getPrefs(
78 'topo_mapid',
79 {
80 mapid: 'usa',
81 mapscale: 1,
82 mapfilepath: '*continental_us',
83 tint: 'off'
84 },
85 $loc.search()
86 );
87 }
88
Steven Burrowse3a18842016-09-22 15:33:33 +010089 function setMap(map) {
90 ps.setPrefs('topo_mapid', map);
Steven Burrowsea1d1ec2017-02-23 15:39:25 +000091 return setUpMap.bind(this)();
Steven Burrowse3a18842016-09-22 15:33:33 +010092 }
93
Steven Burrowsd576f642016-09-26 10:40:51 -070094 function openMapSelection() {
95
Steven Burrowsd576f642016-09-26 10:40:51 -070096 MapSelectionDialog.prototype.currentMap = currentMap;
97
98 new MapSelectionDialog({
99 okHandler: function (preferences) {
100 setMap(preferences);
101 }
102 }).open();
103 }
104
Steven Burrows1c5c8612016-10-05 13:45:13 -0500105 function resetZoom() {
106 zoomer.reset();
107 }
108
Steven Burrowse3a18842016-09-22 15:33:33 +0100109 angular.module('ovTopo2')
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000110 .factory('Topo2MapService', [
111 '$location', 'Topo2ViewController', 'PrefsService', 'MapService', 'FlashService',
112 'SvgUtilService', 'Topo2CountryFilters', 'Topo2MapDialog',
Steven Burrowse3a18842016-09-22 15:33:33 +0100113
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000114 function (_$loc_, ViewController, _ps_, _ms_, _flash_, _sus_, _t2cf_, _t2md_) {
Steven Burrowse3a18842016-09-22 15:33:33 +0100115
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000116 $loc = _$loc_;
117 ps = _ps_;
118 ms = _ms_;
119 flash = _flash_;
120 sus = _sus_;
121 countryFilters = _t2cf_;
122 MapSelectionDialog = _t2md_;
Steven Burrows86b74fc2017-02-22 00:15:16 +0000123
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000124 var MapLayer = ViewController.extend({
Steven Burrows1c5c8612016-10-05 13:45:13 -0500125
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000126 id: 'topo-map',
127 displayName: 'Map',
Steven Burrowse3a18842016-09-22 15:33:33 +0100128
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000129 init: init,
130 setMap: setMap,
131 openMapSelection: openMapSelection,
132 resetZoom: resetZoom
133 });
134
135 return instance || new MapLayer();
136 }
137 ]);
Steven Burrowse3a18842016-09-22 15:33:33 +0100138})();