Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit ee93943

Browse files
committed
- Add layer control for different groups of markers
1 parent 5f83911 commit ee93943

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

resources/js/Pages/Map/Index.vue

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ export default {
134134
clickedCoords: '',
135135
coordsCommand: '',
136136
afkPeople: '',
137-
openPopup: null
137+
openPopup: null,
138+
layers: {
139+
"Players": L.layerGroup(),
140+
"Dead Players": L.layerGroup(),
141+
"Vehicles": L.layerGroup(),
142+
"Blips": L.layerGroup(),
143+
}
138144
};
139145
},
140146
methods: {
@@ -296,6 +302,26 @@ export default {
296302
return coords;
297303
}
298304
},
305+
addToLayer(marker, layer) {
306+
const _this = this;
307+
308+
$.each(this.layers, function(key) {
309+
if (layer !== key) {
310+
_this.layers[key].removeLayer(marker);
311+
}
312+
});
313+
314+
this.layers[layer].addLayer(marker);
315+
},
316+
getLayer(isDriving, isPassenger, isInvisible, isDead) {
317+
if (isDriving || isPassenger) {
318+
return "Vehicles";
319+
} else if (isDead) {
320+
return "Dead Players";
321+
} else {
322+
return "Players";
323+
}
324+
},
299325
renderMapData(data) {
300326
if (this.isPaused) {
301327
return;
@@ -365,15 +391,15 @@ export default {
365391
}
366392
);
367393
368-
marker.addTo(_this.map);
369-
370394
marker.bindPopup('', {
371395
autoPan: false
372396
});
373397
374398
markers[id] = marker;
375399
}
376400
401+
_this.addToLayer(markers[id], _this.getLayer(isDriving, isPassenger, isInvisible, isDead));
402+
377403
let extra = '<br>Altitude: ' + Math.round(player.coords.z) + 'm';
378404
if (speed) {
379405
extra += '<br>Speed: ' + Math.round(speed * 2.236936) + ' mph';
@@ -535,6 +561,12 @@ export default {
535561
536562
this.map.setView([-124, 124], 3);
537563
564+
L.control.layers({}, this.layers).addTo(this.map);
565+
566+
$.each(this.layers, function(key) {
567+
_this.layers[key].addTo(_this.map);
568+
});
569+
538570
$.each(this.blips, function (_, blip) {
539571
const coords = eval('(() => (' + blip.coords + '))()'),
540572
coordsText = coords.x.toFixed(2) + ' ' + coords.y.toFixed(2);
@@ -550,11 +582,11 @@ export default {
550582
}
551583
);
552584
553-
marker.addTo(_this.map);
554-
555585
marker.bindPopup(blip.label + '<br><i>' + coordsText + '</i>', {
556586
autoPan: false
557587
});
588+
589+
_this.layers["Blips"].addLayer(marker);
558590
});
559591
560592
this.map.on('click', function (e) {

0 commit comments

Comments
 (0)