OpenLayers - Trying to load layers using a JSON file -


i have bunch of layers need load map, instead of loading each 1 individually trying load using json file , openlayers.request.get not know how complete code.

json file:

{ "layers": [ { "title":"client manholes" , "url":"./mh_file.geojson" , "style":"mh_style"},  { "title":"client pipe" , "url":"./pipe_file.geojson" , "style":"pipe_style"},  { "title":"client parcels" , "url":"./parcel_file.geojson" , "style":"parcel_style"} ] } 

javascript:

var request = openlayers.request.get({     url: "http://domain.com/layers.json",     callback: handler });  function handler(request) {     //alert (request);     var  response = json.read (request.responsetext);     //loop thru each layer     each (var layer in request) {                 //load layer                 layer = new openlayers.layer.vector(layer_title, {                     strategies: [new openlayers.strategy.fixed()],                     protocol: new openlayers.protocol.http({                         url: layer_url,                         format: new openlayers.format.geojson({                         })                     }),                     //...load stylemap                 });                 //turn layer off                 layer.setvisibility(false);             }          }; 

fixed it!

function handler (request) {             var  json = new  openlayers.format.json ();             var  response = json.read (request.responsetext);             //console.log(response);              var layer_data = response.layers             (var in layer_data) {                 var layer_name = layer_data[i].title;                 //alert(layer_name);                 var layer_url = layer_data[i].url;                 //alert(layer_url);                 var layer_style = layer_data[i].style;                 //alert (layer_style);                 layer = new openlayers.layer.vector(layer_name, {                     strategies: [new openlayers.strategy.fixed()],                     protocol: new openlayers.protocol.http({                         url: layer_url,                         format: new openlayers.format.geojson({                         })                     }),                     //...load stylemap                 });                 //turn layer off                 layer.stylemap = mh_style_map;                 layer.setvisibility(false);                 map.addlayer(layer);             }             //alert (response);         }; 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -