prepareImage() || draw()

Sean Gillies sgillies at FRII.COM
Fri Jan 21 10:40:24 EST 2005


On Jan 21, 2005, at 8:27 AM, Aaron Craig wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I'm confused about how we're supposed to draw the final map image
> through mapscript.
>
> I want to get a mapfile loaded, add a layer with some lines on it
> connecting some dots already present in another layer.  In pseudo code,
> I'm doing more or less:
>
> mapObj = mapscript::mapObj->new("mapfile.map");
> imgObj = mapObj->prepareImage();
>
> pntA = mapscript::pointObj->new();
> pntA->setXY(X, Y);
> pntA->draw(map, lyrObj, imgObj, null, "");
> pntB = mapscript::pointObj->new();
> pntB->setXY(X, Y);
> pntB->draw(map, lyrObj, imgObj, null, "");
>
> linObj = mapscript::lineObj->new();
> linObj->add(pntA);
> linObj->add(pntB);
>
> shpObj = mapscript::shapeObj->new(MS_SHAPE_LINE);
> shpObj->add(linObj);
> shpObj->{index} = 0; # is this necessary?
>
> lyrObj = mapscript::layerObj->new(mapObj);
> mapObj->insertLayer(lyrObj);
>
> lyrObj->{status} = MS_ON;
> lyrObj->addFeature(shpObj);
> lyrObj->draw(mapObj, imgObj);
>
> imgObj->save("file.png");
>
> Which results in an empty image.
>
> If instead of calling prepareImage() I call draw(), then I get the map
> drawn as described in the mapfile, without my new layer.
>
> Help?
>

Aaron, your inline layer needs classes and styles for symbolization of
the shape.  Also, only add features to the layer *after* you've
inserted it into the map.  Remember, MapServer cannot deal with map
elements by reference and so insertLayer makes a *copy* in the mapObj.
You'll need to add features to that copy and not to the original layer.

Sean

--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies



More information about the mapserver-users mailing list