From b9e3f41b759607aae6a11897819c7ca5e2101aaf Mon Sep 17 00:00:00 2001 From: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com> Date: Sun, 24 Jan 2021 23:52:34 +0200 Subject: [PATCH 01/18] Replace direct prototype manipulation by defining inenumerable properties instead --- [web]/ajax/json.js | 193 +++++++++++++++++++++++---------------------- 1 file changed, 100 insertions(+), 93 deletions(-) diff --git a/[web]/ajax/json.js b/[web]/ajax/json.js index e91078b1d..c5f12750a 100644 --- a/[web]/ajax/json.js +++ b/[web]/ajax/json.js @@ -59,148 +59,154 @@ if (!Object.prototype.toJSONString) { - Array.prototype.toJSONString = function () { - var a = [], // The array holding the member texts. - i, // Loop counter. - l = this.length, - v; // The value to be stringified. + Object.defineProperty(Array.prototype, 'toJSONString', { + enumerable: false, + value: function () { + let a = [], // The array holding the member texts. + i, // Loop counter. + l = this.length, + v; // The value to be stringified. // For each value in this array... - for (i = 0; i < l; i += 1) { - v = this[i]; - switch (typeof v) { - case 'object': + for (i = 0; i < l; i += 1) { + v = this[i]; + switch (typeof v) { + case 'object': // Serialize a JavaScript object value. Ignore objects thats lack the // toJSONString method. Due to a specification error in ECMAScript, // typeof null is 'object', so watch out for that case. - if (v) { - if (typeof v.toJSONString === 'function') { - a.push(v.toJSONString()); + if (v) { + if (typeof v.toJSONString === 'function') { + a.push(v.toJSONString()); + } + } else { + a.push('null'); } - } else { - a.push('null'); - } - break; + break; - case 'string': - case 'number': - case 'boolean': - a.push(v.toJSONString()); + case 'string': + case 'number': + case 'boolean': + a.push(v.toJSONString()); // Values without a JSON representation are ignored. + } } - } // Join all of the member texts together and wrap them in brackets. - return '[' + a.join(',') + ']'; - }; - - - Boolean.prototype.toJSONString = function () { - return String(this); - }; + return '[' + a.join(',') + ']'; + }, + }); + Object.defineProperty(Boolean.prototype, 'toJSONString', { + enumerable: false, + value: function () { + return String(this); + }, + }); - Date.prototype.toJSONString = function () { + Object.defineProperty(Date.prototype, 'toJSONString', { + enumerable: false, + value: function () { // Ultimately, this method will be equivalent to the date.toISOString method. - function f(n) { + function f(n) { // Format integers to have at least two digits. - return n < 10 ? '0' + n : n; - } - - return '"' + this.getFullYear() + '-' + - f(this.getMonth() + 1) + '-' + - f(this.getDate()) + 'T' + - f(this.getHours()) + ':' + - f(this.getMinutes()) + ':' + - f(this.getSeconds()) + '"'; - }; + return n < 10 ? '0' + n : n; + } + return '"' + this.getFullYear() + '-' + + f(this.getMonth() + 1) + '-' + + f(this.getDate()) + 'T' + + f(this.getHours()) + ':' + + f(this.getMinutes()) + ':' + + f(this.getSeconds()) + '"'; + }, + }); - Number.prototype.toJSONString = function () { + Object.defineProperty(Number.prototype, 'toJSONString', { + enumerable: false, + value: function () { // JSON numbers must be finite. Encode non-finite numbers as null. - return isFinite(this) ? String(this) : 'null'; - }; - + return isFinite(this) ? String(this) : 'null'; + }, + }); - Object.prototype.toJSONString = function () { - var a = [], // The array holding the member texts. - k, // The current key. - v; // The current value. + Object.defineProperty(Object.prototype, 'toJSONString', { + enumerable: false, + value: function () { + let a = [], // The array holding the member texts. + k, // The current key. + v; // The current value. // Iterate through all of the keys in the object, ignoring the proto chain. - for (k in this) { - if (this.hasOwnProperty(k)) { - v = this[k]; - switch (typeof v) { - case 'object': + for (k in this) { + if (this.hasOwnProperty(k)) { + v = this[k]; + switch (typeof v) { + case 'object': // Serialize a JavaScript object value. Ignore objects that lack the // toJSONString method. Due to a specification error in ECMAScript, // typeof null is 'object', so watch out for that case. - if (v) { - if (typeof v.toJSONString === 'function') { - a.push(k.toJSONString() + ':' + v.toJSONString()); + if (v) { + if (typeof v.toJSONString === 'function') { + a.push(k.toJSONString() + ':' + v.toJSONString()); + } + } else { + a.push(k.toJSONString() + ':null'); } - } else { - a.push(k.toJSONString() + ':null'); - } - break; + break; - case 'string': - case 'number': - case 'boolean': - a.push(k.toJSONString() + ':' + v.toJSONString()); + case 'string': + case 'number': + case 'boolean': + a.push(k.toJSONString() + ':' + v.toJSONString()); // Values without a JSON representation are ignored. + } } } - } // Join all of the member texts together and wrap them in braces. - return '{' + a.join(',') + '}'; - }; - - - (function (s) { - -// Augment String.prototype. We do this in an immediate anonymous function to -// avoid defining global variables. + return '{' + a.join(',') + '}'; + } + }); // m is a table of character substitutions. - var m = { - '\b': '\\b', - '\t': '\\t', - '\n': '\\n', - '\f': '\\f', - '\r': '\\r', - '"' : '\\"', - '\\': '\\\\' - }; - + const m = { + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }; - s.parseJSON = function (filter) { - var j; + Object.defineProperty(String.prototype, 'parseJSON', { + enumerable: false, + value: function (filter) { + let j; function walk(k, v) { - var i; + let i; if (v && typeof v === 'object') { for (i in v) { if (v.hasOwnProperty(i)) { @@ -242,11 +248,12 @@ if (!Object.prototype.toJSONString) { j = walk('', j); } return j; - }; - - - s.toJSONString = function () { + }, + }); + Object.defineProperty(String.prototype, 'toJSONString', { + enumerable: false, + value: function () { // If the string contains no control characters, no quote characters, and no // backslash characters, then we can simply slap some quotes around it. // Otherwise we must also replace the offending characters with safe @@ -254,7 +261,7 @@ if (!Object.prototype.toJSONString) { if (/["\\\x00-\x1f]/.test(this)) { return '"' + this.replace(/([\x00-\x1f\\"])/g, function (a, b) { - var c = m[b]; + let c = m[b]; if (c) { return c; } @@ -265,6 +272,6 @@ if (!Object.prototype.toJSONString) { }) + '"'; } return '"' + this + '"'; - }; - })(String.prototype); + }, + }); } From 25b2e7e2c2944d873d1e6889095e25119bf0752c Mon Sep 17 00:00:00 2001 From: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com> Date: Sun, 24 Jan 2021 23:53:32 +0200 Subject: [PATCH 02/18] Change OpenLayers tilecache source --- [web]/webmap/script.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/[web]/webmap/script.js b/[web]/webmap/script.js index 99d5df4d3..09835057e 100644 --- a/[web]/webmap/script.js +++ b/[web]/webmap/script.js @@ -14,18 +14,18 @@ var bliplist = new Object; function init() { - map = new OpenLayers.Map( $('map'), {'maxResolution': 360/512, 'maxExtent':new OpenLayers.Bounds(-90.0,-90.0,90.0,90.0), - 'numZoomLevels':6, + map = new OpenLayers.Map( 'map', {'maxResolution': 1, 'maxExtent':new OpenLayers.Bounds(-90.0,-90.0,90.0,90.0), + 'numZoomLevels':8, }); map.addControl(new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')})); - maplayer = new OpenLayers.Layer.WMS( "San Andreas Map", - "http://code.opencoding.net/tilecache/tilecache.cgi?", {layers: 'sa_map', format: 'image/png' } ); - map.addLayer(maplayer); + // maplayer = new OpenLayers.Layer.WMS( "San Andreas Map", + // "http://code.opencoding.net/tilecache/tilecache.cgi?", {layers: 'sa_map', format: 'image/png' } ); + // map.addLayer(maplayer); - aeriallayer = new OpenLayers.Layer.WMS( "San Andreas Aerial Map", - "http://code.opencoding.net/tilecache/tilecache.cgi?", {layers: 'sa_aerial_map', format: 'image/png' } ); + aeriallayer = new OpenLayers.Layer.XYZ( "San Andreas Aerial Map", + "https://community.mtasa.blue/tilecache/${z}_${x}_${y}.jpg" ); map.addLayer(aeriallayer); map.zoomTo(2); From 6e61c775b52dffaaa98af1c19fd6f02d6208b993 Mon Sep 17 00:00:00 2001 From: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com> Date: Sun, 24 Jan 2021 23:57:23 +0200 Subject: [PATCH 03/18] Add sea color as background color --- [web]/webmap/css.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/[web]/webmap/css.css b/[web]/webmap/css.css index bc6dfb823..53fdb57dc 100644 --- a/[web]/webmap/css.css +++ b/[web]/webmap/css.css @@ -12,7 +12,7 @@ body { padding: 0px; - background: #FFFFFF; + background: #00789d; font: bold 1em "Trebuchet MS", Arial, sans-serif; } #map { From 3dc77d90eac58945349246baa9a35ec67b924622 Mon Sep 17 00:00:00 2001 From: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com> Date: Mon, 25 Jan 2021 18:11:45 +0200 Subject: [PATCH 04/18] Use the old maxResolution --- [web]/webmap/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/[web]/webmap/script.js b/[web]/webmap/script.js index 09835057e..1583256d6 100644 --- a/[web]/webmap/script.js +++ b/[web]/webmap/script.js @@ -14,7 +14,7 @@ var bliplist = new Object; function init() { - map = new OpenLayers.Map( 'map', {'maxResolution': 1, 'maxExtent':new OpenLayers.Bounds(-90.0,-90.0,90.0,90.0), + map = new OpenLayers.Map( 'map', {'maxResolution': 360/512, 'maxExtent':new OpenLayers.Bounds(-90.0,-90.0,90.0,90.0), 'numZoomLevels':8, }); From 02b42865d94d3341558f0291345d069dab6a2a93 Mon Sep 17 00:00:00 2001 From: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com> Date: Mon, 25 Jan 2021 18:11:59 +0200 Subject: [PATCH 05/18] Use aeriallayer when adding feature --- [web]/webmap/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/[web]/webmap/script.js b/[web]/webmap/script.js index 1583256d6..569e7a3da 100644 --- a/[web]/webmap/script.js +++ b/[web]/webmap/script.js @@ -42,7 +42,7 @@ function init() function addPlayerMarker(player) { - var feature = new OpenLayers.Feature(maplayer, gtaCoordToLonLat(player.pos.x, player.pos.y), {icon:playericon.clone()}); + var feature = new OpenLayers.Feature(aeriallayer, gtaCoordToLonLat(player.pos.x, player.pos.y), {icon:playericon.clone()}); var marker = feature.createMarker(); marker.playerName = player.name; marker.feature = feature; @@ -53,7 +53,7 @@ function addPlayerMarker(player) function addBlipMarker(blip) { - var feature = new OpenLayers.Feature(maplayer, gtaCoordToLonLat(blip.pos.x, blip.pos.y), {icon:radaricons[blip.icon].clone()}); + var feature = new OpenLayers.Feature(aeriallayer, gtaCoordToLonLat(blip.pos.x, blip.pos.y), {icon:radaricons[blip.icon].clone()}); var marker = feature.createMarker(); marker.element = blip.element; marker.feature = feature; From 19671287ea62a504aa1cc53c63c0e8e79a8a6839 Mon Sep 17 00:00:00 2001 From: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com> Date: Mon, 25 Jan 2021 18:12:13 +0200 Subject: [PATCH 06/18] Tweak mapx mapy in coord calc --- [web]/webmap/script.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/[web]/webmap/script.js b/[web]/webmap/script.js index 569e7a3da..476eb0c65 100644 --- a/[web]/webmap/script.js +++ b/[web]/webmap/script.js @@ -64,16 +64,16 @@ function addBlipMarker(blip) // Takes a GTA x and y and returns a x and y on the map function gtaCoordToMap(x, y) { - var mapx = x * 0.03; - var mapy = y * 0.03; + var mapx = x * 0.03185; + var mapy = y * -0.015; return {x: mapx, y: mapy}; } // Takes a GTA x and y and returns a LonLat function gtaCoordToLonLat(x, y) { - var mapx = x * 0.03; - var mapy = y * 0.03; + var mapx = x * 0.03185; + var mapy = y * -0.015; return new OpenLayers.LonLat(mapx,mapy); } From 14c1e6f67ebb94278a785263e12fce7e647d6801 Mon Sep 17 00:00:00 2001 From: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com> Date: Mon, 25 Jan 2021 18:23:23 +0200 Subject: [PATCH 07/18] Fix map missing in feature or marker for some reason --- [web]/webmap/script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/[web]/webmap/script.js b/[web]/webmap/script.js index 476eb0c65..82feb6895 100644 --- a/[web]/webmap/script.js +++ b/[web]/webmap/script.js @@ -48,6 +48,8 @@ function addPlayerMarker(player) marker.feature = feature; marker.events.register("mousedown", marker, showplayerinfo); playermarkers.addMarker(marker); + feature.map = map; + marker.map = map; return feature; } @@ -58,6 +60,8 @@ function addBlipMarker(blip) marker.element = blip.element; marker.feature = feature; blipmarkers.addMarker(marker); + feature.map = map; + marker.map = map; return feature; } From 9ed66a18bac09c83fef689dac2368d80efa51bb5 Mon Sep 17 00:00:00 2001 From: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com> Date: Tue, 26 Jan 2021 20:27:44 +0200 Subject: [PATCH 08/18] Update source urls --- [web]/webmap/script.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/[web]/webmap/script.js b/[web]/webmap/script.js index 82feb6895..d98473ace 100644 --- a/[web]/webmap/script.js +++ b/[web]/webmap/script.js @@ -15,18 +15,22 @@ var bliplist = new Object; function init() { map = new OpenLayers.Map( 'map', {'maxResolution': 360/512, 'maxExtent':new OpenLayers.Bounds(-90.0,-90.0,90.0,90.0), - 'numZoomLevels':8, + 'numZoomLevels':5, }); map.addControl(new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')})); - // maplayer = new OpenLayers.Layer.WMS( "San Andreas Map", - // "http://code.opencoding.net/tilecache/tilecache.cgi?", {layers: 'sa_map', format: 'image/png' } ); - // map.addLayer(maplayer); + maplayer = new OpenLayers.Layer.XYZ( "San Andreas Map", + "https://assets.mtasa.com/mtasa-resources/webmap/sa_map/v1/${z}_${x}_${y}.jpg" ); + map.addLayer(maplayer); - aeriallayer = new OpenLayers.Layer.XYZ( "San Andreas Aerial Map", - "https://community.mtasa.blue/tilecache/${z}_${x}_${y}.jpg" ); - map.addLayer(aeriallayer); + aeriallayerv1 = new OpenLayers.Layer.XYZ( "San Andreas Aerial Map", + "https://assets.mtasa.com/mtasa-resources/webmap/sa_aerial_map/v1/${z}_${x}_${y}.jpg" ); + map.addLayer(aeriallayerv1); + + aeriallayerv2 = new OpenLayers.Layer.XYZ( "San Andreas Aerial Map V2", + "https://assets.mtasa.com/mtasa-resources/webmap/sa_aerial_map/v2/${z}_${x}_${y}.jpg" ); + map.addLayer(aeriallayerv2); map.zoomTo(2); @@ -42,7 +46,7 @@ function init() function addPlayerMarker(player) { - var feature = new OpenLayers.Feature(aeriallayer, gtaCoordToLonLat(player.pos.x, player.pos.y), {icon:playericon.clone()}); + var feature = new OpenLayers.Feature(maplayer, gtaCoordToLonLat(player.pos.x, player.pos.y), {icon:playericon.clone()}); var marker = feature.createMarker(); marker.playerName = player.name; marker.feature = feature; @@ -55,7 +59,7 @@ function addPlayerMarker(player) function addBlipMarker(blip) { - var feature = new OpenLayers.Feature(aeriallayer, gtaCoordToLonLat(blip.pos.x, blip.pos.y), {icon:radaricons[blip.icon].clone()}); + var feature = new OpenLayers.Feature(maplayer, gtaCoordToLonLat(blip.pos.x, blip.pos.y), {icon:radaricons[blip.icon].clone()}); var marker = feature.createMarker(); marker.element = blip.element; marker.feature = feature; From 0286aefea00e8e63cd11beee868edf076583bc0c Mon Sep 17 00:00:00 2001 From: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com> Date: Wed, 27 Jan 2021 23:49:57 +0200 Subject: [PATCH 09/18] Tweak map position and size --- [web]/webmap/css.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/[web]/webmap/css.css b/[web]/webmap/css.css index 53fdb57dc..a44a5f0f6 100644 --- a/[web]/webmap/css.css +++ b/[web]/webmap/css.css @@ -17,14 +17,14 @@ body { #map { width: 100%; - height: 99%; + height: 100%; } #mainarea { position: absolute; left: 0px; top: 37px; - bottom: 5px; + bottom: 0; right: 5px; } From 6b8ced9aaeff588e6a40b9a80ac7fed06d8dd41d Mon Sep 17 00:00:00 2001 From: patrikjuvonen <22572159+patrikjuvonen@users.noreply.github.com> Date: Wed, 27 Jan 2021 23:52:29 +0200 Subject: [PATCH 10/18] Use html5 --- [web]/webmap/map.htm | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/[web]/webmap/map.htm b/[web]/webmap/map.htm index 45399b5c6..495c03d79 100644 --- a/[web]/webmap/map.htm +++ b/[web]/webmap/map.htm @@ -1,22 +1,26 @@ - - + +
+ + + +