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 | 5c3ed73 | 2017-07-20 19:03: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 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 28 | // internal state |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 29 | var instance, mapG, zoomLayer, zoomer, currentMap; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 30 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 31 | function init() { |
| 32 | this.appendElement('#topo2-background', 'g'); |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 33 | zoomLayer = d3.select('#topo2-zoomlayer'); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 34 | zoomer = t2zs.getZoomer(); |
Steven Burrows | 9053fdb | 2017-04-12 12:08:16 -0700 | [diff] [blame] | 35 | currentMap = null; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 38 | function setUpMap(mapId, mapFilePath, mapScale) { |
| 39 | |
Steven Burrows | 091a1b1 | 2017-04-10 09:52:35 -0700 | [diff] [blame] | 40 | if (currentMap === mapId) { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 41 | return new Promise(function(resolve) { |
Steven Burrows | 091a1b1 | 2017-04-10 09:52:35 -0700 | [diff] [blame] | 42 | resolve(); |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | currentMap = mapId; |
| 47 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 48 | var loadMap = ms.loadMapInto, |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 49 | promise, cfilter; |
| 50 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 51 | this.node().selectAll("*").remove(); |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 52 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 53 | if (mapFilePath === '*countries') { |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 54 | cfilter = countryFilters[mapId] || countryFilters.uk; |
Steven Burrows | e7cc308 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 55 | loadMap = ms.loadMapRegionInto; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 58 | promise = loadMap(this.node(), mapFilePath, mapId, { |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 59 | countryFilters: cfilter, |
Steven Burrows | 7d1efef | 2017-03-25 02:07:43 +0000 | [diff] [blame] | 60 | adjustScale: mapScale || 1, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 61 | shading: '' |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 62 | }); |
| 63 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 64 | return promise; |
| 65 | } |
| 66 | |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 67 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 68 | function resetZoom() { |
| 69 | zoomer.reset(); |
| 70 | } |
| 71 | |
Simon Hunt | c43a59d | 2017-04-05 13:56:13 -0700 | [diff] [blame] | 72 | function zoomCallback(sc, tr) { |
| 73 | // keep the map lines constant width while zooming |
| 74 | this.node().style('stroke-width', (2.0 / sc) + 'px'); |
| 75 | } |
| 76 | |
Steven Burrows | 091a1b1 | 2017-04-10 09:52:35 -0700 | [diff] [blame] | 77 | function getCurrentMap() { |
| 78 | return currentMap; |
| 79 | } |
| 80 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 81 | angular.module('ovTopo2') |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 82 | .factory('Topo2MapService', [ |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 83 | '$log', '$location', 'Topo2ViewController', 'PrefsService', |
| 84 | 'MapService', 'FlashService', 'SvgUtilService', 'Topo2ZoomService', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 85 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 86 | function (_$log_, _$loc_, ViewController, _ps_, |
| 87 | _ms_, _flash_, _sus_, _t2zs_) { |
| 88 | |
| 89 | $log = _$log_; |
| 90 | $loc = _$loc_; |
| 91 | ps = _ps_; |
Steven Burrows | 46c5f10 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 92 | ms = _ms_; |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 93 | flash = _flash_; |
| 94 | sus = _sus_; |
| 95 | t2zs = _t2zs_; |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 96 | |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 97 | var MapLayer = ViewController.extend({ |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 98 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 99 | id: 'topo2-map', |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 100 | displayName: 'Map', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 101 | |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 102 | init: init, |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 103 | setUpMap: setUpMap, |
Simon Hunt | c43a59d | 2017-04-05 13:56:13 -0700 | [diff] [blame] | 104 | resetZoom: resetZoom, |
Steven Burrows | 091a1b1 | 2017-04-10 09:52:35 -0700 | [diff] [blame] | 105 | zoomCallback: zoomCallback, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 106 | getCurrentMap: getCurrentMap |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 107 | }); |
| 108 | |
| 109 | return instance || new MapLayer(); |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 110 | } |
Steven Burrows | ea1d1ec | 2017-02-23 15:39:25 +0000 | [diff] [blame] | 111 | ]); |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 112 | })(); |