Skip to content

Commit 6ab06c5

Browse files
committed
feat: add ajax request for blip data
Blips are not gotten from the server via ajax request to the URL that is set by the user.
1 parent f24ade7 commit 6ab06c5

File tree

4 files changed

+79
-37
lines changed

4 files changed

+79
-37
lines changed

index.php

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
// Set to false to enable the miinified versions of JS and CSS files
88
// that should speed up content delivery on production websites
99
$debug = true;
10+
11+
// Set to the IP of the GTA server that has live_map. Make sure it has the trailing slash (/)
12+
$gtaServer = "http://127.0.0.1:30120/";
13+
14+
// Set tpo the name of "live_map".
15+
// Note: If you change the folder name on the GTA server you NEED to change this
16+
$liveMapName = "live_map";
17+
18+
// Builds the url that we need to use in ajax requests to get the blips
19+
$blipUrl = $gtaServer . $liveMapName . "/blips.json";
1020
?>
1121

1222
<html>
@@ -82,6 +92,10 @@
8292
// Set to false if you don't want to show the player's identifiers (this may be their IP)
8393
var _SETTINGS_showIdentifiers = true;
8494

95+
<?php
96+
echo "var _SETTINGS_blipUrl = \"$blipUrl\";"
97+
?>
98+
8599
// Do not remove unless you know what you're doing (and you have a google api key)
86100
// Hack from https://stackoverflow.com/questions/38148097/google-maps-api-without-key/38809129#38809129
87101
// hack Google Maps to bypass API v3 key (needed since 22 June 2016 http://googlegeodevelopers.blogspot.com.es/2016/06/building-for-scale-updates-to-google.html)

js/src/controls.js

-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
var _invervalId;
2-
var _isLive = false;
3-
var _blips = [];
4-
var _blipCount = 0;
5-
var _showBlips = true;
6-
var _isConnected = false;
7-
var _trackPlayer = null;
81

92
function toggleBlips(){
103
console.log("showing local blips");

js/src/init.js

+65-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,79 @@
1+
var _invervalId;
2+
var _isLive = false;
3+
var _blips = [];
4+
var _blipCount = 0;
5+
var _showBlips = true;
6+
var _isConnected = false;
7+
var _trackPlayer = null;
8+
19
function globalInit() {
210
mapInit("map-canvas");
3-
initPage()
11+
initPage();
12+
initBlips();
413
}
514

615
function initPage() {
716
$(window).on("load resize", function() {
817
$(".map-tab-content").height((($("#tab-content").height() - $(".page-title-1").height()) - ($("#map-overlay-global-controls").height() * 4.2)))
9-
})
18+
});
19+
}
20+
21+
function createBlip(blip){
22+
var obj = new MarkerObject(blip.name, new Coordinates(blip.x, blip.y, blip.z), MarkerTypes[blip.type], blip.description, "", "");
23+
24+
_blips[_blipCount++] = blip;
25+
26+
createMarker(false, false, obj, "");
27+
}
28+
29+
function blipSuccess(data, textStatus){
30+
if (data.error){
31+
//Do something about the error i guess.
32+
console.error("Error: " + data.error);
33+
return;
34+
}
35+
36+
for (var spriteId in data) {
37+
if (data.hasOwnProperty(spriteId)) {
38+
// data[spriteId] == array of blips for that type
39+
var blipArray = data[spriteId];
40+
41+
for (var i in blipArray) {
42+
var blip = blipArray[i];
43+
blip.name = (blip.hasOwnProperty("name") || blip.name != undefined) ? blip.name : MarkerTypes[spriteId].name;
44+
blip.description = (blip.hasOwnProperty("description") || blip.description != undefined) ? blip.description : "";
45+
46+
blip.type = spriteId;
47+
48+
createBlip(blip);
49+
}
50+
}
51+
}
52+
53+
console.log(_blipCount + " blips created");
54+
$("#blip_count").text(_blipCount);
55+
56+
}
57+
58+
function blipError( textStatus, errorThrown){
59+
console.error("Error \"" + textStatus + "\": " + errorThrown);
60+
}
61+
62+
function initBlips(){
63+
_blipCount = 0;
64+
_blips = [];
65+
66+
console.log("Sending ajax request to " + _SETTINGS_blipUrl);
67+
$.ajax(_SETTINGS_blipUrl, {
68+
error: blipError,
69+
dataType: "json",
70+
success: blipSuccess
71+
});
1072
}
1173

1274
function initMarkers(debugOnly) {
1375
if (debugOnly) {
14-
createMarker(false, true, new MarkerObject("@DEBUG@@Locator", new Coordinates(0, 500, 0), MarkerTypes[999], "", ""), "")
76+
createMarker(false, true, new MarkerObject("@DEBUG@@Locator", new Coordinates(0, 500, 0), MarkerTypes[999], "", ""), "");
1577
console.log("MarkerType: " + MarkerTypes[999]);
1678
} else {
1779
createMarker(false, false, new MarkerObject("True Map Center", new Coordinates(0, 0, 0), MarkerTypes[6], "", ""), "");

js/src/socket.js

-27
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ function connect(){
2323
function onOpen(e){
2424
_isConnected = true;
2525
console.log("_isConnected: " + _isConnected);
26-
// Get blips?
27-
//TODO: Ajax request the blips
2826

2927
webSocket.send("getPlayerData"); // Get any players connected to the server
3028

@@ -103,31 +101,6 @@ function onClose(e){
103101
if (_isLive){
104102
clearInterval(_invervalId);
105103
}
106-
107-
}
108-
109-
function addBlip(blip, bool){
110-
//_blipCount++;
111-
}
112-
113-
function initBlips(blips){
114-
_blipCount = 0;
115-
_blips = [];
116-
clearAllMarkers();
117-
118-
if (_showBlips){
119-
blips.forEach(function(blip){
120-
var desc = blip.description == undefined ? "" : blip.description;
121-
var obj = new MarkerObject(blip.name, new Coordinates(blip.x, blip.y, blip.z), MarkerTypes[blip.type], desc, "", "");
122-
123-
_blips[_blipCount++] = blip;
124-
125-
createMarker(false, false, obj, "");
126-
});
127-
}
128-
129-
console.log(_blipCount + " blips created");
130-
$("#blip_count").text(_blipCount);
131104
}
132105

133106
var localCache = {};

0 commit comments

Comments
 (0)