-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathol-map-popup.js
70 lines (61 loc) · 1.75 KB
/
ol-map-popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Popup Overlay
*/
var div = document.getElementById('ol-popup');
var close = document.getElementById('close');
var content = document.getElementById('content');
var popup = new ol.Overlay({
element: div,
autoPan: true,
autoPanAnimation: {
duration: 250
}
});
// Hide overlay
popup.setPosition(undefined);
// Show overlay
//popup.setPosition(ol.proj.fromLonLat([0, 0]));
map.addOverlay(popup);
// Close/hide overlay popup
close.onclick = function() {
popup.setPosition(undefined);
close.blur();
return false;
};
// On click
map.on('singleclick', function (evt) {
// Show popup on marker click
var feature = map.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
return feature;
});
// Show popup on marker click
if (map.hasFeatureAtPixel(evt.pixel) === true)
{
var coordinate = evt.coordinate;
popup.setPosition(coordinate);
// Get marker description
content.innerHTML = feature.get('desc');
} else {
popup.setPosition(undefined);
close.blur();
}
console.log("Marker clicked/hovered !!!");
});
// Hover popup
// map.on('pointermove', function (evt) {
// // Show popup on marker click
// var feature = map.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
// return feature;
// });
// if (map.hasFeatureAtPixel(evt.pixel) === true)
// {
// var coordinate = evt.coordinate;
// popup.setPosition(coordinate);
// // Get marker description
// content.innerHTML = feature.get('desc');
// console.log("Marker clicked/hovered !!! Type: ", feature.get('desc'));
// } else {
// popup.setPosition(undefined);
// close.blur();
// }
// });