I am trying to store my map's resolutions in web.config and the property in my ASP.NET is a string
web.config
<maplayers>
<bufferMaps useBufferMaps="1" zoomOffset="13" resolutions="19.1092570678711,9.55462853393555,4.77731426696777,2.38865713348389,1.19432856674 1945,0.5971642833709725"/>
</maplayers>
When I read the resolutions
property in my javascript I get the following error:
Object [19.1092570678711,9.55462853393555,4.777314…66741945,0.5971642833709725] has no method 'sort'
I think it may be because it's a string but how can I solve this?
My javascript
var str1 = "[";
var str2 = "]";
var res_str=str1.concat(ob.resolutions,str2);
var mapnik_layer = new OpenLayers.Layer.OSM(
"OpenStreetMap",
"http://localhost/WebClient/Openstreetmap/${z}/${x}/${y}.png",
{zoomOffset: 13,
resolutions: res_str}
);
map.addLayers([mapnik_layer]);
Like you suspected it's because resolutions
is supposed to be an array rather than a string.
OpenLayers.Layer.resolutions {Array} A list of map resolutions (map units per pixel) in descending order.
The string.split()
method, takes a string as input and splits it into an array at a given delimiter - in this case at each comma ,
:
var res_str = ob.resolutions.split(',');
The output of which is:
["19.1092570678711", "9.55462853393555", "4.77731426696777", "2.38865713348389", "1.194328566741945", "0.5971642833709725"]
An array of strings, rather than just a string:
"[19.1092570678711, 9.55462853393555, 4.77731426696777, 2.38865713348389, 1.194328566741945, 0.5971642833709725]"