C# layerObj.draw && layerObj.drawLegend

Tamas Szekeres szekerest at GMAIL.COM
Fri Apr 20 15:14:44 EDT 2007


2007/4/20, Jean Michel PIERRET <jmp at geosys.com>:
>
>  Hi,
>
>
>
> I'm using mapserver with c# bindings and i have two questions.
>
>
>
> 1)
>
>                         layerObj lobj = null;
>
>
>
> ...
>
>
>
>             imageObj iobj = null;
>
>
>
>             iobj = lobj.map.prepareImage();
>
>             lobj.draw(_lobj.map, iobj);
>
>
>
> In the drawn image, the labels don't appear, whereas with the method
> mapObj.draw they are there. It is normal ?.
>

I guess you should either disable the labelcache for this layer (
layerObj.labelcache = mapscript.MS_OFF) or call
layerObj.drawlabelcacheexplicitly right after drawing the shapes.


2)
>
>
>
> Exist there a method to draw legend for one layer only and not for all the
> map.
>

Here is a function extracted from my previous project for drawing the legend
image, hopefully it applies to your intents fairly enough.

private Image CreateLegendImage(layerObj layer, int classindex, int width,
int height, int keysizex, int keysizey)
        {
            using (classObj def_class = new classObj(null)) // for drawing
legend images
            {
                using (imageObj image = def_class.createLegendIcon(map,
layer, width, height))
                {
                    classObj layerclass = layer.getClass(classindex);
                    layerclass.drawLegendIcon(layer.map, layer, keysizex,
keysizey, image,
                        (width - keysizex) / 2, (height - keysizey) / 2);
                    byte[] img = image.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        return Image.FromStream(ms);
                    }
                }
            }
        }


Best regards,

Tamas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-dev/attachments/20070420/29726856/attachment.html


More information about the mapserver-dev mailing list