-
Notifications
You must be signed in to change notification settings - Fork 0
/
markerclip.js
73 lines (58 loc) · 2.17 KB
/
markerclip.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
71
72
function MarkerClip(map) {
this.map = map;
var theClip = this;
var markerDiv = document.createElement('div');
markerDiv.id = map.parent.id + '-markerClip-' + new Date().getTime();
markerDiv.style.margin = '0';
markerDiv.style.padding = '0';
markerDiv.style.position = 'absolute';
markerDiv.style.top = '0px';
markerDiv.style.left = '0px';
markerDiv.style.width = map.dimensions.x+'px';
markerDiv.style.height = map.dimensions.y+'px';
map.parent.appendChild(markerDiv);
function onMapChange() {
theClip.updateMarkers();
}
map.addCallback('panned', onMapChange);
map.addCallback('zoomed', onMapChange);
map.addCallback('centered', onMapChange);
map.addCallback('extentset', onMapChange);
map.addCallback('resized', function() {
markerDiv.style.width = map.dimensions.x+'px';
markerDiv.style.height = map.dimensions.y+'px';
theClip.updateMarkers();
});
this.updateMarkers = function() {
for (var i = 0; i < this.markers.length; i++) {
this.updateMarkerAt(i);
}
};
this.markers = [];
this.markerLocations = [];
this.markerOffsets = [];
this.addMarker = function(element, location, offset) {
element.style.position = 'absolute';
markerDiv.appendChild(element);
this.markers.push(element);
this.markerLocations.push(location);
this.markerOffsets.push(offset);
this.updateMarkerAt(this.markers.length-1);
};
this.updateMarkerAt = function(index) {
var point = map.locationPoint(this.markerLocations[index]),
offset = this.markerOffsets[index],
element = this.markers[index];
element.style.left = (point.x - offset.x) + 'px';
element.style.top = (point.y - offset.y) + 'px';
};
var createdMarkerCount = 0;
this.createDefaultMarker = function(w,h) {
var div = document.createElement('div');
div.style.width = w + 'px';
div.style.height = h + 'px';
div.id = map.parent.id+'-marker-'+createdMarkerCount;
createdMarkerCount++;
return div;
};
}