Skip to content
This repository was archived by the owner on Apr 16, 2025. It is now read-only.

Commit b15938f

Browse files
committed
fix: blip controls breaking when switching servers
They no longer break when swicthing servers.
1 parent d1cc408 commit b15938f

File tree

6 files changed

+66
-67
lines changed

6 files changed

+66
-67
lines changed

dist/first-bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/last-bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/src/controls.2.js

Lines changed: 44 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,50 @@
1717
// ************************************************************************** //
1818

1919
function toggleBlips(){
20-
console._log("showing local blips");
21-
if (_showBlips){
22-
23-
for(var spriteId in _blips){
24-
var blipArray = _blips[spriteId];
25-
//console._log("Disabled (" + spriteId + ")? " + _disabledBlips.includes(spriteId));
26-
27-
if(_disabledBlips.indexOf(spriteId) != -1){
28-
if(_SETTINGS_debug){
29-
console._log("Blip " + spriteId + "'s are disabled..");
30-
}
31-
// If disabled, don't make a marker for it
32-
continue;
33-
}
3420

35-
for(var i in blipArray){
36-
var blip = blipArray[i];
21+
clearAllMarkers();
22+
if(!_showBlips){
23+
return;
24+
}
3725

38-
var obj = new MarkerObject(blip.name, new Coordinates(blip.pos.x, blip.pos.y, blip.pos.z), MarkerTypes[blip.type], blip.description, "", "");
39-
blip.markerId = createMarker(false, false, obj, "") - 1;
40-
}
26+
for (var spriteId in _blips) {
27+
var blipArray = _blips[spriteId];
28+
console._log("Disabled (" + spriteId + ")? " + _disabledBlips.includes(spriteId));
29+
30+
if (_disabledBlips.indexOf(spriteId) != -1) {
31+
console._log("Blip " + spriteId + "'s are disabled..");
32+
// If disabled, don't make a marker for it
33+
continue;
4134
}
4235

43-
}else{
44-
clearAllMarkers();
36+
for (var i in blipArray) {
37+
var blip = blipArray[i];
38+
39+
var obj = new MarkerObject(blip.name, new Coordinates(blip.pos.x, blip.pos.y, blip.pos.z), MarkerTypes[blip.type], blip.description, "", "");
40+
blip.markerId = createMarker(false, false, obj, "") - 1;
41+
}
4542
}
43+
4644
}
4745

4846
$(document).ready(function(){
4947
globalInit();
5048

49+
// Toggle blip
50+
$("#showBlips").click(function(e){
51+
e.preventDefault();
52+
53+
_showBlips = !_showBlips;
54+
55+
//webSocket.send("getBlips");
56+
toggleBlips();
57+
58+
$("#blips_enabled").removeClass("badge-success").removeClass("badge-danger")
59+
.addClass( _showBlips ? "badge-success" : "badge-danger")
60+
.text(_showBlips ? "on" : "off");
61+
});
62+
63+
5164
$("#playerSelect").on("change", function(){
5265
if (this.value == ""){
5366
_trackPlayer = null;
@@ -60,30 +73,16 @@ $(document).ready(function(){
6073

6174
$("#refreshBlips").click(function(e){
6275
e.preventDefault();
63-
if (_showBlips){
64-
clearAllMarkers();
65-
initBlips();
66-
}
76+
77+
clearAllMarkers();
78+
initBlips(connectedTo.getBlipUrl());
6779
});
6880

6981
$("#server_menu").on("click", ".serverMenuItem", function(e){
7082
console._log($(this).text());
7183
changeServer($(this).text());
7284
});
7385

74-
$("#showBlips").click(function(e){
75-
e.preventDefault();
76-
77-
_showBlips = !_showBlips;
78-
79-
//webSocket.send("getBlips");
80-
toggleBlips();
81-
82-
$("#blips_enabled").removeClass("badge-success").removeClass("badge-danger")
83-
.addClass( _showBlips ? "badge-success" : "badge-danger")
84-
.text(_showBlips ? "on" : "off");
85-
});
86-
8786
$("#reconnect").click(function(e){
8887
e.preventDefault();
8988

@@ -97,25 +96,26 @@ $(document).ready(function(){
9796
});
9897

9998
$("#toggle-all-blips").on("click", function(){
99+
_blipControlToggleAll = !_blipControlToggleAll;
100+
console._log(_blipControlToggleAll +" showing blips?");
100101
// Toggle the classes and add/remove the blipIds from the array
102+
101103
$("#blip-control-container").find("a").each(function(index, ele){
102104
var ele = $(ele);
103-
var blipId = ele.data("blipNumber").toString();
105+
var blipId = ele.data("blip-number").toString();
104106

105-
// Toggle blip
106-
if(_disabledBlips.includes(blipId)){
107-
// Already disabled, enable it
107+
if (_blipControlToggleAll){
108+
// Showing them
108109
_disabledBlips.splice(_disabledBlips.indexOf(blipId), 1);
109110
ele.removeClass("blip-disabled").addClass("blip-enabled");
110111
}else{
111-
// Enabled, disable it
112+
// Hiding them all
112113
_disabledBlips.push(blipId);
113114
ele.removeClass("blip-enabled").addClass("blip-disabled");
114115
}
115116
});
116117

117118
// Now we can refresh the markers
118-
clearAllMarkers();
119119
toggleBlips();
120120
});
121121
});
@@ -159,15 +159,6 @@ function initControls(Map, PlayerMarkers){
159159
Map.fitBounds(mapBounds);
160160
CurrentLayer = e.layer;
161161

162-
Map.removeLayer(PlayerMarkers); // Remove the cluster layer
163-
window.PlayerMarkers = L.markerClusterGroup({ // Re-make it fresh
164-
maxClusterRadius: 20,
165-
spiderfyOnMaxZoom: false,
166-
showCoverageOnHover: false,
167-
zoomToBoundsOnClick: false
168-
});
169-
Map.addLayer(PlayerMarkers); // Add it back. The clearAllMarkers() will ensure player markers are added to the new cluster layer
170-
171162
clearAllMarkers();
172163
toggleBlips();
173164
});

js/src/init.1.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ var _trackPlayer = null;
3434
var playerCount = 0;
3535
var _overlays = [];
3636
var _disabledBlips = [];
37+
var _blipControlToggleAll = true; // Show all by default
38+
3739
window.changeServer = function (nameOfServer) {
3840
console._log("Changing connected server to: " + nameOfServer);
41+
3942
if (!(nameOfServer in config.servers)) {
4043
createAlert({
4144
title: "<strong>Couldn't load server config!</strong>",
@@ -61,7 +64,6 @@ window.changeServer = function (nameOfServer) {
6164
}
6265

6366
// If we've changed servers. Might as well reset everything.
64-
clearAllMarkers();
6567
if (window.webSocket && window.webSocket.readyState == WebSocket.OPEN) window.webSocket.close();
6668

6769
$("#server_name").text(nameOfServer);
@@ -217,7 +219,7 @@ function blipSuccess(data, textStatus){
217219

218220
console._log(_blipCount + " blips created");
219221
$("#blip_count").text(_blipCount);
220-
222+
toggleBlips();
221223
}
222224

223225
function blipError( textStatus, errorThrown){

js/src/map.1.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ function createMarker(animated, draggable, objectRef, title) {
8787
var infoContent = '<div class="info-window"><div class="info-header-box"><div class="info-header">' + name + '</div></div><div class="clear"></div><div class=info-body>' + html + "</div></div>";
8888

8989
var image = L.icon(markerType);
90-
//console._log(image);
91-
//console._log("image: " + JSON.stringify(image));
9290

9391
var where = Map;
9492
if(objectRef.data && objectRef.data.isPlayer){
@@ -121,15 +119,25 @@ function setMapCenterLeaflet(coord) {
121119

122120
function clearAllMarkers() {
123121
for (var i = 0; i < MarkerStore.length; i++) {
124-
if (MarkerStore[i] != "NULL") {
125-
MarkerStore[i].remove();
126-
}
122+
clearMarker(i);
127123
}
128124
MarkerStore.length = 0;
125+
129126
// Re-do player markers
130127
for(var id in localCache){
131128
localCache[id].marker = null;
132129
}
130+
if(Map != undefined){
131+
Map.removeLayer(window.PlayerMarkers); // Remove the cluster layer
132+
133+
window.PlayerMarkers = L.markerClusterGroup({ // Re-make it fresh
134+
maxClusterRadius: 20,
135+
spiderfyOnMaxZoom: false,
136+
showCoverageOnHover: false,
137+
zoomToBoundsOnClick: false
138+
});
139+
Map.addLayer(window.PlayerMarkers); // Add it back. The clearAllMarkers() will ensure player markers are added to the new cluster layer
140+
}
133141
}
134142

135143
function clearMarker(id) {

js/src/markers.1.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,16 @@ function generateBlipControls(){
246246
}
247247
}
248248

249-
// Events
250-
$(".blip-button-a").on("click", function(e){
249+
$(".blip-button-a").on("click", function (e) {
251250
var ele = $(e.currentTarget);
252251
var blipId = ele.data("blipNumber").toString();
253252

254253
// Toggle blip
255-
if(_disabledBlips.includes(blipId)){
254+
if (_disabledBlips.includes(blipId)) {
256255
// Already disabled, enable it
257256
_disabledBlips.splice(_disabledBlips.indexOf(blipId), 1);
258257
ele.removeClass("blip-disabled").addClass("blip-enabled");
259-
}else{
258+
} else {
260259
// Enabled, disable it
261260
_disabledBlips.push(blipId);
262261
ele.removeClass("blip-enabled").addClass("blip-disabled");
@@ -266,7 +265,6 @@ function generateBlipControls(){
266265
clearAllMarkers();
267266
toggleBlips();
268267
});
269-
270268
}
271269

272270
function generateBlipShit(){

0 commit comments

Comments
 (0)