[Mapserver-users] mapscript - strange behavior
Sean Gillies
sgillies at frii.com
Tue Jan 13 11:28:35 PST 2004
On Jan 13, 2004, at 10:38 AM, Christoph Spoerri wrote:
> Hi there,
>
> I'm writing an application that let's user add point features to the
> map by
> clicking on any location of the map. For this purpose I'm using the
> attached
> code (Note: each click on the map results in a request to the server
> for a
> new image).
>
> The problem is that the first point (to be mapped) is not displayed on
> the
> map. Yet when the user clicks on the map for the second time (to add a
> new
> point) both points show up. When checking the .map files everything
> looks
> fine: acetate layer is there, class definition looks fine and point
> coordinates are there.
>
> In case a predefine the acetate layer (w/ class def) in the base .map
> file,
> the first point shows up just fine. Note: this solution is not an
> option
> thought :(
>
> any ideas? Thanks in advance,
> Christoph
>
>
> *********** code ********************
>
> x = atof(param['x'])
> y = atof(param['y'])
> # create point object
> ptCoord = getMapPoint([x,y],self._map)
> ptObj = pointObj()
> ptObj.x=ptCoord[0]
> ptObj.y=ptCoord[1]
> lnObj = lineObj()
> lnObj.add(ptObj)
>
> # create new point layer with class and add shape
> mapImg=self._map.prepareImage()
> lyrAcetate = self._map.getLayerByName('acetate')
> if (not isinstance(lyrAcetate,layerObj)):
> color = colorObj()
> color.red = 255
> color.green = 255
> color.blue = 255
> lyrAcetate = layerObj(self._map)
> lyrAcetate.name = "acetate"
> lyrAcetate.type = MS_LAYER_POINT
> classTemp = classObj(lyrAcetate)
> styl = styleObj()
> styl.symbolname = "pin"
> styl.size = 1
> styl.maxsize = 1
> styl.minsize = 1
> styl.color = color
> styl.backgroundcolor = color
> styl.outlinecolor = color
> classTemp.numstyles=1
> classTemp.styles = styl
>
> # create shape object and add point to shape object
> shpObj = shapeObj(MS_SHAPE_POINT)
> shpObj.add(lnObj)
> shpObj.setBounds();
> shpObj.index = 1
>
> lyrAcetate.status = MS_ON
> lyrAcetate.addFeature(shpObj)
> lyrAcetate.draw(self._map,mapImg)
>
> imagename = \
> self._map.name+mapSession.id()+"_"+str(int(time()))+"."+mapImg.format.e
> xtension
> mapImg.save(mapImg.imagepath+imagename)
>
Christoph,
Do I remember correctly that you are using mod_python? Is this a reason
why you say that you cannot predefine your acetate layer? I hope you
are
not trying to persist a mapObj in the same way that mod_python users use
persistent database connections. MapServer is not fully thread-safe
(yet)
and so you will certainly encounter some trouble with a persistent
mapObj.
I don't see _anything_ in your code that would prevent the acetate layer
from being predefined in your map file. If it is only a matter of
colors and styles, I strongly recommend that you predefine the acetate
layer and then modify its classes and styles during the script
execution.
cheers,
Sean
--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies
More information about the MapServer-users
mailing list