blob: 366204c90fa1bee009397c0424f87fe6f6d75589 [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
19
20 @author Simon Hunt
21 */
Simon Huntf044d8a2015-01-07 17:53:04 -080022
23/*
Simon Huntf8173382015-01-13 14:12:09 -080024 The Map Service provides a simple API for loading geographical maps into
25 an SVG layer. For example, as a background to the Topology View.
Simon Huntf044d8a2015-01-07 17:53:04 -080026
Simon Huntf8173382015-01-13 14:12:09 -080027 e.g. var ok = MapService.loadMapInto(svgLayer, '*continental-us');
Simon Huntf044d8a2015-01-07 17:53:04 -080028
Simon Huntf8173382015-01-13 14:12:09 -080029 The Map Service makes use of the GeoDataService to load the required data
Simon Hunta7b6a6b2015-01-13 19:53:09 -080030 from the server and to create the appropriate geographical projection.
31
Simon Huntf8173382015-01-13 14:12:09 -080032*/
Simon Huntf044d8a2015-01-07 17:53:04 -080033
Simon Hunt7ac7be92015-01-06 10:47:56 -080034(function () {
35 'use strict';
36
Simon Huntf044d8a2015-01-07 17:53:04 -080037 // injected references
Simon Hunta7b6a6b2015-01-13 19:53:09 -080038 var $log, fs, gds;
Simon Hunt7ac7be92015-01-06 10:47:56 -080039
40 angular.module('onosSvg')
Simon Hunta7b6a6b2015-01-13 19:53:09 -080041 .factory('MapService', ['$log', 'FnService', 'GeoDataService',
42 function (_$log_, _fs_, _gds_) {
Simon Hunt7ac7be92015-01-06 10:47:56 -080043 $log = _$log_;
Simon Huntf044d8a2015-01-07 17:53:04 -080044 fs = _fs_;
Simon Hunta7b6a6b2015-01-13 19:53:09 -080045 gds = _gds_;
Simon Hunt404e54c2015-01-09 11:58:49 -080046
47 function loadMapInto(mapLayer, id) {
Simon Hunta7b6a6b2015-01-13 19:53:09 -080048 var promise = gds.fetchTopoData(id);
49 if (!promise) {
Simon Hunt404e54c2015-01-09 11:58:49 -080050 $log.warn('Failed to load map: ' + id);
Simon Hunta7b6a6b2015-01-13 19:53:09 -080051 return false;
Simon Hunt404e54c2015-01-09 11:58:49 -080052 }
53
Simon Hunta7b6a6b2015-01-13 19:53:09 -080054 promise.then(function () {
55 var gen = gds.createPathGenerator(promise.topodata);
Simon Hunt404e54c2015-01-09 11:58:49 -080056
57 mapLayer.selectAll('path')
Simon Hunta7b6a6b2015-01-13 19:53:09 -080058 .data(gen.geodata.features)
Simon Hunt404e54c2015-01-09 11:58:49 -080059 .enter()
60 .append('path')
Simon Hunta7b6a6b2015-01-13 19:53:09 -080061 .attr('d', gen.pathgen);
Simon Hunt404e54c2015-01-09 11:58:49 -080062 });
Simon Hunta7b6a6b2015-01-13 19:53:09 -080063 return true;
Simon Hunt404e54c2015-01-09 11:58:49 -080064 }
65
Simon Hunt7ac7be92015-01-06 10:47:56 -080066 return {
Simon Hunt404e54c2015-01-09 11:58:49 -080067 loadMapInto: loadMapInto
Simon Hunt7ac7be92015-01-06 10:47:56 -080068 };
69 }]);
70
71}());