Changing symbol icon on the fly
Sean Gillies
sgillies at FRII.COM
Wed Apr 27 08:59:29 PDT 2005
On Apr 27, 2005, at 9:32 AM, Aaron Craig wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Using mapscript (perl, but any generic example will do) what's the
> preferred way to change the icon of a point, in a layer that is defined
> as follows:
>
> LAYER
> ~ NAME "musei"
> ~ TYPE POINT
> ~ STATUS OFF
>
> ~ CONNECTION 'user=tsc2 password=tsc2 dbname=geo_sardegna'
> ~ CONNECTIONTYPE POSTGIS
> ~ DATA 'the_point from musei'
>
> ~ CLASS
> ~ NAME "musei"
> ~ STYLE
> ~ SYMBOL
> "/var/www/OpenPortal/htdocs/confartigianato/Images/icona_small.gif"
> ~ SIZE 10
> ~ COLOR 0 0 0
> ~ END
> END
>
>
> I'm doing
>
> my $lyrPoints = $map->getLayerByName($sLayerName);
>
> $lyrPoints->{status} = $mapscript::MS_ON;
> my $cls = $lyrPoints->getClass(0); # change this if we ever use layers
> with more than one class
> my $stl = $cls->getStyle(0); # change this if we ever use classes with
> more than one style
> my $nSymbolIndex = $stl->{symbol};
>
> my $sym = $map->{symbolset}->getSymbol($nSymbolIndex);
> $sym->{imagepath} =
> "/var/www/OpenPortal/htdocs/confartigianato/Images/$sLayerName.gif";
>
> [snip]
Aaron,
Symbols are more static than dynamic. You can't mutate their imagepath
like that. You can, however modify your map's symbolset so that it
contains custom symbols:
# create and add a new symbol
layer_name = 'foo'
symbol_path = '/path/to/foo/symbol.gif'
new_symbol = mapscript.symbolObj(layer_name, symbol_path)
new_index = map.symbolset.appendSymbol(new_symbol)
# assign this new symbol to the styleObj
style.symbol = new_index
Check out these URLs for more details on symbols and symbolsets
http://zcologia.com/mapserver/mapscript#symbolsetobj
http://zcologia.com/mapserver/mapscript#symbolobj
cheers,
Sean
--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies
More information about the MapServer-users
mailing list