Dynamic Layer Creation Problem
Stephen Woodbridge
woodbri at SWOODBRIDGE.COM
Sat Oct 29 18:36:43 PDT 2005
Yeah! Got it to work:
if ($line->{numpoints}) {
warn "numpoints=$line->{numpoints}\n";
my $lay = new mapscript::layerObj($map);
$lay->{status} = 1;
$lay->{type} = $mapscript::MS_LAYER_LINE;
$lay->{name} = "tsp_route";
my $class = new mapscript::classObj($lay);
$class->{status} = 1;
my $style = new mapscript::styleObj($class);
$style->{color} = new mapscript::colorObj();
$style->{color}->setRGB(255,0,0);
#$style->{size} = 1;
#$style->{symbol} = 0;
warn "numclasses=$lay->{numclasses}\n";
warn "numstyles=$class->{numstyles}\n";
warn "color=" . $style->{color}->toHex() . "\n";
my $shp = new mapscript::shapeObj($mapscript::MS_SHAPE_LINE);
$shp->{classindex} = 0;
$shp->add($line);
$shp->setBounds();
#$shp->draw($map, $lay, $img); #<<<<< seems this does not work!!!
$lay->addFeature($shp); #<<
my $err = $lay->draw($map, $img); #<< But this does
warn "draw err=$err\n"; #<<
my $errObj = new mapscript::errorObj();
while ($errObj) {
warn "$errObj->{code}:$errObj->{message}:$errObj->{routine}\n";
$errObj = $errObj->next();
}
}
-Steve W.
Stephen Woodbridge wrote:
> Hi Sean,
>
> Thank you for the response. I tried adding that and still no joy. The
> code looks like this now:
>
> if ($line->{numpoints}) {
> warn "numpoints=$line->{numpoints}\n";
> my $lay = new mapscript::layerObj($map);
> $lay->{status} = 1;
> $lay->{type} = $mapscript::MS_LAYER_LINE;
> $lay->{name} = "tsp_route";
>
> my $class = new mapscript::classObj($lay);
> $class->{status} = 1;
> my $style = new mapscript::styleObj($class);
> $style->{color} = new mapscript::colorObj();
> $style->{color}->setRGB(255,0,0);
> $style->{size} = 1;
> $style->{symbol} = 0;
>
> warn "numclasses=$lay->{numclasses}\n";
> warn "numstyles=$class->{numstyles}\n";
> warn "color=" . $style->{color}->toHex() . "\n";
>
> my $shp = new mapscript::shapeObj($mapscript::MS_SHAPE_LINE);
> $shp->{classindex} = 0;
> $shp->add($line);
> $shp->setBounds();
> $shp->draw($map, $lay, $img);
> }
>
> Any other ideas, would be appreciated.
>
> -Steve W.
>
> Sean Gillies wrote:
>
>> On Oct 29, 2005, at 6:54 PM, Stephen Woodbridge wrote:
>>
>>> Hi all,
>>>
>>> I know this has been covered before but I haven't been able to find
>>> anything that helps. I'm doing perl mapscript.
>>>
>>> if ($line->{numpoints}) {
>>> warn "numpoints=$line->{numpoints}\n"; # reports 257
>>> my $lay = new mapscript::layerObj($map);
>>> $lay->{status} = 1;
>>> $lay->{type} = $mapscript::MS_LAYER_LINE;
>>> $lay->{name} = "tsp_route";
>>>
>>> my $class = new mapscript::classObj($lay);
>>> #$class->{status} = 1; # doesn't help
>>>
>>> my $style = new mapscript::styleObj($class);
>>> # what should the value for pen be? tried 0 and 1 to no luck
>>> $style->{color} = new mapscript::colorObj(255,0,0,1);
>>> #$style->{size} = 1; # doesn't help
>>> #$style->{symbol} = 1; # doesn't help
>>>
>>> warn "numclasses=$lay->{numclasses}\n"; # reports 1
>>> warn "numstyles=$class->{numstyles}\n"; # reports 1
>>>
>>> my $shp = new mapscript::shapeObj($mapscript::MS_SHAPE_LINE);
>>> $shp->add($line);
>>> $shp->draw($map, $lay, $img);
>>> }
>>>
>>> This code is running but is not drawing the polyline, $line->
>>> {numpoints}
>>> = 257 points.
>>>
>>> Yes, I know I can template this in the mapfile, but I would rather not.
>>> We have all these function in mapscript and it seems they should just
>>> work if you do the logical thing like above.
>>>
>>> -Steve W.
>>>
>>
>> Steve,
>>
>> You're neglecting to set the classindex attribute of your "shp"
>> shapeObj. There are other problems in your code as well, but that's
>> most likely the main one.
>>
>> Sean
>>
>>
>> ---
>> Sean Gillies
>> sgillies at frii dot com
>> http://zcologia.com
>>
>
More information about the MapServer-users
mailing list