Rearranging stack order of layers

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Rearranging stack order of layers

jaslee
Hi,
I have an OpenLayers application which initially has 4 layers, called (a),(b),(c) & (d). The app then allows the creation of a new layer (e) which I want it to "swap" places with layer (b) so that the order should be (a),(e),(c),(d),(b).

I use the map.setLayerIndex and layer.getZIndex to try and do this but I realise that the layers are in a FIFO like queue, so when I temporarily re-assign layer (b) the other layers automatically reorder themselves to (a),(c),(d),(e) ...or at least that's what I think it happening.

Could anyone show me how I can simply swap the z-order of 2 layers?

Thanks

Jason

_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
Reply | Threaded
Open this post in threaded view
|

Re: Rearranging stack order of layers

jaslee
Don't know if it is the best solution, but I am now using "map.raiseLayer()" like so:-

//===========================
lyrNum = 2;
var delta = map.getNumLayers() - lyrNum;

map.raiseLayer(layer, -delta);
map.raiseLayer(netLayer, delta);
//===========================

This seems to do the trick.

Jason


On Fri, Aug 10, 2012 at 9:55 AM, Jason Lee <[hidden email]> wrote:
Hi,
I have an OpenLayers application which initially has 4 layers, called (a),(b),(c) & (d). The app then allows the creation of a new layer (e) which I want it to "swap" places with layer (b) so that the order should be (a),(e),(c),(d),(b).

I use the map.setLayerIndex and layer.getZIndex to try and do this but I realise that the layers are in a FIFO like queue, so when I temporarily re-assign layer (b) the other layers automatically reorder themselves to (a),(c),(d),(e) ...or at least that's what I think it happening.

Could anyone show me how I can simply swap the z-order of 2 layers?

Thanks

Jason


_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
Reply | Threaded
Open this post in threaded view
|

Re: Rearranging stack order of layers

jaslee
Oops, let's make that example more generic(!)

//===========================
lyrNum = 2;
var delta = map.getNumLayers() - lyrNum;

map.raiseLayer(layer_e, -delta);
map.raiseLayer(layer_b, delta);
//===========================

Jason


On Fri, Aug 10, 2012 at 10:26 AM, Jason Lee <[hidden email]> wrote:
Don't know if it is the best solution, but I am now using "map.raiseLayer()" like so:-

//===========================
lyrNum = 2;
var delta = map.getNumLayers() - lyrNum;

map.raiseLayer(layer, -delta);
map.raiseLayer(netLayer, delta);
//===========================

This seems to do the trick.

Jason


On Fri, Aug 10, 2012 at 9:55 AM, Jason Lee <[hidden email]> wrote:
Hi,
I have an OpenLayers application which initially has 4 layers, called (a),(b),(c) & (d). The app then allows the creation of a new layer (e) which I want it to "swap" places with layer (b) so that the order should be (a),(e),(c),(d),(b).

I use the map.setLayerIndex and layer.getZIndex to try and do this but I realise that the layers are in a FIFO like queue, so when I temporarily re-assign layer (b) the other layers automatically reorder themselves to (a),(c),(d),(e) ...or at least that's what I think it happening.

Could anyone show me how I can simply swap the z-order of 2 layers?

Thanks

Jason



_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
Reply | Threaded
Open this post in threaded view
|

Re: Rearranging stack order of layers

geekdenz
How about a function/extension to OpenLayers that does this?

//===========================

OpenLayers.Map.prototype.swapLayers = function(firstLayer, secondLayer) {
  var delta = this.getNumLayers() - 2;
  map.raiseLayer(secondLayer, -delta);
  map.raiseLayer(firstLayer, delta);
}

// in your code you would then call:
map.addLayer(layer_e); // if you haven't done so already
map.swapLayers(layer_b, layer_e);

//===========================

Haven't tested this but believe it works assuming the code below works.

Cheers,
Tim

Tim-Hinnerk Heuer

Twitter: @geekdenz



On 10 August 2012 21:29, Jason Lee <[hidden email]> wrote:
Oops, let's make that example more generic(!)

//===========================
lyrNum = 2;
var delta = map.getNumLayers() - lyrNum;

map.raiseLayer(layer_e, -delta);
map.raiseLayer(layer_b, delta);
//===========================

Jason


On Fri, Aug 10, 2012 at 10:26 AM, Jason Lee <[hidden email]> wrote:
Don't know if it is the best solution, but I am now using "map.raiseLayer()" like so:-

//===========================
lyrNum = 2;
var delta = map.getNumLayers() - lyrNum;

map.raiseLayer(layer, -delta);
map.raiseLayer(netLayer, delta);
//===========================

This seems to do the trick.

Jason


On Fri, Aug 10, 2012 at 9:55 AM, Jason Lee <[hidden email]> wrote:
Hi,
I have an OpenLayers application which initially has 4 layers, called (a),(b),(c) & (d). The app then allows the creation of a new layer (e) which I want it to "swap" places with layer (b) so that the order should be (a),(e),(c),(d),(b).

I use the map.setLayerIndex and layer.getZIndex to try and do this but I realise that the layers are in a FIFO like queue, so when I temporarily re-assign layer (b) the other layers automatically reorder themselves to (a),(c),(d),(e) ...or at least that's what I think it happening.

Could anyone show me how I can simply swap the z-order of 2 layers?

Thanks

Jason



_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev



_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev