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 |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 26 | var $log, $loc, ps, ms, flash, sus, t2zs, 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 | 091a1b1 | 2017-04-10 09:52:35 -0700 | [diff] [blame] | 32 | var instance, mapG, zoomLayer, zoomer, currentMap; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 33 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 34 | function init() { |
| 35 | this.appendElement('#topo2-background', 'g'); |
| 36 | zoomLayer = d3.select('#topo2-zoomlayer'); |
| 37 | zoomer = t2zs.getZoomer(); |
Steven Burrows | 9053fdb | 2017-04-12 12:08:16 -0700 | [diff] [blame] | 38 | currentMap = null; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 41 | function setUpMap(mapId, mapFilePath, mapScale) { |
| 42 | |
Steven Burrows | 091a1b1 | 2017-04-10 09:52:35 -0700 | [diff] [blame] | 43 | if (currentMap === mapId) { |
| 44 | return new Promise(function(resolve) { |
| 45 | resolve(); |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | currentMap = mapId; |
| 50 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 51 | var loadMap = ms.loadMapInto, |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 52 | promise, cfilter; |
| 53 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 54 | this.node().selectAll("*").remove(); |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 55 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 56 | if (mapFilePath === '*countries') { |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 57 | cfilter = countryFilters[mapId] || countryFilters.uk; |
Steven Burrows | e7cc308 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 58 | loadMap = ms.loadMapRegionInto; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 61 | promise = loadMap(this.node(), mapFilePath, mapId, { |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 62 | countryFilters: cfilter, |
Steven Burrows | 7d1efef | 2017-03-25 02:07:43 +0000 | [diff] [blame] | 63 | adjustScale: mapScale || 1, |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 64 | shading: '' |
| 65 | }); |
| 66 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 67 | return promise; |
| 68 | } |
| 69 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 70 | // TODO: deprecated - maps are defined per layout on the server side. |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 71 | function setMap(map) { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 72 | ps.setPrefs('topo2_mapid', map); |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 73 | return setUpMap.bind(this)(); |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 76 | // TODO: deprecated - map selection does not make sense in Topo2 |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 77 | function openMapSelection() { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 78 | $log.warn('openMapSelection DISABLED'); |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 79 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 80 | // MapSelectionDialog.prototype.currentMap = currentMap; |
| 81 | // |
| 82 | // new MapSelectionDialog({ |
| 83 | // okHandler: function (preferences) { |
| 84 | // setMap(preferences); |
| 85 | // } |
| 86 | // }).open(); |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 89 | function resetZoom() { |
| 90 | zoomer.reset(); |
| 91 | } |
| 92 | |
Simon Hunt | c43a59d | 2017-04-05 13:56:13 -0700 | [diff] [blame] | 93 | function zoomCallback(sc, tr) { |
| 94 | // keep the map lines constant width while zooming |
| 95 | this.node().style('stroke-width', (2.0 / sc) + 'px'); |
| 96 | } |
| 97 | |
Steven Burrows | 091a1b1 | 2017-04-10 09:52:35 -0700 | [diff] [blame] | 98 | function getCurrentMap() { |
| 99 | return currentMap; |
| 100 | } |
| 101 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 102 | angular.module('ovTopo2') |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 103 | .factory('Topo2MapService', [ |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 104 | '$log', '$location', 'Topo2ViewController', 'PrefsService', |
| 105 | 'MapService', 'FlashService', 'SvgUtilService', 'Topo2CountryFilters', |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 106 | 'Topo2MapDialog', 'Topo2ZoomService', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 107 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 108 | function (_$log_, _$loc_, ViewController, _ps_, |
| 109 | _ms_, _flash_, _sus_, _t2cf_, |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 110 | _t2md_, _t2zs_) { |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 111 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 112 | $log = _$log_; |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 113 | $loc = _$loc_; |
| 114 | ps = _ps_; |
| 115 | ms = _ms_; |
| 116 | flash = _flash_; |
| 117 | sus = _sus_; |
| 118 | countryFilters = _t2cf_; |
| 119 | MapSelectionDialog = _t2md_; |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 120 | t2zs = _t2zs_; |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 121 | |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 122 | var MapLayer = ViewController.extend({ |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 123 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 124 | id: 'topo2-map', |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 125 | displayName: 'Map', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 126 | |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 127 | init: init, |
| 128 | setMap: setMap, |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 129 | setUpMap: setUpMap, |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 130 | openMapSelection: openMapSelection, |
Simon Hunt | c43a59d | 2017-04-05 13:56:13 -0700 | [diff] [blame] | 131 | resetZoom: resetZoom, |
Steven Burrows | 091a1b1 | 2017-04-10 09:52:35 -0700 | [diff] [blame] | 132 | zoomCallback: zoomCallback, |
| 133 | getCurrentMap: getCurrentMap |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 134 | }); |
| 135 | |
| 136 | return instance || new MapLayer(); |
| 137 | } |
| 138 | ]); |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 139 | })(); |