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