Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 1 | /* |
| 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 Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 25 | // Injected Services |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 26 | var $log, $loc, ps, ms, flash, sus, countryFilters; |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 27 | |
| 28 | // Injected Classes |
| 29 | var MapSelectionDialog; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 30 | |
| 31 | // internal state |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 32 | var instance, mapG, zoomLayer, zoomer; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 33 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 34 | function init(_zoomLayer_, _zoomer_) { |
| 35 | zoomLayer = _zoomLayer_; |
| 36 | zoomer = _zoomer_; |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 37 | // 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 Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 42 | // TODO: to be re-worked: map-id, filePath, scale/pan to be passed as params |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 43 | function setUpMap() { |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 44 | var prefs = currentMap(), |
| 45 | mapId = prefs.mapid, |
| 46 | mapFilePath = prefs.mapfilepath, |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 47 | mapScale = prefs.mapscale || 1, |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 48 | loadMap = ms.loadMapInto, |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 49 | promise, cfilter; |
| 50 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 51 | mapG = d3.select('#topo2-map'); |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 52 | |
| 53 | if (mapG.empty()) { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 54 | mapG = zoomLayer.append('g').attr('id', 'topo2-map'); |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 55 | } else { |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 56 | mapG.each(function () { |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 57 | d3.selectAll(this.childNodes).remove(); |
| 58 | }); |
| 59 | } |
| 60 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 61 | if (!ps.getPrefs('topo2_prefs')[this.prefs.visible]) { |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 62 | this.hide(); |
| 63 | } |
| 64 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 65 | if (mapFilePath === '*countries') { |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 66 | cfilter = countryFilters[mapId] || countryFilters.uk; |
Steven Burrows | e7cc308 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 67 | loadMap = ms.loadMapRegionInto; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 70 | promise = loadMap(mapG, mapFilePath, mapId, { |
| 71 | countryFilters: cfilter, |
| 72 | adjustScale: mapScale, |
| 73 | shading: '' |
| 74 | }); |
| 75 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 76 | return promise; |
| 77 | } |
| 78 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 79 | // TODO: deprecated - the layout will tell us which map |
| 80 | // no longer stored in user preferences |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 81 | function currentMap() { |
| 82 | return ps.getPrefs( |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 83 | 'topo2_mapid', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 84 | { |
| 85 | mapid: 'usa', |
| 86 | mapscale: 1, |
| 87 | mapfilepath: '*continental_us', |
| 88 | tint: 'off' |
| 89 | }, |
| 90 | $loc.search() |
| 91 | ); |
| 92 | } |
| 93 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 94 | // TODO: deprecated - maps are defined per layout on the server side. |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 95 | function setMap(map) { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 96 | ps.setPrefs('topo2_mapid', map); |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 97 | return setUpMap.bind(this)(); |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 100 | // TODO: deprecated - map selection does not make sense in Topo2 |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 101 | function openMapSelection() { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 102 | $log.warn('openMapSelection DISABLED'); |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 103 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 104 | // MapSelectionDialog.prototype.currentMap = currentMap; |
| 105 | // |
| 106 | // new MapSelectionDialog({ |
| 107 | // okHandler: function (preferences) { |
| 108 | // setMap(preferences); |
| 109 | // } |
| 110 | // }).open(); |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 113 | function resetZoom() { |
| 114 | zoomer.reset(); |
| 115 | } |
| 116 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 117 | angular.module('ovTopo2') |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 118 | .factory('Topo2MapService', [ |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 119 | '$log', '$location', 'Topo2ViewController', 'PrefsService', |
| 120 | 'MapService', 'FlashService', 'SvgUtilService', 'Topo2CountryFilters', |
| 121 | 'Topo2MapDialog', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 122 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 123 | function (_$log_, _$loc_, ViewController, _ps_, |
| 124 | _ms_, _flash_, _sus_, _t2cf_, |
| 125 | _t2md_) { |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 126 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 127 | $log = _$log_; |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 128 | $loc = _$loc_; |
| 129 | ps = _ps_; |
| 130 | ms = _ms_; |
| 131 | flash = _flash_; |
| 132 | sus = _sus_; |
| 133 | countryFilters = _t2cf_; |
| 134 | MapSelectionDialog = _t2md_; |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 135 | |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 136 | var MapLayer = ViewController.extend({ |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 137 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 138 | id: 'topo2-map', |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 139 | displayName: 'Map', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 140 | |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 141 | init: init, |
| 142 | setMap: setMap, |
| 143 | openMapSelection: openMapSelection, |
| 144 | resetZoom: resetZoom |
| 145 | }); |
| 146 | |
| 147 | return instance || new MapLayer(); |
| 148 | } |
| 149 | ]); |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 150 | })(); |