Drawing points and lines dynamically

sc sc at BYTRON.COM
Fri Apr 15 10:56:24 EDT 2005


Hi Camden

I have altered my code to use your function but I still cannot see my
'point',  I have also switched
off all other layers and it is still not visible.  Following is an extract
of the code I am using and
part of the map file.

My other layers are all in Lambert Conformal Conic projection, could this be
where the problem lies?

The EXTENTs were arrived at by using ogrinfo -so on my shapefile.

regards

Simon

# Code Extract

$layer = ms_newLayerObj($map);
$layer->set("name","Route");
$layer->set("type",MS_LAYER_POINT);
$layer->set("status", MS_ON);
add_point_to_layer($layer, 0.0, 54.0);
$image = $map->draw();


# Map file extract

MAP
    NAME UK
    STATUS ON
    SIZE 800 600
    IMAGETYPE PNG
    IMAGECOLOR 170 210 250
    SHAPEPATH "/usr/local/apache/htdocs/map/data/conic"
    EXTENT -994934.821920 5173124.716504 322333.423383 6431993.097353
    #UNITS MILES



-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU]On
Behalf Of Camden Daily
Sent: 15 April 2005 14:06
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] Drawing points and lines dynamically


If you turn off all of the other layers, can you see the point then?
It might be a matter of extents or projections.  Are your extents in
latitude/longitude degrees as well?

> One thing that I am confused about is to whether or not the layer that I
> want to create the point
> on has to be already defined in the map file or whether the code below
> actually creates a 'dynamic'
> layer.

It creates a dynamic layer.  You do not need to pre-define the layer
in the .map file.  Althought I've not actually tried it, I believe
that you could make your entire .map file definition through
mapscript.

I'm not sure why else the point might not show up, but I would suggest
looking at the layer->addFeature() function.  I think it's much more
straightforward than drawing the map, and then calling point->draw()
over it.  Just do something like this to add a point to a layer:

function add_point_to_layer($layer, $longitude, $latitude) {
  // create and initialize new point object
  $point = ms_newPointObj();
  $point->setXY($longitude, $latitude);
  // create and initialize new line object
  $line = ms_newLineObj();
  $line->add($point);
  // create and initialize new shape object
  $shape = ms_newShapeObj(MS_SHAPE_POINT);
  $shape->add($line);
  // add our shape
  $layer->addFeature($shape);
}

Then, once you've added the points, just call $image = $map->draw();
and everything should draw nicely.

-Camden

> regards
> Simon
>
> $layer = ms_newLayerObj($map);
> $layer->set("name", "Route");
> $layer->set("type", MS_LAYER_POINT);
> $layer->set("status", MS_DEFAULT);
> $layer->set("transform", TRUE);
>
> $class = ms_newClassObj($layer);
> $class->label->set("font", "arial");
> $class->label->color->setRGB(255, 0, 0);
>
> $symbol = $map->getSymbolByName("circle");
> $style = ms_newStyleObj($class);
> $style->set("symbol", $symbol);
> $style->set("size", 8);
> $style->color->setRGB(255, 0, 0);
>
> $image = $map->draw();
>
> $point = ms_newPointObj();
> $point->setXY(0.0, 54.0);
> $point->draw($map, $layer, $image, 0, "test");
> $image_url=$image->saveWebImage();
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.308 / Virus Database: 266.9.11 - Release Date: 14/04/2005
>


--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.11 - Release Date: 14/04/2005

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.11 - Release Date: 14/04/2005



More information about the mapserver-users mailing list