Skip to content

Commit 54d2f90

Browse files
authored
#8 - Expand node on double-click. (#10)
1 parent 5eb8cee commit 54d2f90

File tree

4 files changed

+74
-30
lines changed

4 files changed

+74
-30
lines changed

dist/ml-ol-maps-ng.js

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
enableLinks: '=',
2525

2626
// parent callbacks
27-
parentSingleClick: '&singleClick'
27+
parentSingleClick: '&singleClick',
28+
parentDoubleClick: '&doubleClick'
2829
},
2930
templateUrl: '/templates/detail-map.html',
3031
controller: 'MLOlDetailMapController',
@@ -54,11 +55,31 @@
5455
});
5556

5657
$scope.$on('openlayers.map.singleclick', function(event, data) {
58+
if (data.event.map.hasFeatureAtPixel(data.event.pixel)) {
59+
data.event.map.forEachFeatureAtPixel(data.event.pixel, function (feature, layer) {
60+
$scope.$apply(function() {
61+
if ($scope.parentSingleClick) {
62+
$scope.parentSingleClick({ 'feature': feature });
63+
}
64+
65+
// if (feature.get('metadata')) {
66+
// ctrl.mapItemSelected = feature.get('metadata');
67+
// }
68+
});
69+
});
70+
}
71+
else {
72+
$scope.$apply(function() {
73+
ctrl.mapItemSelected = null;
74+
});
75+
}
76+
});
77+
78+
$scope.$on('openlayers.map.dblclick', function(event, data) {
5779
data.event.map.forEachFeatureAtPixel(data.event.pixel, function (feature, layer) {
58-
var featureUri = feature.get('uri');
5980
$scope.$apply(function() {
60-
if ($scope.parentSingleClick) {
61-
$scope.parentSingleClick({ 'featureUri': featureUri });
81+
if ($scope.parentDoubleClick) {
82+
$scope.parentDoubleClick({ 'feature': feature });
6283
}
6384

6485
if ($scope.enableLinks) {
@@ -384,29 +405,29 @@
384405
};
385406

386407
var createLineStyle = function(feature, resolution) {
387-
// var geometry = feature.getGeometry();
408+
var geometry = feature.getGeometry();
388409
var styles = [
389410
new ol.style.Style({
390411
stroke: new ol.style.Stroke({color: 'black', width: 3}),
391412
text: createTextStyle(feature.get('name'), 'black')
392413
})
393414
];
394415

395-
// geometry.forEachSegment(function(start, end) {
396-
// var dx = end[0] - start[0];
397-
// var dy = end[1] - start[1];
398-
// var rotation = Math.atan2(dy, dx);
399-
// // arrows
400-
// styles.push(new ol.style.Style({
401-
// geometry: new ol.geom.Point(end),
402-
// image: new ol.style.Icon({
403-
// src: 'images/arrow-black.png',
404-
// anchor: [1.5, 0.5],
405-
// rotateWithView: false,
406-
// rotation: -rotation
407-
// })
408-
// }));
409-
// });
416+
geometry.forEachSegment(function(start, end) {
417+
var dx = end[0] - start[0];
418+
var dy = end[1] - start[1];
419+
var rotation = Math.atan2(dy, dx);
420+
// arrows
421+
styles.push(new ol.style.Style({
422+
geometry: new ol.geom.Point(end),
423+
image: new ol.style.Icon({
424+
src: 'images/arrow-black.png',
425+
anchor: [1.5, 0.5],
426+
rotateWithView: false,
427+
rotation: -rotation
428+
})
429+
}));
430+
});
410431

411432
return styles;
412433
};
@@ -489,15 +510,16 @@
489510
},
490511
defaults: {
491512
interactions: {
492-
mouseWheelZoom: true
513+
mouseWheelZoom: true,
514+
doubleClickZoom: false
493515
},
494516
controls: {
495517
zoom: true,
496518
rotate: false,
497519
attribution: false
498520
},
499521
events: {
500-
map: ['singleclick', 'moveend']
522+
map: ['singleclick', 'dblclick', 'moveend']
501523
}
502524
},
503525
baseMap: {

0 commit comments

Comments
 (0)