blob: f44ffe08a34c90cf7b2ff958ac2df348761266e4 [file] [log] [blame]
Simon Hunt7ac7be92015-01-06 10:47:56 -08001/*
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 Hunt7ac7be92015-01-06 10:47:56 -080019 */
Simon Huntf044d8a2015-01-07 17:53:04 -080020
21/*
Simon Huntf8173382015-01-13 14:12:09 -080022 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 Huntf044d8a2015-01-07 17:53:04 -080024
Simon Huntf8173382015-01-13 14:12:09 -080025 e.g. var ok = MapService.loadMapInto(svgLayer, '*continental-us');
Simon Huntf044d8a2015-01-07 17:53:04 -080026
Simon Huntf8173382015-01-13 14:12:09 -080027 The Map Service makes use of the GeoDataService to load the required data
Simon Hunta7b6a6b2015-01-13 19:53:09 -080028 from the server and to create the appropriate geographical projection.
29
Simon Huntf8173382015-01-13 14:12:09 -080030*/
Simon Huntf044d8a2015-01-07 17:53:04 -080031
Simon Hunt7ac7be92015-01-06 10:47:56 -080032(function () {
33 'use strict';
34
Simon Huntf044d8a2015-01-07 17:53:04 -080035 // injected references
Simon Hunta7b6a6b2015-01-13 19:53:09 -080036 var $log, fs, gds;
Simon Hunt7ac7be92015-01-06 10:47:56 -080037
38 angular.module('onosSvg')
Simon Hunta7b6a6b2015-01-13 19:53:09 -080039 .factory('MapService', ['$log', 'FnService', 'GeoDataService',
40 function (_$log_, _fs_, _gds_) {
Simon Hunt7ac7be92015-01-06 10:47:56 -080041 $log = _$log_;
Simon Huntf044d8a2015-01-07 17:53:04 -080042 fs = _fs_;
Simon Hunta7b6a6b2015-01-13 19:53:09 -080043 gds = _gds_;
Simon Hunt404e54c2015-01-09 11:58:49 -080044
Simon Hunt426bd862015-01-14 16:48:41 -080045 function loadMapInto(mapLayer, id, opts) {
Simon Hunta7b6a6b2015-01-13 19:53:09 -080046 var promise = gds.fetchTopoData(id);
47 if (!promise) {
Simon Hunt404e54c2015-01-09 11:58:49 -080048 $log.warn('Failed to load map: ' + id);
Simon Hunta7b6a6b2015-01-13 19:53:09 -080049 return false;
Simon Hunt404e54c2015-01-09 11:58:49 -080050 }
51
Simon Hunta7b6a6b2015-01-13 19:53:09 -080052 promise.then(function () {
Simon Hunt426bd862015-01-14 16:48:41 -080053 var gen = gds.createPathGenerator(promise.topodata, opts);
Simon Hunt404e54c2015-01-09 11:58:49 -080054
55 mapLayer.selectAll('path')
Simon Hunta7b6a6b2015-01-13 19:53:09 -080056 .data(gen.geodata.features)
Simon Hunt404e54c2015-01-09 11:58:49 -080057 .enter()
58 .append('path')
Simon Hunta7b6a6b2015-01-13 19:53:09 -080059 .attr('d', gen.pathgen);
Simon Hunt404e54c2015-01-09 11:58:49 -080060 });
Simon Hunta7b6a6b2015-01-13 19:53:09 -080061 return true;
Simon Hunt404e54c2015-01-09 11:58:49 -080062 }
63
Simon Hunt7ac7be92015-01-06 10:47:56 -080064 return {
Simon Hunt404e54c2015-01-09 11:58:49 -080065 loadMapInto: loadMapInto
Simon Hunt7ac7be92015-01-06 10:47:56 -080066 };
67 }]);
68
69}());