-
Notifications
You must be signed in to change notification settings - Fork 1
/
d3stuff.js
70 lines (59 loc) · 1.9 KB
/
d3stuff.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
var geomap = document.querySelector("geomap")
var maplatlng = [ parseFloat(geomap.getAttribute("lat")), parseFloat(geomap.getAttribute("lon")) ]
var markerID = 0
globaalidata = [
{
id: "globaali1",
latlng: [ maplatlng[0]+0.001, maplatlng[1] ]
},
{
id: "globaali2",
latlng: [ maplatlng[0]+0.003, maplatlng[1] ]
},
{
id: "globaali3",
latlng: [ maplatlng[0]+0.002, maplatlng[1] ]
}
];
// DOM level click event
geomap.addEventListener("click", function(e) {
console.log("geomap click", this._geomap)
});
// MAP level click event
// TODO: make e map engine independent, now it's leaflet
geomap._geomap.on("click", function(latlng, e) {
console.log("geomap innerclick", e);
var marker = {
id: "click-marker-" + ++markerID,
latlng: latlng,
text: document.querySelector("#disruptive-template").innerHTML.replace("%ID%", "click-form-"+markerID)
}
// TODO: actuaally control the marker stream with d3
updateMarkers([marker])
});
updateMarkers = function(data) {
d3map = d3.select("geomap")
// console.log("d3map", d3map)
var markers = d3map.selectAll("marker")
.data(data, function(d) { return d ? d.id : null } )
markers
.enter()
.append("marker")
.html(function(d, i) { return d.text })
.attr("id", function(d) { return d.id })
.attr("lat", function(d) { return d.latlng[0] })
.attr("lon", function(d) { return d.latlng[1] })
}
disruptiveOK = function(el) {
// SORRY WE RUSHED IN SOME HACKINESS
var input = el.parentNode.querySelector("input[type=text]")
var id = el.parentNode.id
var marker = geomap.querySelector("#"+id.replace("form", "marker"))
console.log(el, input, marker)
el.parentNode.innerHTML = input.value
marker.innerHTML = input.value
marker._geomap.obj.setPopupContent(input.value) // YES THIS IS LEAFLET CODE, sorry we hacked it
}
window.addEventListener("DOMContentLoaded", function() {
// updateMarkers(globaalidata);
});