| 1 | = styleObj = |
| 2 | |
| 3 | Illustrating use of new 4.x styleObj, two approaches: |
| 4 | |
| 5 | == One - Using an existing style from map file. Default values will come from values set in map file. == |
| 6 | {{{ |
| 7 | #!perl |
| 8 | my $layerObj = $map->getLayerByName('data_points'); |
| 9 | my $class = $layerObj->getClass(0); |
| 10 | # we only have one style in this layer. |
| 11 | my $style = $class->getStyle(0); |
| 12 | # change some sytle values |
| 13 | $style->{size} = 20; |
| 14 | $style->{color}->setRGB(255,0,0); |
| 15 | $layerObj->draw($map,$img); |
| 16 | }}} |
| 17 | |
| 18 | == Two - Creating a new style. All values must be set. == |
| 19 | {{{ |
| 20 | #!perl |
| 21 | my $circle_idx = $map->getSymbolByName('circle'); |
| 22 | my $layerObj = $map->getLayerByName('data_points'); |
| 23 | my $class = $layerObj->getClass(0); |
| 24 | my $style = new mapscript::styleObj(); |
| 25 | $style->{symbol} = $circle_idx; |
| 26 | $style->{size} = 20; |
| 27 | $style->{color}->setRGB(255,0,0); |
| 28 | $style->{outlinecolor}->setRGB(0,0,0); |
| 29 | # insert the style in class |
| 30 | $class->insertStyle($style, 0); |
| 31 | $layerObj->draw($map,$img); |
| 32 | # remove the style, this is important when in a loop. There is a maximum of 5 styles/class. |
| 33 | $class->removeStyle(0); |
| 34 | }}} |
| 35 | == Map file fragment == |
| 36 | {{{ |
| 37 | LAYER |
| 38 | NAME "data_points" |
| 39 | TYPE POINT |
| 40 | STATUS ON |
| 41 | TEMPLATE "bogus.html" |
| 42 | TOLERANCE 5 |
| 43 | CLASS |
| 44 | STYLE |
| 45 | SYMBOL "circle" |
| 46 | SIZE 0 |
| 47 | COLOR 0 0 0 |
| 48 | OUTLINECOLOR 0 0 0 |
| 49 | END |
| 50 | END |
| 51 | PROJECTION |
| 52 | "proj=latlong" |
| 53 | END |
| 54 | END |
| 55 | }}} |
| 56 | |
| 57 | == Access to styles has been changed in version 4.2. == |
| 58 | |
| 59 | $class->getStyle(0)->{symbol} = 0; |
| 60 | |
| 61 | (there is a hidden pen parameter that needs to be set) |
| 62 | |
| 63 | $style->setRGB(255, 0, 0); |
| 64 | |
| 65 | ---- |
| 66 | back to PerlMapScript |