Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a vector layer where some features are found entirely within other features and therefore I can't select that feature because the other feature is on top of it. Is there a way to reverse the order of the features of a vector layer after they have already been loaded? This will likely solve about 99% of issues that may occur with my mouseover popup.

Edit to add code:

I'm trying to do this on demand after the layer is already loaded.

var refreshStrategy = new OpenLayers.Strategy.Refresh( {
    interval : 60 * 1000
var vLayer = new OpenLayers.Layer.Vector("Hazards with Population",
        projection : "EPSG:4326",
        strategies : [new OpenLayers.Strategy.Fixed(), refreshStrategy],
        protocol : new OpenLayers.Protocol.HTTP(
          url : "./getFeatures.php",              
          format : new OpenLayers.Format.GeoJSON(),
          rendererOptions : {
            zIndexing : true
share|improve this question
How are you currently getting your data/what have you got at the moment? What is the problem preventing you from reversing the data you are stuffing into the layer? – René Wolferink Apr 25 '13 at 14:54
up vote 3 down vote accepted

Supposing you have access and can modify your getFeatures.php, simply reverse the array where the data is being formatted as GeoJSON.

If it's coming from a database, reverse your order by clauses. Or if it's coming from some other source, reverse the array just before formatting it as GeoJSON:

$data = array(item1, item2, item3, ...); // Your array of data the way it's loaded currently
$reversed = array_reverse($data); // Reverse the array
makeGeoJSON($reversed); // Transfor it into GeoJSON the way you're doing currently

If you don't have access to the php code, you probably can achieve the same effect by adding an event listener to the beforefeaturesadded event on the layer:'beforefeaturesadded', vectorLayer, function (data) {
share|improve this answer
That would be nice, but I don't have access to the getFeatures.php. I was hoping there was a javascript way to flip the feature order. – Jonathan Apr 25 '13 at 15:56
Updated my answer to include a javascript-only solution. – René Wolferink Apr 25 '13 at 16:12
Thanks Rene! I should have been more clear in my initial question. I already have them loaded and want to switch them after the load. Like when a user fires an event. I updated the question to reflect that. – Jonathan Apr 29 '13 at 14:56
@René Wolferink is right. featureArrayList.reverse() should help you... – Aragon Apr 29 '13 at 15:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.