[ka-Map-users] Kamap removeMapLayer

Stéphane RIFF stephane.riff at cerene.fr
Thu Sep 6 08:38:22 EDT 2007


Hi,

I have made a workaround for the kaLegend draw() function.
I don't know if it's totally ok but it seems to work.

Can you have look and tell me if you see some problem so I can improve it ?

Here is the draw function :
Remove the line with "--" and add the ones with "++"

/**
 * legend.draw( szContents )
 *
 * render the contents of a legend template into a div
 */
kaLegend.prototype.draw = function() {
/*modificato da kappu non trova url corretto se non lo metto anche qui*/
    this.urlBase = this.kaMap.server;
    this.urlBase += 
(this.urlBase!=''&&this.urlBase.substring(-1)!='/')?'':'/';

    var oMap = this.kaMap.getCurrentMap();

    this.expanders = [];
    this.queryCBs = [];

    if (this.domObj.childNodes.length == 0) {
        this.domObj.appendChild(this.createHeaderHTML());
    }

    var aLayers = oMap.getAllLayers();
--    for (var i=(aLayers.length-1);i>=0;i--) {
--        if (aLayers[i].kaLegendObj == null) {
--            this.createLayerHTML( aLayers[i] );
--        } else {
--            try{this.domObj.removeChild( aLayers[i].kaLegendObj );}
--            catch(e){};
--        }
--    }
++        var childs = this.domObj.childNodes;
++        for (var i=(childs.length-1);i>=0;i--) {
++          if(childs[i].className == "kaLegendLayer") {
++            try{this.domObj.removeChild( childs[i] );}
++            catch(e){};
++            }
++    }

    for (var i=(aLayers.length-1);i>=0;i--) {
++      this.createLayerHTML( aLayers[i] );
      this.domObj.appendChild( aLayers[i].kaLegendObj );
    }

    if (this.kaMap.isIE4) {
        for(var i=0; i<this.queryCBs.length; i++) {
            this.queryCBs[i].checked = this.queryCBs[i].oLayer.visible;
        }
    }
    return;
};

Thanks,
Hope this help.

Stephane

Paul Spencer wrote:

> this appears to be a bug in kaLegend draw() method, it rebuilds the  
> legend based on the layers in the map but in doing so it only removes  
> legend entries for layers that are in the map - so once a layer is  
> removed, and draw is called (through KAMAP_LAYERS_CHANGED event), the  
> legend entry will not be removed.
>
> Patches welcome.
>
> Cheers
>
> Paul
>
> On 31-Aug-07, at 10:57 AM, Stéphane RIFF wrote:
>
>> Hi,
>>
>> I use the removeMapLayer but I have a problem.
>> With addMapLayer, the layer is added to the legend too but with  
>> removeMapLayer the layer isn't remove from legend.
>>
>> Can someone tell me how to remove a layer from the legend ?
>>
>> Thanks
>> Steff
>> _______________________________________________
>> ka-Map-users mailing list
>> ka-Map-users at lists.maptools.org
>> http://lists.maptools.org/mailman/listinfo/ka-map-users
>
>
> +-----------------------------------------------------------------+
> |Paul Spencer                          pspencer at dmsolutions.ca    |
> +-----------------------------------------------------------------+
> |Chief Technology Officer                                         |
> |DM Solutions Group Inc                http://www.dmsolutions.ca/ |
> +-----------------------------------------------------------------+
>
>
>
>
>
>



More information about the ka-Map-users mailing list