If you just need the coordinates, use Ajax to read a .json
File. Then you could execute the function above with your data.
JSON Example:
[[784,457],[759,989]] <- your coordinates
Ajax call:
function loadJSON() {
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
render(xmlhttp.responseText) //render your map with the response
}
}
xmlhttp.open("GET", "your_json_file.json", true);
xmlhttp.send();
}
The render()
function:
function render(response){
var json = JSON.parse(response); //parse the response to json
ctx.fillStyle="rgb(255,255,255)";
ctx.beginPath();
ctx.moveTo(json[0][0],json[0][1]);
ctx.lineTo(json[1][0],json[1][1]);
ctx.fill();
}
Or if you realy just want to eval your functions, execute the eval() function on your Ajax Response:
eval(xmlhttp.responseText);
but remember that this is very uncertain!