-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathdom-events.js
41 lines (37 loc) · 1.16 KB
/
dom-events.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
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.transform([-0.92, 52.96], 'EPSG:4326', 'EPSG:3857'),
zoom: 6
})
});
var popup = new Popup();
map.addOverlay(popup);
map.on('singleclick', function(evt) {
var el = document.createElement("div");
var title = document.createElement("h2");
title.innerHTML = 'Close the popup?';
el.appendChild(title);
var content = document.createElement("p");
content.innerHTML = '<a href="#" data-action="yes">Yes</a>, <a href="#" data-action="no">No</a>';
el.appendChild(content);
popup.show(evt.coordinate, el);
});
// Add a click event handler to the popup DOM element which we will use to
// capture the user clicking on a link within the popup with an "action" data
// attribute
popup.getElement().addEventListener('click', function(e) {
var action = e.target.getAttribute('data-action');
if (action) {
alert('You choose: ' + action);
if (action === 'yes') {
popup.hide();
}
e.preventDefault();
}
}, false);