Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 -- SVG -- Map Service |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 19 | */ |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 20 | |
| 21 | /* |
Simon Hunt | f817338 | 2015-01-13 14:12:09 -0800 | [diff] [blame] | 22 | The Map Service provides a simple API for loading geographical maps into |
| 23 | an SVG layer. For example, as a background to the Topology View. |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 24 | |
Simon Hunt | f817338 | 2015-01-13 14:12:09 -0800 | [diff] [blame] | 25 | e.g. var ok = MapService.loadMapInto(svgLayer, '*continental-us'); |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 26 | |
Simon Hunt | f817338 | 2015-01-13 14:12:09 -0800 | [diff] [blame] | 27 | The Map Service makes use of the GeoDataService to load the required data |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 28 | from the server and to create the appropriate geographical projection. |
| 29 | |
Simon Hunt | f817338 | 2015-01-13 14:12:09 -0800 | [diff] [blame] | 30 | */ |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 31 | |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 32 | (function () { |
| 33 | 'use strict'; |
| 34 | |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 35 | // injected references |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 36 | var $log, fs, gds; |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 37 | |
| 38 | angular.module('onosSvg') |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 39 | .factory('MapService', ['$log', 'FnService', 'GeoDataService', |
| 40 | function (_$log_, _fs_, _gds_) { |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 41 | $log = _$log_; |
Simon Hunt | f044d8a | 2015-01-07 17:53:04 -0800 | [diff] [blame] | 42 | fs = _fs_; |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 43 | gds = _gds_; |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 44 | |
Simon Hunt | 426bd86 | 2015-01-14 16:48:41 -0800 | [diff] [blame] | 45 | function loadMapInto(mapLayer, id, opts) { |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 46 | var promise = gds.fetchTopoData(id); |
| 47 | if (!promise) { |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 48 | $log.warn('Failed to load map: ' + id); |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 49 | return false; |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 50 | } |
| 51 | |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 52 | promise.then(function () { |
Simon Hunt | 426bd86 | 2015-01-14 16:48:41 -0800 | [diff] [blame] | 53 | var gen = gds.createPathGenerator(promise.topodata, opts); |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 54 | |
| 55 | mapLayer.selectAll('path') |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 56 | .data(gen.geodata.features) |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 57 | .enter() |
| 58 | .append('path') |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 59 | .attr('d', gen.pathgen); |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 60 | }); |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 61 | return true; |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 64 | return { |
Simon Hunt | 404e54c | 2015-01-09 11:58:49 -0800 | [diff] [blame] | 65 | loadMapInto: loadMapInto |
Simon Hunt | 7ac7be9 | 2015-01-06 10:47:56 -0800 | [diff] [blame] | 66 | }; |
| 67 | }]); |
| 68 | |
| 69 | }()); |