vendor/ember-leaflet-cartodb/cartodb_noleaflet.js
function(model, col, options) {
    if (this.size() > 0) {

      // Assign an order of 0 to the first layer
      this.at(0).set({ order: 0 });

      if (this.size() > 1) {
        var layersByType = {};
        for (var i = 1; i < this.size(); ++i) {
          var layer = this.at(i);
          var layerType = layer.get('type');
          layersByType[layerType] = layersByType[layerType] || [];
          layersByType[layerType].push(layer);
        }

        var lastOrder = 0;
        var sortedTypes = [CARTODB_LAYER_TYPE, TORQUE_LAYER_TYPE, TILED_LAYER_TYPE];
        for (var i = 0; i < sortedTypes.length; ++i) {
          var type = sortedTypes[i];
          var layers = layersByType[type] || [];
          for (var j = 0; j < layers.length; ++j) {
            var layer = layers[j];
            layer.set({
              order: ++lastOrder
            });
          }
        }
      }
    }
  }
function(model, col, options) {
    if (this.size() > 0) {

      // Assign an order of 0 to the first layer
      this.at(0).set({ order: 0 });

      if (this.size() > 1) {
        var layersByType = {};
        for (var i = 1; i < this.size(); ++i) {
          var layer = this.at(i);
          var layerType = layer.get('type');
          layersByType[layerType] = layersByType[layerType] || [];
          layersByType[layerType].push(layer);
        }

        var lastOrder = 0;
        var sortedTypes = [CARTODB_LAYER_TYPE, TORQUE_LAYER_TYPE, TILED_LAYER_TYPE];
        for (var i = 0; i < sortedTypes.length; ++i) {
          var type = sortedTypes[i];
          var layers = layersByType[type] || [];
          for (var j = 0; j < layers.length; ++j) {
            var layer = layers[j];
            layer.set({
              order: ++lastOrder
            });
          }
        }
      }
    }
  }
function ( model , col , options ) { if ( this . size ( ) > 0 ) { // Assign an order of 0 to the first layer this . at ( 0 ) . set ( { order : 0 } ) ; if ( this . size ( ) > 1 ) { var layersByType = { } ; for ( var i = 1 ; i < this . size ( ) ; ++ i ) { var layer = this . at ( i ) ; var layerType = layer . get ( 'type' ) ; layersByType [ layerType ] = layersByType [ layerType ] || [ ] ; layersByType [ layerType ] . push ( layer ) ; } var lastOrder = 0 ; var sortedTypes = [ CARTODB_LAYER_TYPE , TORQUE_LAYER_TYPE , TILED_LAYER_TYPE ] ; for ( var i = 0 ; i < sortedTypes . length ; ++ i ) { var type = sortedTypes [ i ] ; var layers = layersByType [ type ] || [ ] ; for ( var j = 0 ; j < layers . length ; ++ j ) { var layer = layers [ j ] ; layer . set ( { order : ++ lastOrder } ) ; } } } } }
each time a layer is added or removed
the index should be recalculated
each time a layer is added or removed the index should be recalculated