[OpenLayers-Users] Filter.spatial and Styles

Tondo gpktondo at gmail.com
Mon Dec 5 05:21:56 EST 2011


Hi friends,

I would like to create dynamic spatial filter, that changes default styles
of features... As far I know, there need to be at least two objects to test
intersection on the map. So I've got two combo boxes (html select object) so
user can choose two layers and see intersection result. Here's code:

/var spFilterGoButton = $("spGo");
spFilterGoButton.onclick = function() {
var spLayersA = $("spLayersA");
var spLayersB = $("spLayersB");
var filters = new Array;
var features = new Array;
var layers = activeLayers(); //returns array of visible layers
for (var i in layers) {
if (layers[i].name == spLayersA.value) var layerA = layers[i];
if (layers[i].name == spLayersB.value) var layerB = layers[i];
}
features = layerA.features //filter input should be features so get array
layers features

//Apply LayersA features to spatial filter
  for (var i in features) {
  var filter = new OpenLayers.Filter.Spatial({
  type: OpenLayers.Filter.Spatial.INTERSECTS,
  value: features[i].geometry
  });
  filters[i] = filter;
  }

//now just add array of spatial filters to logical filter
var logicalFilter = new OpenLayers.Filter.Logical({
  type: OpenLayers.Filter.Logical.OR,
  filters: filters
  });

//rule based on logical filter
var rule = new OpenLayers.Rule({
filter: logicalFilter,
symbolizer: {
fillColor: '#FF0000', fillOpacity:.8,
pointRadius:3, strokeColor: '#FF0000',
strokeWidth:2
}
});
var style = new OpenLayers.Style();
style.addRules([rule]);
var filter_map = new OpenLayers.StyleMap({
'default': style
});

//apply rule on layers and redraw
layerA.styleMap = filter_map;
layerA.redraw();
layerB.styleMap = filter_map;
layerB.redraw();
}/  

My questions are:
1. Is it even possible to apply styles based on spatial/logical filter? If
no, how could be done it?
2. If features of LayerA are the first input, what is the second and where
can I apply it?

Thank you.

regards,
Tom

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Filter-spatial-and-Styles-tp7062378p7062378.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list