I will go staright to the point !!
I have a webpage that displays a map ,the user diffines some points and it returns a route between these points and also at the page i create a table dynamically with javascript to show the length and the name of the streets ,but i found that the creation of the table is CPU intense at google crome it consumes 102 CPU . The data to create my table are taken for a postgresSQL database . Is there any other way to still use the dynamic table but be less CPU consuming ?
I wasn't sure if i should post this here or under Web Development but since i will post and the code for the table i disided to post it under Javascript
function executeURL(){
Json_layers[How_many_layers]=json_layer = new OpenLayers.Layer.Vector('Route');
json_layer.styleMap = myStyles;
document.getElementById("mytable").innerHTML = "";
var root=null;
var tab=null;
var tbo=null;
var row=null;
var cell=null;
OpenLayers.Request.GET({
url: json_url,
success: function(e) {
var reader = new OpenLayers.Format.GeoJSON();
segments =e.responseText;
root = document.getElementById('mytable');
tab = document.createElement('table');
tab.className="table";
tbo = document.createElement('tbody');
for(var i=0;i<segments.split('name').length-1;i++){
var name = reader.read(segments)[i].attributes.name;
var length = reader.read(segments)[i].attributes.length;
row=document.createElement('tr');
for(var j=0;j<2;j++){
cell=document.createElement('td');
if(j==0){
if(!isBlank(name)){
cell.appendChild(document.createTextNode(name));
}else{
cell.appendChild(document.createTextNode("Ανόνυμη οδός"));
}
}else{
cell.appendChild(document.createTextNode(Number(length).toFixed(0)+ " μέτρα") );
total_length_m += parseFloat(length);
}
row.appendChild(cell);
}
tbo.appendChild(row);
}
tab.appendChild(tbo);
root.appendChild(tab);
document.getElementById('length').innerHTML="Το οληκό μήκος της διαδρομής είναι :"+Number(total_length_m).toFixed(0)+ " meters";
document.getElementById('length').style.display='block';
total_length_m=0;
var features = new OpenLayers.Format.GeoJSON().read(e.responseText);
for(var i= 0; i < features.length; i++){
features[i].geometry.transform(
new OpenLayers.Projection("EPSG:4326"),
new OpenLayers.Projection("EPSG:900913")
);
}
json_layer.addFeatures(features);
}
});
segments='';
How_many_layers++;
}
Any suggestions would be appriciated and please explain with as much detail as possible :-)
Thanks in advance !!!

New Topic/Question
Reply



MultiQuote





|