/*
* Class SVGMap
*
* @elementId - the html DOM id
*
*
* Requires project.js, heatmap.js
*/
var SVGMap = function(elementId, mapConf) {
var vBoxWidth = 1200,
vBoxHeight = 900,
bgWidth = 900,
bgHeight = 1500,
overlayID = "telemetry",
tooltip = new CustomTooltip(elementId + "-tooltip"),
clicked;
// Initialise the map
loadSvg();
function loadSvg() {
//block();
$.ajax({
url: mapConf.svgFile,
type: "GET",
data: {},
dataType: "xml",
async: false,
success: function(xml, textStatus, jqXHR) {
var importedNode;
try {
importedNode = document.importNode(xml.documentElement, true);
}
catch(e) {
// IE case
importedNode = ieImportNode(xml.documentElement, document);
}
$("#" + elementId).append(importedNode);
},
error: function (xhr, ajaxOptions, thrownError){
console.error(this.url + "\n" + ajaxOptions + " " + xhr.status + " " + thrownError );
},
complete: function() {
var svg = d3.select("#" + elementId + " svg")
.attr("width", $("#" + elementId).width())
.attr("height", $("#" + elementId).height())
.attr("enable-background", "new 0 0 " + bgWidth + " " + bgHeight)
.call(svg_interact);
drawGrid();
}
});
//unBlock();
}
function drawGrid() {
var gridStep = 500/mapConf.scale; // The step of the grid in map coordinates
var grid = d3.select("#" + elementId + " svg")
.append("svg:g")
.attr("id", "grid");
var xAxisDataNeg = d3.range(convert2WebXCoord(0), 0, -gridStep);
var xAxisDataPos = d3.range(convert2WebXCoord(0), bgWidth, gridStep);
var yAxisDataNeg = d3.range(convert2WebYCoord(0), 0, -gridStep);
var yAxisDataPos = d3.range(convert2WebYCoord(0), bgHeight, gridStep);
grid.selectAll("line.vertical")
.data(xAxisDataNeg.concat(xAxisDataPos))
.enter()
.append("svg:line")
.attr("x1", function(d) {return d;})
.attr("y1", 0)
.attr("x2", function(d) {return d;})
.attr("y2", bgHeight)
.attr("class", "map-grid");
grid.selectAll("line.horizontal")
.data(yAxisDataNeg.concat(yAxisDataPos))
.enter()
.append("svg:line")
.attr("x1", 0)
.attr("y1", function(d) {return d;})
.attr("x2", bgWidth)
.attr("y2", function(d) {return d;})
.attr("class", "map-grid");
}
function drawLayers(layersElementId) {
$("#" + layersElementId)
.append(
$("