[OpenLayers-Users] Re: Draw Box From Selected Features

Richard Barnes barn0357 at umn.edu
Wed Jun 29 14:51:39 EDT 2011


Thanks for your help, Alexandre Dube. I dug deep into stack traces and found, well... nothing.
But I did find a solution.
The code I posted was:
-------------
var bounds=null;
  for(i in stations.selectedFeatures)
     for(x in stations.selectedFeatures[i].cluster)
       if(bounds==null)
  
  bounds=stations.selectedFeatures[i].cluster[x].geometry.getBounds().clone();
       else
  
  bounds.extend(stations.selectedFeatures[i].cluster[x].geometry.getBounds());

  Fit_box=bounds.toGeometry().components[0];
  Fix_box=new OpenLayers.Feature.Vector(Fit_box, null, {fillColor:
  "green"});
  VectorLayer.addFeatures([Fit_box]);
-------------
It turns out you can fix things by replacing the lines:
  Fit_box=bounds.toGeometry().components[0];
  Fix_box=new OpenLayers.Feature.Vector(Fit_box, null, {fillColor:
  "green"});
with the lines
  var fit_bounds=bounds.toGeometry().components[0];
  Fix_box=new OpenLayers.Feature.Vector(fit_bounds, null, {fillColor:
  "green"});

Ridiculous, right?

Anyways, thanks for your help!

~Richard~



More information about the Users mailing list