-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathzaprange.js
123 lines (105 loc) · 5.18 KB
/
zaprange.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// @author ZasoGD
// @name Zaprange
// @category Layer
// @version 0.1.8
// @description Shows the maximum range of attack by the portals.
/* exported setup, changelog --eslint */
/* global L -- eslint */
var changelog = [
{
version: '0.1.8',
changes: ['Refactoring: fix eslint'],
},
{
version: '0.1.7',
changes: ['Version upgrade due to a change in the wrapper: plugin icons are now vectorized'],
},
{
version: '0.1.6',
changes: ['Version upgrade due to a change in the wrapper: added plugin icon'],
},
];
// use own namespace for plugin
window.plugin.zaprange = function () {};
window.plugin.zaprange.zapLayers = {};
window.plugin.zaprange.MIN_MAP_ZOOM = 16;
window.plugin.zaprange.portalAdded = function (data) {
data.portal.on('add', function () {
window.plugin.zaprange.draw(this.options.guid, this.options.team);
});
data.portal.on('remove', function () {
window.plugin.zaprange.remove(this.options.guid, this.options.team);
});
};
window.plugin.zaprange.remove = function (guid, faction) {
var previousLayer = window.plugin.zaprange.zapLayers[guid];
if (previousLayer) {
if (faction === window.TEAM_ENL) {
window.plugin.zaprange.zapCircleEnlHolderGroup.removeLayer(previousLayer);
} else {
window.plugin.zaprange.zapCircleResHolderGroup.removeLayer(previousLayer);
}
delete window.plugin.zaprange.zapLayers[guid];
}
};
window.plugin.zaprange.draw = function (guid, faction) {
var d = window.portals[guid];
if (faction !== window.TEAM_NONE) {
var coo = d._latlng;
var latlng = new L.LatLng(coo.lat, coo.lng);
var portalLevel = d.options.level;
var optCircle = { color: 'red', opacity: 0.7, fillColor: 'red', fillOpacity: 0.1, weight: 1, interactive: false, dashArray: [10, 6] };
var range = 5 * portalLevel + 35;
var circle = new L.Circle(latlng, range, optCircle);
if (faction === window.TEAM_ENL) {
circle.addTo(window.plugin.zaprange.zapCircleEnlHolderGroup);
} else {
circle.addTo(window.plugin.zaprange.zapCircleResHolderGroup);
}
window.plugin.zaprange.zapLayers[guid] = circle;
}
};
window.plugin.zaprange.showOrHide = function () {
if (window.map.getZoom() >= window.plugin.zaprange.MIN_MAP_ZOOM) {
// show the layer
if (!window.plugin.zaprange.zapLayerEnlHolderGroup.hasLayer(window.plugin.zaprange.zapCircleEnlHolderGroup)) {
window.plugin.zaprange.zapLayerEnlHolderGroup.addLayer(window.plugin.zaprange.zapCircleEnlHolderGroup);
$('.leaflet-control-layers-list span:contains("Zaprange Enlightened")').parent('label').removeClass('disabled').attr('title', '');
}
if (!window.plugin.zaprange.zapLayerResHolderGroup.hasLayer(window.plugin.zaprange.zapCircleResHolderGroup)) {
window.plugin.zaprange.zapLayerResHolderGroup.addLayer(window.plugin.zaprange.zapCircleResHolderGroup);
$('.leaflet-control-layers-list span:contains("Zaprange Resistance")').parent('label').removeClass('disabled').attr('title', '');
}
} else {
// hide the layer
if (window.plugin.zaprange.zapLayerEnlHolderGroup.hasLayer(window.plugin.zaprange.zapCircleEnlHolderGroup)) {
window.plugin.zaprange.zapLayerEnlHolderGroup.removeLayer(window.plugin.zaprange.zapCircleEnlHolderGroup);
$('.leaflet-control-layers-list span:contains("Zaprange Enlightened")').parent('label').addClass('disabled').attr('title', 'Zoom in to show those.');
}
if (window.plugin.zaprange.zapLayerResHolderGroup.hasLayer(window.plugin.zaprange.zapCircleResHolderGroup)) {
window.plugin.zaprange.zapLayerResHolderGroup.removeLayer(window.plugin.zaprange.zapCircleResHolderGroup);
$('.leaflet-control-layers-list span:contains("Zaprange Resistance")').parent('label').addClass('disabled').attr('title', 'Zoom in to show those.');
}
}
};
var setup = function () {
// this layer is added to the layer chooser, to be toggled on/off
window.plugin.zaprange.zapLayerEnlHolderGroup = new L.LayerGroup();
window.plugin.zaprange.zapLayerResHolderGroup = new L.LayerGroup();
// this layer is added into the above layer, and removed from it when we zoom out too far
window.plugin.zaprange.zapCircleEnlHolderGroup = new L.LayerGroup();
window.plugin.zaprange.zapCircleResHolderGroup = new L.LayerGroup();
window.plugin.zaprange.zapLayerEnlHolderGroup.addLayer(window.plugin.zaprange.zapCircleEnlHolderGroup);
window.plugin.zaprange.zapLayerResHolderGroup.addLayer(window.plugin.zaprange.zapCircleResHolderGroup);
// to avoid any favouritism, we'll put the player's own faction layer first
if (window.PLAYER.team === 'RESISTANCE') {
window.layerChooser.addOverlay(window.plugin.zaprange.zapLayerResHolderGroup, 'Zaprange Resistance');
window.layerChooser.addOverlay(window.plugin.zaprange.zapLayerEnlHolderGroup, 'Zaprange Enlightened');
} else {
window.layerChooser.addOverlay(window.plugin.zaprange.zapLayerEnlHolderGroup, 'Zaprange Enlightened');
window.layerChooser.addOverlay(window.plugin.zaprange.zapLayerResHolderGroup, 'Zaprange Resistance');
}
window.addHook('portalAdded', window.plugin.zaprange.portalAdded);
window.map.on('zoomend', window.plugin.zaprange.showOrHide);
window.plugin.zaprange.showOrHide();
};