|
21 | 21 | baseMap: '=', |
22 | 22 | zoom: '=', |
23 | 23 | geometry: '=', |
| 24 | + groups: '=', |
24 | 25 | enableLinks: '=', |
| 26 | + enablePropertiesView: '=', |
25 | 27 |
|
26 | 28 | // parent callbacks |
27 | 29 | parentSingleClick: '&singleClick', |
|
36 | 38 | MLOlDetailMapController.$inject = ['$scope', 'mlOlHelper', 'mapLinksService']; |
37 | 39 | function MLOlDetailMapController($scope, mlOlHelper, mapLinksService) { |
38 | 40 | var ctrl = this; |
| 41 | + var i = 0; |
39 | 42 | ctrl.pointMap = {}; |
40 | 43 | ctrl.geometries = []; |
| 44 | + ctrl.mapItemSelected = null; |
41 | 45 |
|
42 | 46 | ctrl.hideLinks = false; |
43 | 47 | if ($scope.enableLinks !== undefined) { |
44 | 48 | ctrl.hideLinks = !$scope.enableLinks; |
45 | 49 | } |
46 | 50 |
|
| 51 | + ctrl.enablePropertiesView = true; |
| 52 | + if ($scope.enablePropertiesView !== undefined) { |
| 53 | + ctrl.enablePropertiesView = $scope.enablePropertiesView; |
| 54 | + } |
| 55 | + |
| 56 | + if ($scope.groups !== undefined) { |
| 57 | + for (i = 0; i < $scope.groups.length; i++) { |
| 58 | + mlOlHelper.setGroupColor($scope.groups[i].name, $scope.groups[i].color); |
| 59 | + } |
| 60 | + } |
| 61 | + |
47 | 62 | $scope.$watch('features', function(data) { |
48 | 63 | ctrl.addMapNodes($scope.features); |
49 | 64 | }); |
|
62 | 77 | $scope.parentSingleClick({ 'feature': feature }); |
63 | 78 | } |
64 | 79 |
|
65 | | - // if (feature.get('metadata')) { |
66 | | - // ctrl.mapItemSelected = feature.get('metadata'); |
67 | | - // } |
| 80 | + if (feature.get('metadata')) { |
| 81 | + ctrl.mapItemSelected = feature.get('metadata'); |
| 82 | + } |
68 | 83 | }); |
69 | 84 | }); |
70 | 85 | } |
|
96 | 111 | ctrl.mapSettings.lineLayer.visible = !ctrl.hideLinks; |
97 | 112 | }; |
98 | 113 |
|
| 114 | + ctrl.closeMetadata = function() { |
| 115 | + ctrl.mapItemSelected = null; |
| 116 | + }; |
| 117 | + |
99 | 118 | ctrl.addLinkedNodes = function(results) { |
100 | 119 | var tmpPoints = []; |
101 | 120 | var i = 0; |
|
107 | 126 | properties: { |
108 | 127 | name: results.nodes[i].label, |
109 | 128 | id: results.nodes[i].id, |
110 | | - uri: results.nodes[i].id |
| 129 | + uri: results.nodes[i].id, |
| 130 | + group: results.nodes[i].group || 'unknown', |
| 131 | + count: results.nodes[i].edgeCount || 0, |
| 132 | + metadata: results.nodes[i].metadata |
111 | 133 | }, |
112 | 134 | geometry: { |
113 | 135 | type: 'Point', |
|
145 | 167 | type: 'Feature', |
146 | 168 | id: results.edges[i].id, |
147 | 169 | properties: { |
148 | | - name: results.edges[i].label |
| 170 | + name: results.edges[i].label, |
| 171 | + strength: results.edges[i].strength || 2, |
| 172 | + metadata: results.edges[i].metadata |
149 | 173 | }, |
150 | 174 | geometry: { |
151 | 175 | type: 'LineString', |
|
290 | 314 |
|
291 | 315 | // Define the map settings. |
292 | 316 | var tmpMapSettings = mlOlHelper.buildMapSettings(); |
293 | | - tmpMapSettings.ptLayer.style = mlOlHelper.createPointStyle; |
| 317 | + tmpMapSettings.ptLayer.style = mlOlHelper.createPointCountStyle; |
294 | 318 | tmpMapSettings.lineLayer = $scope.lineLayer ? $scope.lineLayer : defaultLineLayer; |
295 | 319 | tmpMapSettings.center.zoom = $scope.zoom ? $scope.zoom : 4; |
296 | 320 |
|
|
370 | 394 | '#e8790b', // orange |
371 | 395 | '#2433d8', // blue |
372 | 396 | '#bb0be8', // purple |
373 | | - '#17e804' // lime-green |
| 397 | + '#17e804' // lime-green |
374 | 398 | ]; |
375 | 399 |
|
376 | | - var createTextStyle = function(text, fColor) { |
377 | | - var fillColor = '#f70010'; |
378 | | - if (fColor) { |
379 | | - fillColor = fColor; |
380 | | - } |
| 400 | + // Map for user defined colors based on 'group' property. |
| 401 | + var groupColorMap = {}; |
| 402 | + |
| 403 | + var createTextStyle = function(text, fColor, sColor, yOffset) { |
| 404 | + var fillColor = fColor || '#f70010'; |
| 405 | + var strokeColor = sColor || 'white'; |
| 406 | + var yOff = yOffset || 6; |
| 407 | + |
381 | 408 | return new ol.style.Text({ |
382 | 409 | textAlign: 'center', |
383 | 410 | textBaseline: 'top', |
384 | 411 | font: '12px Arial', |
385 | 412 | text: text, |
386 | 413 | fill: new ol.style.Fill({color: fillColor}), |
387 | | - stroke: new ol.style.Stroke({color: 'white', width: 3}), |
| 414 | + stroke: new ol.style.Stroke({color: strokeColor, width: 1}), |
388 | 415 | offsetX: 0, |
389 | | - offsetY: 4, |
| 416 | + offsetY: yOff, |
390 | 417 | rotation: 0 |
391 | 418 | }); |
392 | 419 | }; |
393 | 420 |
|
| 421 | + var createTextCountStyle = function(count, fColor, yOffset, xOffset) { |
| 422 | + var fillColor = fColor || '#f70010'; |
| 423 | + var yOff = yOffset || 6; |
| 424 | + var xOff = xOffset || 6; |
| 425 | + |
| 426 | + return new ol.style.Text({ |
| 427 | + textAlign: 'center', |
| 428 | + textBaseline: 'middle', |
| 429 | + font: '8pt Arial', |
| 430 | + text: count.toString(), |
| 431 | + fill: new ol.style.Fill({color: fillColor}), |
| 432 | + offsetX: xOff, |
| 433 | + offsetY: yOff |
| 434 | + }); |
| 435 | + }; |
| 436 | + |
394 | 437 | var createClusterTextStyle = function(text) { |
395 | 438 | return new ol.style.Text({ |
396 | 439 | textAlign: 'center', |
|
414 | 457 | ]; |
415 | 458 |
|
416 | 459 | geometry.forEachSegment(function(start, end) { |
| 460 | + var canvas = document.createElement('canvas'); |
| 461 | + var render = canvas.getContext('2d'); |
417 | 462 | var dx = end[0] - start[0]; |
418 | 463 | var dy = end[1] - start[1]; |
419 | 464 | var rotation = Math.atan2(dy, dx); |
| 465 | + |
| 466 | + render.strokeStyle = 'black'; |
| 467 | + render.fillStyle = 'black'; |
| 468 | + render.lineWidth = 3; |
| 469 | + render.beginPath(); |
| 470 | + render.moveTo(0,0); |
| 471 | + render.lineTo(10,10); |
| 472 | + render.lineTo(0,20); |
| 473 | + render.stroke(); |
| 474 | + |
420 | 475 | // arrows |
421 | 476 | styles.push(new ol.style.Style({ |
422 | 477 | geometry: new ol.geom.Point(end), |
423 | 478 | image: new ol.style.Icon({ |
424 | | - src: 'images/arrow-black.png', |
425 | | - anchor: [1.5, 0.5], |
| 479 | + img: canvas, |
| 480 | + imgSize: [canvas.width, canvas.height], |
| 481 | + anchor: [26, 10], |
| 482 | + anchorXUnits: 'pixels', |
| 483 | + anchorYUnits: 'pixels', |
426 | 484 | rotateWithView: false, |
427 | 485 | rotation: -rotation |
428 | 486 | }) |
|
433 | 491 | }; |
434 | 492 |
|
435 | 493 | var createPointStyle = function(feature, resolution) { |
436 | | - var radius = 6; |
437 | | - return new ol.style.Style({ |
438 | | - image: new ol.style.Circle({ |
439 | | - radius: radius, |
440 | | - fill: new ol.style.Fill({color: 'red'}), |
441 | | - stroke: new ol.style.Stroke({color: 'black', width: 1}) |
442 | | - }), |
443 | | - text: createTextStyle(feature.get('name')) |
444 | | - }); |
| 494 | + var radius = 8; |
| 495 | + var fillColor = 'red'; |
| 496 | + if (feature.get('group')) { |
| 497 | + var group = feature.get('group'); |
| 498 | + if (group && groupColorMap[group]) { |
| 499 | + fillColor = groupColorMap[group]; |
| 500 | + } |
| 501 | + } |
| 502 | + |
| 503 | + var styles = [ |
| 504 | + new ol.style.Style({ |
| 505 | + image: new ol.style.Circle({ |
| 506 | + radius: radius, |
| 507 | + fill: new ol.style.Fill({color: fillColor}), |
| 508 | + stroke: new ol.style.Stroke({color: 'black', width: 1}) |
| 509 | + }), |
| 510 | + text: createTextStyle(feature.get('name'), fillColor) |
| 511 | + }) |
| 512 | + ]; |
| 513 | + |
| 514 | + return styles; |
| 515 | + }; |
| 516 | + |
| 517 | + var createPointCountStyle = function(feature, resolution) { |
| 518 | + var radius = 16; |
| 519 | + var fillColor = 'red'; |
| 520 | + var childCount = feature.get('count') || 0; |
| 521 | + var styles = []; |
| 522 | + |
| 523 | + if (feature.get('group')) { |
| 524 | + var group = feature.get('group'); |
| 525 | + if (group && groupColorMap[group]) { |
| 526 | + fillColor = groupColorMap[group]; |
| 527 | + } |
| 528 | + } |
| 529 | + |
| 530 | + styles.push( |
| 531 | + new ol.style.Style({ |
| 532 | + image: new ol.style.Circle({ |
| 533 | + radius: radius, |
| 534 | + fill: new ol.style.Fill({color: fillColor}), |
| 535 | + stroke: new ol.style.Stroke({color: 'black', width: 1}) |
| 536 | + }), |
| 537 | + text: createTextStyle(feature.get('name'), fillColor, null, radius) |
| 538 | + }) |
| 539 | + ); |
| 540 | + |
| 541 | + if (childCount > 0) { |
| 542 | + var cRadius = 10; |
| 543 | + var textColor = 'white'; |
| 544 | + var canvas = document.createElement('canvas'); |
| 545 | + var render = canvas.getContext('2d'); |
| 546 | + |
| 547 | + if (childCount >= 100 && childCount < 1000) { |
| 548 | + cRadius = 12; |
| 549 | + } |
| 550 | + else if (childCount >= 1000 && childCount < 10000) { |
| 551 | + cRadius = 15; |
| 552 | + } |
| 553 | + else if (childCount >= 10000) { |
| 554 | + cRadius = 17; |
| 555 | + } |
| 556 | + |
| 557 | + render.strokeStyle = 'white'; |
| 558 | + render.fillStyle = '#848484'; |
| 559 | + render.lineWidth = 1; |
| 560 | + render.beginPath(); |
| 561 | + render.arc(cRadius, cRadius, cRadius, 0, 2 * Math.PI); |
| 562 | + render.fill(); |
| 563 | + render.stroke(); |
| 564 | + |
| 565 | + styles.push( |
| 566 | + new ol.style.Style({ |
| 567 | + image: new ol.style.Icon({ |
| 568 | + img: canvas, |
| 569 | + imgSize: [canvas.width, canvas.height], |
| 570 | + anchor: [cRadius + 15, 20], |
| 571 | + anchorXUnits: 'pixels', |
| 572 | + anchorYUnits: 'pixels' |
| 573 | + }), |
| 574 | + text: createTextCountStyle(childCount, textColor, cRadius - 20, -15) |
| 575 | + }) |
| 576 | + ); |
| 577 | + } |
| 578 | + |
| 579 | + return styles; |
445 | 580 | }; |
446 | 581 |
|
447 | 582 | var createClusterPointStyle = function(feature, resolution) { |
|
473 | 608 | fill: new ol.style.Fill({color: markerColors[colorIdx]}), |
474 | 609 | stroke: new ol.style.Stroke({color: 'black', width: strokeWidth, lineDash: lineDash}) |
475 | 610 | }), |
476 | | - text: (count > 1) ? createClusterTextStyle(''+ count) : createTextStyle('') |
| 611 | + text: (count > 1) ? createClusterTextStyle(count.toString()) : createTextStyle('') |
477 | 612 | }); |
478 | 613 | }; |
479 | 614 |
|
|
550 | 685 | return settings; |
551 | 686 | }; |
552 | 687 |
|
| 688 | + var setGroupColor = function(group, color) { |
| 689 | + groupColorMap[group] = color; |
| 690 | + }; |
| 691 | + |
553 | 692 | return { |
554 | 693 | createTextStyle: createTextStyle, |
| 694 | + createTextCountStyle: createTextCountStyle, |
555 | 695 | createPointStyle: createPointStyle, |
| 696 | + createPointCountStyle: createPointCountStyle, |
556 | 697 | createClusterPointStyle: createClusterPointStyle, |
557 | 698 | createClusterTextStyle: createClusterTextStyle, |
558 | 699 | createLineStyle: createLineStyle, |
559 | 700 | convertExtent: convertExtent, |
560 | | - buildMapSettings: buildMapSettings |
| 701 | + buildMapSettings: buildMapSettings, |
| 702 | + setGroupColor: setGroupColor |
561 | 703 | }; |
562 | 704 | } |
563 | 705 |
|
|
0 commit comments