blob: 1faf6e2de1a4690b7f20751a338ba991b6d41193 [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 Huntac4c6f72015-02-03 19:50:53 -080025 e.g. var promise = 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 Huntac4c6f72015-02-03 19:50:53 -080030 A promise is returned to the caller, which is resolved with the
31 map projection once created.
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 Huntac4c6f72015-02-03 19:50:53 -080038 var $log, $q, fs, gds;
39
40 function loadMapInto(mapLayer, id, opts) {
41 var promise = gds.fetchTopoData(id),
42 deferredProjection = $q.defer();
43
44 if (!promise) {
45 $log.warn('Failed to load map: ' + id);
46 return false;
47 }
48
49 promise.then(function () {
50 var gen = gds.createPathGenerator(promise.topodata, opts);
51
52 deferredProjection.resolve(gen.settings.projection);
53
54 mapLayer.selectAll('path')
55 .data(gen.geodata.features)
56 .enter()
57 .append('path')
58 .attr('d', gen.pathgen);
59 });
60 return deferredProjection.promise;
61 }
62
Simon Hunt7ac7be92015-01-06 10:47:56 -080063
64 angular.module('onosSvg')
Simon Huntac4c6f72015-02-03 19:50:53 -080065 .factory('MapService', ['$log', '$q', 'FnService', 'GeoDataService',
66 function (_$log_, _$q_, _fs_, _gds_) {
Simon Hunt7ac7be92015-01-06 10:47:56 -080067 $log = _$log_;
Simon Huntac4c6f72015-02-03 19:50:53 -080068 $q = _$q_;
Simon Huntf044d8a2015-01-07 17:53:04 -080069 fs = _fs_;
Simon Hunta7b6a6b2015-01-13 19:53:09 -080070 gds = _gds_;
Simon Hunt404e54c2015-01-09 11:58:49 -080071
Simon Hunt7ac7be92015-01-06 10:47:56 -080072 return {
Simon Hunt404e54c2015-01-09 11:58:49 -080073 loadMapInto: loadMapInto
Simon Hunt7ac7be92015-01-06 10:47:56 -080074 };
75 }]);
76
77}());