> I guess your problem is related to the asynchronous loading of the 
> images. Maybe the size of your legendContainer is calculated before 
> the image is loaded completely. I would suggest to try to call the 
>  'doLayout' function of your legendContainer after the image is 
> loaded. For this you can use the ' legendimageloaded' event of the 
> 'LegendImage' class.
>

Thanks for the suggestion, but no cigar. Tried all sorts of 
arrangements. I checked with debugger and do.Layout() not being called 
till after all images are loaded. However, the code is also loading a 
form.label for the text which shouldn't wait for anything and that is 
also not appearing. I put the whole unit below which works, but doesnt 
if the width/height settings are removed despite the waiting for image 
load. Tearing my hair at this stage - so close and yet so far.




/*
  * Copyright (c) 2008-2012 The Open Source Geospatial Foundation
  *
  * Published under the BSD license.
  * See https://github.com/geoext/geoext2/blob/master/license.txt for 
the full
  * text of the license.
  */

/*
  * @include OpenLayers/Layer/WMS.js
  * @include OpenLayers/Util.js
  * @requires GeoExt/container/LayerLegend.js
  * @include GeoExt/LegendImage.js
  */

/**
  *  Show a legend image for a AgsGIS93REST layer using the REST interface
  *
  * @class GeoExt.container.AgsLegend
  */
Ext.define('GeoExt.container.AgsLegend', {
     extend: 'GeoExt.container.LayerLegend',
     alias: 'widget.gx_agslegend',
     requires: ['GeoExt.LegendImage'],
     alternateClassName: 'GeoExt.AgsLegend',

     statics: {
         supports: function (layerRecord) {
             return layerRecord.getLayer() instanceof 
OpenLayers.Layer.ArcGIS93Rest ? 1 : 0;
         }
     },
     imageCount:0,
     baseParams: null,
     legendContainer:null,

     initComponent: function(){
         var me = this;
         me.addEvents('legendimageloaded');
         me.callParent();
         var layer = me.layerRecord.getLayer();
         me._noMap = !layer.map;
         this.legendContainer = Ext.create('Ext.panel.Panel',{ // panel 
to hold image/text pairs
                                             layout: 
{type:'table',columns:2},
                                             itemId:'agslegendbox',
                                             border: false,
                                             defaults: {
                                                 border: false
                                             },
                                             width:180
                                         });
         this.add(this.legendContainer);
         layer.events.register("moveend", me, me.onLayerMoveend);
         me.update();
     },

     /**
      * @private
      * @param {Object} e
      */
     onLayerMoveend: function(e) {
         if ((e.zoomChanged === true && this.useScaleParameter === true) ||
             this._noMap) {
             delete this._noMap;
             this.update();
         }
     },

     gotLegendImage: function(){  // called on legend image load
        this.imageCount -=1;
        if(this.imageCount===0) {
         this.fireEvent('legendimageloaded', this);        // fire event 
when all loaded
         this.doLayout(); // not working!
        }
     },

     /**
      * Update the legend, adding, removing or updating
      * the per-sublayer box component.
      * @private
      */
     update: function() {
         var layer = this.layerRecord.getLayer();
         if(!(layer && layer.map)) {
             return;
         }
         this.callParent();
         var h = 0;
         var layerNames, layerName, i, len, j, lenj;
         this.legendContainer.removeAll(false);
         var la = 
(layer.params.LAYERS.indexOf(':')>-1)?layer.params.LAYERS.split(":")[1]:layer.params.LAYERS;
         layerNames = [la].join(",").split(",");
         this.imageCount =0;
// first run through loop to get count of images for the legend
         for  (j=0, lenj = layerNames.length; j<lenj; j++) {
             layerName = layerNames[j];
// layer needs to be created with agsLegend object attached. This hold 
legend json from the server. It is passed in because
// can only get legend for whole service url. Cant get just the legend 
images for a particular by themselves.
             for(i = 0, len = 
layer.agsLegend.layerLegend[layerName].legend.length; i<len; i++) {
                 if(!this.items || !this.getComponent(layerName+i)) {
                     if (!layer.hideInLegend) {
                       this.imageCount +=1;
                     }
                 }
             }
         }
         for  (j=0, lenj = layerNames.length; j<lenj; j++) {
             layerName = layerNames[j];
             for(i = 0, len = 
layer.agsLegend.layerLegend[layerName].legend.length; i<len; i++) {
                 if(!this.items || !this.getComponent(layerName+i)) {
                     if (!layer.hideInLegend) {
                       var lg = 
layer.agsLegend.layerLegend[layerName].legend[i];
                       this.legendContainer.add([{
                                     xtype: "gx_legendimage",
                                     url: layer.agsLegend.serverUrl 
+'/'+ layerName +'/images/'+lg.url,
                                     itemId: lg.label,
                                     listeners: {
                                         'legendimageloaded':{ 
fn:this.gotLegendImage()},
                                             scope: this
                                     }

                       },{
                         xtype:"label",
                         text:lg.label
                       }]);
                        h += (lg.height+5); //kludge to height of legend 
container
                     }
                 }
             }
         }
         this.legendContainer.setHeight(h); //kludge
         this.doLayout(); //shouldnt be needed if code getLegendImage 
worked.
     },

     beforeDestroy: function() {
         if (this.useScaleParameter === true) {
             var layer = this.layerRecord.getLayer();
             layer && layer.events &&
             layer.events.unregister("moveend", this, this.onLayerMoveend);
         }
         this.callParent();
     }
}, function() {
     GeoExt.container.LayerLegend.types["gx_agslegend"] = 
GeoExt.container.AgsLegend;
});


Notice: This email and any attachments are confidential.
If received in error please destroy and immediately notify us.
Do not copy or disclose the contents.

_______________________________________________
Dev mailing list
[email protected]
http://www.geoext.org/cgi-bin/mailman/listinfo/dev

Reply via email to