Committed by
Gerrit Code Review
GUI - topo view: enhancements to provide tinting of maps.
Change-Id: Ie369f4eee4c28e70ef86852cfbeea78fea8fae4f
Showing
2 changed files
with
89 additions
and
15 deletions
| ... | @@ -56,13 +56,13 @@ | ... | @@ -56,13 +56,13 @@ |
| 56 | 56 | ||
| 57 | deferredProjection.resolve(gen.settings.projection); | 57 | deferredProjection.resolve(gen.settings.projection); |
| 58 | 58 | ||
| 59 | - var path = mapLayer.selectAll('path') | 59 | + mapLayer.selectAll('path') |
| 60 | .data(gen.geodata.features) | 60 | .data(gen.geodata.features) |
| 61 | .enter() | 61 | .enter() |
| 62 | .append('path') | 62 | .append('path') |
| 63 | .attr('d', gen.pathgen); | 63 | .attr('d', gen.pathgen); |
| 64 | 64 | ||
| 65 | - opts.fill && path.style('fill', opts.fill); | 65 | + reshade(opts.shading); |
| 66 | }); | 66 | }); |
| 67 | return deferredProjection.promise; | 67 | return deferredProjection.promise; |
| 68 | } | 68 | } |
| ... | @@ -78,7 +78,7 @@ | ... | @@ -78,7 +78,7 @@ |
| 78 | // } | 78 | // } |
| 79 | // }); | 79 | // }); |
| 80 | 80 | ||
| 81 | - function loadMapRegionInto(mapLayer, filterOpts) { | 81 | + function loadMapRegionInto(mapLayer, opts) { |
| 82 | var promise = gds.fetchTopoData("*countries"), | 82 | var promise = gds.fetchTopoData("*countries"), |
| 83 | deferredProjection = $q.defer(); | 83 | deferredProjection = $q.defer(); |
| 84 | 84 | ||
| ... | @@ -94,14 +94,14 @@ | ... | @@ -94,14 +94,14 @@ |
| 94 | pathGen = d3.geo.path().projection(proj), | 94 | pathGen = d3.geo.path().projection(proj), |
| 95 | data = promise.topodata, | 95 | data = promise.topodata, |
| 96 | features = topojson.feature(data, data.objects.countries).features, | 96 | features = topojson.feature(data, data.objects.countries).features, |
| 97 | - country = features.filter(filterOpts.countryFilter), | 97 | + country = features.filter(opts.countryFilter), |
| 98 | countryFeature = { | 98 | countryFeature = { |
| 99 | type: 'FeatureCollection', | 99 | type: 'FeatureCollection', |
| 100 | features: country | 100 | features: country |
| 101 | }, | 101 | }, |
| 102 | path = d3.geo.path().projection(proj); | 102 | path = d3.geo.path().projection(proj); |
| 103 | 103 | ||
| 104 | - gds.rescaleProjection(proj, 0.95, 1000, path, countryFeature); | 104 | + gds.rescaleProjection(proj, 0.95, 1000, path, countryFeature, opts.adjustScale); |
| 105 | 105 | ||
| 106 | deferredProjection.resolve(proj); | 106 | deferredProjection.resolve(proj); |
| 107 | 107 | ||
| ... | @@ -110,10 +110,31 @@ | ... | @@ -110,10 +110,31 @@ |
| 110 | .enter() | 110 | .enter() |
| 111 | .append('path').classed('country', true) | 111 | .append('path').classed('country', true) |
| 112 | .attr('d', pathGen); | 112 | .attr('d', pathGen); |
| 113 | + | ||
| 114 | + reshade(opts.shading); | ||
| 113 | }); | 115 | }); |
| 114 | return deferredProjection.promise; | 116 | return deferredProjection.promise; |
| 115 | } | 117 | } |
| 116 | 118 | ||
| 119 | + function reshade(sh) { | ||
| 120 | + var p = sh && sh.palette, | ||
| 121 | + svg, paths, stroke, fill, bg; | ||
| 122 | + if (sh) { | ||
| 123 | + stroke = p.outline; | ||
| 124 | + fill = sh.flip ? p.sea : p.land; | ||
| 125 | + bg = sh.flip ? p.land : p.sea; | ||
| 126 | + | ||
| 127 | + svg = d3.select('#ov-topo').select('svg'); | ||
| 128 | + paths = d3.select('#topo-map').selectAll('path'); | ||
| 129 | + | ||
| 130 | + svg.style('background-color', bg); | ||
| 131 | + paths.attr({ | ||
| 132 | + stroke: stroke, | ||
| 133 | + fill: fill | ||
| 134 | + }); | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + | ||
| 117 | angular.module('onosSvg') | 138 | angular.module('onosSvg') |
| 118 | .factory('MapService', ['$log', '$q', 'FnService', 'GeoDataService', | 139 | .factory('MapService', ['$log', '$q', 'FnService', 'GeoDataService', |
| 119 | function (_$log_, _$q_, _fs_, _gds_) { | 140 | function (_$log_, _$q_, _fs_, _gds_) { |
| ... | @@ -124,7 +145,8 @@ | ... | @@ -124,7 +145,8 @@ |
| 124 | 145 | ||
| 125 | return { | 146 | return { |
| 126 | loadMapRegionInto: loadMapRegionInto, | 147 | loadMapRegionInto: loadMapRegionInto, |
| 127 | - loadMapInto: loadMapInto | 148 | + loadMapInto: loadMapInto, |
| 149 | + reshade: reshade | ||
| 128 | }; | 150 | }; |
| 129 | }]); | 151 | }]); |
| 130 | 152 | ... | ... |
| ... | @@ -29,14 +29,14 @@ | ... | @@ -29,14 +29,14 @@ |
| 29 | ]; | 29 | ]; |
| 30 | 30 | ||
| 31 | // references to injected services etc. | 31 | // references to injected services etc. |
| 32 | - var $scope, $log, $cookies, fs, ks, zs, gs, ms, sus, flash, wss, ps, | 32 | + var $scope, $log, $cookies, fs, ks, zs, gs, ms, sus, flash, wss, ps, th, |
| 33 | tds, tes, tfs, tps, tis, tss, tls, tts, tos, fltr, ttbs, ttip, tov; | 33 | tds, tes, tfs, tps, tis, tss, tls, tts, tos, fltr, ttbs, ttip, tov; |
| 34 | 34 | ||
| 35 | // DOM elements | 35 | // DOM elements |
| 36 | var ovtopo, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer; | 36 | var ovtopo, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer; |
| 37 | 37 | ||
| 38 | // Internal state | 38 | // Internal state |
| 39 | - var zoomer, actionMap; | 39 | + var zoomer, actionMap, themeListener; |
| 40 | 40 | ||
| 41 | // --- Short Cut Keys ------------------------------------------------ | 41 | // --- Short Cut Keys ------------------------------------------------ |
| 42 | 42 | ||
| ... | @@ -345,6 +345,27 @@ | ... | @@ -345,6 +345,27 @@ |
| 345 | } | 345 | } |
| 346 | }; | 346 | }; |
| 347 | 347 | ||
| 348 | + var tintOn = 0, | ||
| 349 | + shadeFlip = 0, | ||
| 350 | + shadePalette = { | ||
| 351 | + light: { | ||
| 352 | + sea: 'aliceblue', | ||
| 353 | + land: 'white', | ||
| 354 | + outline: '#ddd' | ||
| 355 | + }, | ||
| 356 | + dark: { | ||
| 357 | + sea: '#001830', | ||
| 358 | + land: '#232331', | ||
| 359 | + outline: '#3a3a3a' | ||
| 360 | + } | ||
| 361 | + }; | ||
| 362 | + | ||
| 363 | + function shading() { | ||
| 364 | + return tintOn ? { | ||
| 365 | + palette: shadePalette[th.theme()], | ||
| 366 | + flip: shadeFlip | ||
| 367 | + } : ''; | ||
| 368 | + } | ||
| 348 | 369 | ||
| 349 | function setUpMap($loc) { | 370 | function setUpMap($loc) { |
| 350 | var qp = $loc.search(), | 371 | var qp = $loc.search(), |
| ... | @@ -355,27 +376,53 @@ | ... | @@ -355,27 +376,53 @@ |
| 355 | ms1 = qp.mapscale, | 376 | ms1 = qp.mapscale, |
| 356 | ms2 = pr && pr.scale, | 377 | ms2 = pr && pr.scale, |
| 357 | mapScale = ms1 || ms2 || 1, | 378 | mapScale = ms1 || ms2 || 1, |
| 379 | + t1 = qp.tint, | ||
| 380 | + t2 = pr && pr.tint, | ||
| 381 | + tint = t1 || t2 || 'off', | ||
| 358 | promise, | 382 | promise, |
| 359 | cfilter; | 383 | cfilter; |
| 360 | 384 | ||
| 385 | + tintOn = tint === 'on' ? 1 : 0; | ||
| 386 | + | ||
| 361 | mapG = zoomLayer.append('g').attr('id', 'topo-map'); | 387 | mapG = zoomLayer.append('g').attr('id', 'topo-map'); |
| 362 | if (mapId === 'usa') { | 388 | if (mapId === 'usa') { |
| 363 | - promise = ms.loadMapInto(mapG, '*continental_us'); | 389 | + shadeFlip = 0; |
| 390 | + promise = ms.loadMapInto(mapG, '*continental_us', { | ||
| 391 | + adjustScale: mapScale, | ||
| 392 | + shading: shading() | ||
| 393 | + }); | ||
| 364 | } else if (mapId === 'bayarea') { | 394 | } else if (mapId === 'bayarea') { |
| 365 | - // TODO: be consistent about propagating options to other cases | 395 | + shadeFlip = 1; |
| 366 | promise = ms.loadMapInto(mapG, '*bayarea', { | 396 | promise = ms.loadMapInto(mapG, '*bayarea', { |
| 367 | objectTag: 'bayareaGEO', | 397 | objectTag: 'bayareaGEO', |
| 368 | adjustScale: mapScale, | 398 | adjustScale: mapScale, |
| 369 | - fill: 'aliceblue' | 399 | + shading: shading() |
| 370 | }); | 400 | }); |
| 371 | } else { | 401 | } else { |
| 402 | + shadeFlip = 0; | ||
| 372 | cfilter = countryFilters[mapId] || countryFilters.world; | 403 | cfilter = countryFilters[mapId] || countryFilters.world; |
| 373 | - promise = ms.loadMapRegionInto(mapG, { countryFilter: cfilter }); | 404 | + promise = ms.loadMapRegionInto(mapG, { |
| 405 | + countryFilter: cfilter, | ||
| 406 | + adjustScale: mapScale, | ||
| 407 | + shading: shading() | ||
| 408 | + }); | ||
| 374 | } | 409 | } |
| 375 | - ps.setPrefs('topo_mapid', { id: mapId, scale: mapScale }); | 410 | + ps.setPrefs('topo_mapid', { id: mapId, scale: mapScale, tint: tint }); |
| 376 | return promise; | 411 | return promise; |
| 377 | } | 412 | } |
| 378 | 413 | ||
| 414 | + // set up theme listener to re-shade the map when required. | ||
| 415 | + function mapShader(on) { | ||
| 416 | + if (on) { | ||
| 417 | + themeListener = th.addListener(function () { | ||
| 418 | + ms.reshade(shading()); | ||
| 419 | + }); | ||
| 420 | + } else { | ||
| 421 | + th.removeListener(themeListener); | ||
| 422 | + themeListener = null; | ||
| 423 | + } | ||
| 424 | + } | ||
| 425 | + | ||
| 379 | function opacifyMap(b) { | 426 | function opacifyMap(b) { |
| 380 | mapG.transition() | 427 | mapG.transition() |
| 381 | .duration(1000) | 428 | .duration(1000) |
| ... | @@ -448,7 +495,8 @@ | ... | @@ -448,7 +495,8 @@ |
| 448 | .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout', | 495 | .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout', |
| 449 | '$cookies', 'FnService', 'MastService', 'KeyService', 'ZoomService', | 496 | '$cookies', 'FnService', 'MastService', 'KeyService', 'ZoomService', |
| 450 | 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService', | 497 | 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService', |
| 451 | - 'WebSocketService', 'PrefsService', 'TopoDialogService', | 498 | + 'WebSocketService', 'PrefsService', 'ThemeService', |
| 499 | + 'TopoDialogService', | ||
| 452 | 'TopoEventService', 'TopoForceService', 'TopoPanelService', | 500 | 'TopoEventService', 'TopoForceService', 'TopoPanelService', |
| 453 | 'TopoInstService', 'TopoSelectService', 'TopoLinkService', | 501 | 'TopoInstService', 'TopoSelectService', 'TopoLinkService', |
| 454 | 'TopoTrafficService', 'TopoObliqueService', 'TopoFilterService', | 502 | 'TopoTrafficService', 'TopoObliqueService', 'TopoFilterService', |
| ... | @@ -456,7 +504,8 @@ | ... | @@ -456,7 +504,8 @@ |
| 456 | 'TopoOverlayService', | 504 | 'TopoOverlayService', |
| 457 | 505 | ||
| 458 | function (_$scope_, _$log_, $loc, $timeout, _$cookies_, _fs_, mast, _ks_, | 506 | function (_$scope_, _$log_, $loc, $timeout, _$cookies_, _fs_, mast, _ks_, |
| 459 | - _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _ps_, _tds_, _tes_, | 507 | + _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _ps_, _th_, |
| 508 | + _tds_, _tes_, | ||
| 460 | _tfs_, _tps_, _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_, | 509 | _tfs_, _tps_, _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_, |
| 461 | _ttbs_, tspr, _ttip_, _tov_) { | 510 | _ttbs_, tspr, _ttip_, _tov_) { |
| 462 | var params = $loc.search(), | 511 | var params = $loc.search(), |
| ... | @@ -484,6 +533,7 @@ | ... | @@ -484,6 +533,7 @@ |
| 484 | flash = _flash_; | 533 | flash = _flash_; |
| 485 | wss = _wss_; | 534 | wss = _wss_; |
| 486 | ps = _ps_; | 535 | ps = _ps_; |
| 536 | + th = _th_; | ||
| 487 | tds = _tds_; | 537 | tds = _tds_; |
| 488 | tes = _tes_; | 538 | tes = _tes_; |
| 489 | tfs = _tfs_; | 539 | tfs = _tfs_; |
| ... | @@ -523,6 +573,7 @@ | ... | @@ -523,6 +573,7 @@ |
| 523 | tis.destroyInst(); | 573 | tis.destroyInst(); |
| 524 | tfs.destroyForce(); | 574 | tfs.destroyForce(); |
| 525 | ttbs.destroyToolbar(); | 575 | ttbs.destroyToolbar(); |
| 576 | + mapShader(false); | ||
| 526 | }); | 577 | }); |
| 527 | 578 | ||
| 528 | // svg layer and initialization of components | 579 | // svg layer and initialization of components |
| ... | @@ -548,6 +599,7 @@ | ... | @@ -548,6 +599,7 @@ |
| 548 | flash.enable(false); | 599 | flash.enable(false); |
| 549 | toggleMap(prefsState.bg); | 600 | toggleMap(prefsState.bg); |
| 550 | flash.enable(true); | 601 | flash.enable(true); |
| 602 | + mapShader(true); | ||
| 551 | 603 | ||
| 552 | // now we have the map projection, we are ready for | 604 | // now we have the map projection, we are ready for |
| 553 | // the server to send us device/host data... | 605 | // the server to send us device/host data... | ... | ... |
-
Please register or login to post a comment