Javascript:
$(document).ready(function() {
var systemsInfo = 'https://raw.githubusercontent.com/joeberthelot88/EVE-Online-Mapper/master/eveSystems.json?token=AWUj7mQ8T_6NBaRgIcz4Xz0KQd1SazMUks5ZjpeAwA%3D%3D';
var constellationsList = [20000441, 20000442, 20000443, 20000444, 20000445, 20000446, 20000447];
var arrayXCoords = [];
var arrayYCoords = [];
$.getJSON(systemsInfo, function(data) {
data.forEach(function(sysData) {
// Extract information and create elements for objects found in constellations list
if(constellationsList.indexOf(sysData.constellation_id) > -1) {
// Simplify location coordinates
var xCoord = sysData.position.x / 100000000000000;
var yCoord = sysData.position.y / 100000000000000;
// Store coordinates in arrays
arrayXCoords.push(xCoord);
arrayYCoords.push(yCoord);
// Get the lowest coordinate values
var offsetXValue = Math.min.apply(Math, arrayXCoords);
var offsetYValue = Math.min.apply(Math, arrayYCoords);
// Set pixel offsets to center in the viewport
var updatedCoordX = xCoord + offsetXValue;
var updatedCoordY = yCoord + offsetYValue;
// Create SVG elements
var svgelement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svgelement.setAttribute('id', sysData.name);
svgelement.setAttribute('title', sysData.name);
svgelement.setAttribute('class', 'system');
svgelement.setAttribute('constellation-id', sysData.constellation_id);
svgelement.setAttribute('style', 'margin-top:'+updatedCoordY+'px;margin-left:'+updatedCoordX+'px');
svgelement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink");
document.getElementById('container').appendChild(svgelement);
} else {
}
});
});
$(this.body).panzoom();
});
Functionality Explanation:
- Iterates through a JSON object
- Checks each object for matches containing the constellation_id
- If match is found, adds coordinates to an array and stores the lowest coordinate values in variables
- Creates an SVG element during each iteration
Challenge:
When creating the SVG elements, the CSS margins are set using coordX
and coordY
variables. I need to substitute these with the new offsetX
and offsetY
variables, but this doesn't work as the offsetX and offsetY values are not finalized yet due to the ongoing construction of arrayXCoords and arrayYCoords.
In essence, I have to establish the offsetX and offsetY variables first before proceeding with the SVG creation process.