0
On another topic I did a question and a friend of the site helped me.
I tried to use the function with the truncated file, however the result was:
Code that I used:
<script>
function dec(string)
{// retorna a matris pura, descompactada
var myArray = [];
var str, str2, arr, arr2, lat, lng, f;
var strings = string.split(" ");
for (var i in strings)
{
str = strings[i];
str2 = '';
arr = [];
arr2 = [];
for (var j=0; j<str.length; j++)
{
switch (str.charAt(j))
{
case 'A': str2 += ',0'; break;
case 'B': str2 += ',1'; break;
case 'C': str2 += ',-1'; break;
case 'D': str2 += ',2'; break;
case 'E': str2 += ',-2'; break;
case 'F': str2 += ',3'; break;
case 'G': str2 += ',-3'; break;
case 'H': str2 += ',4'; break;
case 'I': str2 += ',-4'; break;
case 'J': str2 += ',5'; break;
case 'K': str2 += ',-5'; break;
case 'L': str2 += ',6'; break;
case 'M': str2 += ',-6'; break;
case 'N': str2 += ',7'; break;
case 'O': str2 += ',-7'; break;
case 'P': str2 += ',8'; break;
case 'Q': str2 += ',-8'; break;
case 'R': str2 += ',9'; break;
case 'S': str2 += ',-9'; break;
default: str2 += str.charAt(j); break;
}
}
arr = str2.split(",");
f = arr.shift();
lng = parseInt(arr[0])/f;
lat = parseInt(arr[1])/f;
arr2.push([lat, lng]);
for (var j=2; j<arr.length; j+=2)
{
lng += parseInt(arr[j])/f;
lat += parseInt(arr[j+1])/f;
arr2.push([lat, lng]);
}
myArray.push(arr2);
}
document.write(myArray);
return myArray;
}
dec('{shapes:{3550308:"1000I6575E3374BCBAACBABABABABBABBAABBBABBAABBABBDABAABBBABBAABBAABBABAABBBABBAABBBABBBBAABBAACBABCBABAABBABCBAACBCACBABAACBABAACBAAAACCAACCCACBCACACCACCCCCAACCCCCCACAACACACACACACACACACACCCACAACAACCCCCCCCCCACCACCCACCACCACACACBAACACACCAACACCAACACBAACACACCACCCACAACCACAACAACAACCACAACCACAACACBAACAAACACACCAACBCAAACACACACACACCAACACCAACACBAACACBAACBAACACACACACACCACAACACACACACCAACACCAACBAACACCAACCAACACACCCACACBAACBAACACACBAACACBAACBAACACBCBCBCACBAACACACBAACACACACACACACACACACACACACBCACACACACACCEACCEACACBAACACBAACBAACACAAACACBABCBAACBAABBBBABBBABABABABAABBABBBAABBBBBABBAABBBBBBBBABBBAABBBABBABAABBABABAABBAABBABBABBBBAABBBBAABBABABBABBABABBBABBBABAABBABABABBBABABABAABBABABABABABABABBBABABABCBABABAACBABBBABADABABABABABCBABABABCBABCBABCBABAACBABABAACBABABABABABABBACBABABBBABABABABAABBABABABABBBABABAABBAACBABABABAABBABAABCBABBABABAACBCBAABCAABBABAABABABBABAABBABABCBABABABAACBABAAAABBABBACBAACBABAABCAABBAABBABAABBABAACACBABAACCCCAACBABAACACBCBAABABBAACACBACCCABCBAACCACAACACCAACACBAACBABAABBAACBAACBAABABBAABABBABCBABAABBAABBAABBABABABAACBABABAABABBAABCAABABABBAABAAAABAACBAABAAABABBAABBAACACBAACACBAACACBAACBAACCAACBAACACACBAACBAACACBAACBCACBAACBAACACBAACBAACACACBAACACBAACBAACACBAACBAACACACACCAACACACACACCACACACBCACACAACCACCACBAACCAACCACACACACAACCACAACCAACACACCACACCAAACBABAACCAACCAACCACAACCAACCAACCAACCAACCBCACAACAAACBAACACACACACACBAACBCACBABAACBCACBAACACACCCCAECCACACAAEBCBAACACBACCACBAACAAACACBAACBABCBABAACBABABCBABABABAAAACACECCCACAAACCABCCCBAACBABAACACBABABAACACCACCCACACCCAACACBABCBAACACBAACACBCACBAACACBAACCAABCAABCAACCAACCAACCCACACACCAACACACBAACACCAACCACACACACACCCCCAABCACACACAACCCCCCAACAAACACBABCBAACBCACACACCAACCCCAACACACCAACCAACCAACCACCCACACACAACACCAACACBCACACACACCAACCACACCCCCACAACACACCAACACCACAACCACACACAACACACCACACAABABABABCACBABCAABCACACBCCCAACACACBAACCAACCACACACBCCCACACACACCCCCACACACACBCACACAABCACAABCACACACAACCACAABCACAABCAABCACACAABCAACCBACCACACACACACAABABCAABABCAABABCAABAAABAAABCAABABABABCAABCCABCACBCACACACAABCACAACCACACAACCAABCACCCACAABCAACCACAABCACACAACCACACCCACACAABCACBCAABCAABCAABABCAABCAABCACACACBABCACBCAABCACACACACACACACACACAACCBCACACACAABCACBCAABCACAABCACBCAABCAABCAABCACACACACAACCAACCAACCCACCACCCACACBCACBCBCACBCAABCACBCAABCAABCACAABCACBCBCACACAABCACAACACACACACACCAACACACAECCACAEAECEACACACCCAEACACBAACBAACACCCACACCACAACCAACACBCACAEACBACCACACCAACACCACCCAACCAACCACAACCACAACCACAACCAACCACACACAACCACAACCAACCACACACAACCACCCAACCACACAACCACAABCAABCAABCCEAACCCCAACCACBCAABCAACACCCACACACACACACACCAACACCACAACCAACACACACACBAACACCCCAACCAACCAACBAACACACCCACCCCCACBABABAACACBAACACACACBABABCACACBAACBAACBCBBBAACACACACBAABBCACBABABABAACBAACACBAACCAACCAACCAACCACAACCACACCCACACACCCCCCCCCCCCCCCCCAACCAACCACAACCAECCAECCAEACCCACCCABKBAAEBEACDSAEAEBEBCBEDELOBEFGDGJKACBCBCACACAGAC2ACACACACAKACACACACCCAEAECAACCCCCCAACCAACEECCCCCCACACACACACCEAGAGBEBOBEBCDCDADEDCDCDEDCACAEACACACACACACBCACACACACACACCAACACACACAECAACACACACACBCACBCCCBEBCCCBCACACACBAACACACACBAACHBEECCCAACACBAACACACACDAACBAACACCAACACBCACACACACCACAACBCBCACCACACAACACCAACCAAAEACAACACACBCACACBABABCDABBDAACBAACCCACCAACBCBECCBCCAACACCACAACCAACDEBAACBAACACACACCAACAAACCACAACBABACCBCACCCCACAACAACCACACACCAABABCACBCAACCACACCACCAACCACACACACAACCACACAACCCABCAACAACAACCAACCACAACCACAACBAACACACBCACBAACACACACACBAACBAACBABAACCAACCACACACCACCCCACBCAACCAACACCAACCACACAACCACACACCCACCCAAACAABCBABCBABCACAABCBABCACBCACAABABCBCBCACACACACACACCCACACACACACACACACBCACAABCAABCBABABCAABCACACCACCACCCACBCACACCACCAACCACCCAACCAACCACACCCACCCAABCACACACACCACCACCCACAACCAACCACACACACBCAABABCACACCCACACACACCCACACACACACAABCACBCAABCACACACACACACAACACCACACACACACAACBAACCACAAACACACACCCAACACCAACCCCCACCACACCACACCACACACAABCAACCAACCCCACACAABABCACAABABCAABBAABBABBBAABBABAABBAABABABBBABBBCBBAABBBABBAABBABAABABBAABBAABABABBAABBAABCAABABBABAABBAABBAABABABABCACAACCAABCAABCBCBCAABCAABCAABBAABABABCBCACBCACCCAABCACACAABCBCBABCAABABBAABCBABBBABCACACACACBCACAABCAABCACAABBAABCAABCAABCBCACBCACAACCAACCACACACBCBABCAABCACAABCACACACACACCCACBABABABABCBABABABABABCBABCBABABABABCBABABBACBCAABBAABABCAABABBAABCAABBACBBAABAAABABBAABBAABABBAABBAABABBBABBAABABABBAABCAABBACBABCAAACAABABABABAABABCBBACBABAACBAACACACACBAACBABAABBABABCBABADABABCBABAABBABADADABABBBABAABBJADABAFANAPAB0ABCAABCAABCBABCABBABCAABBAABABABABCAABABBABABABAACBABCBABBACBABBBABAACBAABBABABAABABBAABABABABABABABCACCABCAABBABAABBAABABABABABABCACBCAABCAABCAABCAABCAABCACAABCAABCACAABCACAABCACBCAABCACAABCACACACACAABCACAABCACACACACACACACACAABCACACAABCAABABABBAABAAABBAABCAABBAAABAABBAABBABAABABABABBAABBAABBBBAABABBABAABBAABCAAAABAABAAABBABCACAABBACBABAAABCBABABABBBABABBABBDBDABBBABABBABBBBBABBABBBABABAABBBBAABBDABBDABABABABCBCACBCACCCACAABCAABCAABCACAABCCACCAABCAABCAABCACAABCACBCBCAABCBBBABCACAABCACACBCAABABABABCBABCAABABCBABBAABDBBAABABBAABBBABBBCAABBAABABABCAABBAABABCAABABABABABAAABBAABABABBAABAAABCAABAAABCAABCACACACBCACACBCAABBABABAABBAABABCAABCBABABCBABCAABCAABBACBBAABABBAABABABABABBBABABBAABBAABABBAABABBAABABABABABABBAABABAAABABABABBAABABABABBAABABABABAAABCAABABBABBBBBAABABABBAABBBBABAABABBABABABAABBAABBABAABAAABBAABABABBAABBABAABBABAABBABAABBAABBAABABBAABBAABBAABBAABBBBAABBAABABABBAABBAABBABAABBAABBAACBAABBABAABABABABBBBAABBBCACAABABCACAABCACACBCACAABCAABABCBABCAACCAACCAACCAACCACACACCCACACACACACAACCCACCACAEBCCACCACACACACACAACCACAACCACACBCACCCACACAABCACACAACACCCCACACACCCACACAAAABCBABABAAABABCAABBAABCAABABABBAABABBBCAABBAABABBBABBAABABCAABCAABABABBABABABABBAABABABABAACBBBABAABABBABAABBAABABBABBBCBBBAABABBAABBABABCBAABBBBBABBABABABABBBABAABBAABABABABBABABDBAAABAACBABAABABABBAABABBABBABABBAABBAABABBAABABCAABABBAABCAABCBABABABBAABABABABABABABCAABBAABABABABABABDBBDBBBABABABABABABAABBAABABBDCACAACCACACAABCAABABABCACAABEACAABABAAABCACAABABCBAAABCACBABCAABABBAABBAABABBAABBAABBABABAABABABBAABAAABCAABCACAABCACACACACAABCACAABCAABABABCAABABCAABCBABABABABADABABABCAABCACAABCAABCAABABCBABABBAABABABBAABBABAABABBBABBABAABCACAACCACAACCAACACCCCCACCACACACACAABCAACCAACCACACACAABCAABCAABCACAABCAAACACAACCACAACCCACBAACCAACACACCACAACCACBBBABCAABCBCBCBCBABCAABABABABABABABCAABCAABABCAABABABABABABABCAABBBABCAABCACAABABABABABCAABCAABCAABCAABABABCACACBCAABCAABCAABCBABABABABBAABBABAABABABABABCAABCAABABCACAABCAABCBABBAABBAABCAABCBBAABBAABBAABBAACBAABBAABBABAAABAABBCBABABAABBABABCBABAABBAABAABAABBABABAABCAABBABAACBAACBAACBAACACCAACCAACBAACBAABBAACBABACBABBAABBABABABAACBAACAAAABABAACAAACBABAACBABBBABAABABABCAABABBABAABBABABCBABABACBBBBABABABABAAAABABAAABBAABCAABBAABABABABBAACBAABABBABAABBAABBAACBABCBAABBAACBAABBABCBABABAACACBAACBABABAABBAAABAACBAABBCABBABAAABABAACBBBABABABABBBAACBAACACBAACBAACBAACBABABAACBABABABABAACBAACBABCACACACACACACBAACBCBCBABABABABABBACBAACACBCACACACACACACBAAABAACBABABABABCABBABAACACACACACACACBABABABABABABBBABCBCBCBCBABAABBBABABABABABABBABBBAABBABABAABBABBACBADEBCBABABABABAACBAACBCBCACBABCBABABCBCACBCACBAACBABABBBABABBBABABABABBBABABABABADBBABCBABAACBABABBBAABABBABABDBBBABADABAABBAABABCBCBABBABABAACBABADABABABAABBACBCBABABABABBABAABBACDABABBBBBABBBABBAABBAABBBBAABBABABBBABBBAABABABCBCAABABABBABBBABAABBABBBABABABBBBBBABBABABAABBAABBAABBAABBABAABABBBBABABABABA"},bounds:{NORTE:-23.3563,SUL:-24.0084,LESTE:-46.3651,OESTE:-46.8262}}');
</script>
Does anyone know that I was wrong to use the function?
What part is giving
NaN,NaN...
?– bfavaretto
Something else, don’t use
for (var i in strings)
, forstrings
is an array. Usefor(var i=0; i<strings.length; i++)
.– bfavaretto
Nan, Nan, myArray leaves..., he gets like this after he passes the switch. I used for(var i in strings) because the function is already ready,
– Rodolfo Oliveira
And which is the entrance (
string
) that you’re using?– bfavaretto
@bfavaretto This link here:http://www.cites.ibge.gov.br/gmap/shapes/35/MU_M13_3550308_1000.json
– Rodolfo Oliveira