Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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'm adding layers to a GeoExt map panel map dynamically in response to a user's selection. I have a corresponding FeatureStore definition from which I create the layers. When a new layer is added, I'd like it to be the top most layer.

var vecLayer = new OpenLayers.Layer.Vector(natureOfAttack, {
            styleMap: new OpenLayers.StyleMap({
                'default': style
            protocol: new OpenLayers.Protocol.HTTP({
                url: "./server/maps/incidents.php",
                params: {natureOfAttack: natureOfAttack},
                format: new OpenLayers.Format.GeoJSON()
            strategies: [new OpenLayers.Strategy.Fixed()]

        // manually bind store to layer

        // some more controls
        var selectCtrl = new OpenLayers.Control.SelectFeature(vecLayer);;{
            'featureselected': function(e) {


        // for dev purpose
        map =;
        mapPanel = mapPanel;

I've then added:

var cLayer = map.getLayersByName(natureOfAttack)[0];
    map.setLayerIndex(cLayer, map.layers.length+1);

in an attempt to make the layer the top most layer, but this doesn't seem to work.

Having thought about it for a while, I came to the conclusion that I should probably have a listener in the store definition as shown below:

Ext.define('', {
    extend: '',
    model: 'CMD.model.Summit',
    autoLoad: false,

    listeners: {
        add: function(thisStore, records, index) {
            console.log('FeatureStore: A new layer added...');

but the event in the listener is not executed. Any idea on how I can achieve this will be appreciated.


I've added:
        'loadend': function(layer) {
            map.setLayerIndex(layer, map.getLayerIndex(layer)+5);

to the vector layer. This makes the created vector layer the top most layer. However, the error TypeError: a.setZIndex is not a function is generated.


My environment: GeoExt 2, ExtJS 4, OpenLayers 2.12.

share|improve this question

you can try map.raiseLayer function. Following code will help you to make your added layer to the top most layer with getting the length of layers.

map.raiseLayer(addedLayer, map.layers.length);

i hope it helps you...

share|improve this answer
Thanks a lot. This also makes the layer the top most layer. But it also generates the error TypeError: a.setZIndex is not a function. – okello Feb 4 '13 at 8:23
May be this might help: I'm using GeoExt 2 with ExtJS 4. – okello Feb 4 '13 at 12:20

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.