[Chameleon] Adding Points

Ken Sanderson ken at rockies.ca
Mon Aug 9 16:25:31 EDT 2004


Thanks Eric, added your example to my list to refer to when I get to
working out these details.

I am however still stuck at the problem of using these functions in a
NavTool extend instead of CWCWidget, or adversly using NavTool functions
with CWCWidget.

Ken

-----Original Message-----
From: Eric Bridger [mailto:eric at gomoos.org] 
Sent: August 9, 2004 2:10 PM
To: Ken Sanderson
Cc: wbronsema at dmsolutions.ca; chameleon at lists.maptools.org
Subject: RE: [Chameleon] Adding Points


I am a new to Chameleon also, so can't answer most of your questions,
but I created a custom widget is used to add labels to a map. Below is
some code which should work with minor modifications to put a symbols on
the map. This is done in the ParseURL() method of a widget which extends
CWCWidget.

$oLayer = $this->moMapObject->oMap->getLayerByName('contaminant_label');
$oLayer->set("status", MS_ON);

$pt = ms_newPointObj();
$ln = ms_newLineObj();
$shp = ms_newShapeObj(MS_SHAPE_POINT);
// we need a single point line since shapeObj can't add just points.
$pt->setXY($label_x,$label_y); $ln->add($pt); $shp->add($ln);
$shp->set("text", $theLabel); $oLayer->addFeature($shp);

I let Chameleon do the drawing, just turn the layer on and add a FEATURE
at the correct place.  It also works when adding mulitple FEATURE's to
the LAYER, i.e. more than one point.

Here is the definition of the contaminant_label layer:

LAYER
  NAME "contaminant_label"
  STATUS OFF
  TRANSFORM FALSE
  TYPE ANNOTATION
  CLASS
    STYLE
    END
    LABEL
      TYPE TRUETYPE
      FONT arial
      SIZE 12
      COLOR 0 0 0
      ANTIALIAS TRUE
      POSITION LR
      PARTIALS FALSE
      BUFFER 0 
    END
  END
END 


Note: I have TRANSFORM FALSE, since my x, y are pixels not geographic
coordinates. You could make the layer TYPE POINT, add a SYMBOL, etc. and
don't set the 'text' of the FEATURE it should work.

Eric


On Mon, 2004-08-09 at 15:29, Ken Sanderson wrote:
> Thanks Will for the reply.
> 
> I have sorta been a bit down this road before and I am having a 
> problem with the classes. I really don't have a lot of experience with

> PHP classes so I find it hard to follow all the dependancies, but from

> what I can tell $this->moMapObject->oMap needs to be with a widget 
> that's an extend of the CWCWidget?
> 
> My widget I have created does the following:
> 1) loads the button image with the other Navigation tools, sets the 
> appropriate NavCommand when its selected.
> 2) user clicks on the map, it gets the pixel coords, converts to 
> geographic coords, then sends to a PHP script that loads up a userform

> to collect some specific information about the point.
> 3) this is the part I am struggling with: want to display a point on 
> the map where the user clicked and add another if they click again. I 
> have the coords from step 2, but still need to find a way of adding 
> the point.
> 
> For parts one and two I have it setup so that my widget class extends 
> NavTool. I assume you can't extend to more then one object? So my 
> question is how do I access both the NavTool and CWCWidget in order to

> use $this->moMapObject->oMap?
> 
> Thanks again,
> 
> Ken
> 
> -----Original Message-----
 
> To: Ken Sanderson
> Cc: chameleon at lists.maptools.org
> Subject: Re: [Chameleon] Adding Points
> 
> 
> Hi Ken,
> 
> Ken Sanderson wrote:
> > A few more questions in regards to adding a point, or points, to the
> > map within Chameleon. Been tossing around various ideas so my 
> > questions are a bit mixed:
> > 
> > 1) I have been looking over the mapscript examples, which are fairly
> > clear, what I don't understand is how I hook into the map/image that

> > chameleon is going to return vs returning another image with my
points
> 
> > on it. Is there a way to reference the map object that chameleon is
> > using from another widget and add points to it?
> Widgets have access to the map object by using: 
> $this->moMapObject->oMap.
> 
> There are a number of widgets to look at that reference the map
object. 
>   Take a look at the expressionbuilder.widget.php file for example
> (specifically the parseURL function).
> 
> > 
> > 2) Another method I found an exmaple on was the 
> > MapImageSharedResource
> 
> > in conjunction with SQLQuery Widget, only in my case I would likely
> > create a widget to build the array of points in another method. It 
> > says in the example: "where you want your map, you should include
the 
> > MapImageSharedResource". Where is that supposed to be? In the 
> > MAPDHTMLWIDGET table?
> Sorry, I'm not too familiar with using the SQLQuery widget.  I'll 
> leave
> that to someone else to answer.
> 
> > 
> > 3) Lastly while poking around in the drawmap.php file I found some
> > references to pulling points from the URL, specifically: "Draw
points 
> > from URL if necessary" section. Has anyone used this or knows if
there
> 
> > is any functions/widgets/documentation on how this might be used?
> To the best of my knowledge there is nothing in Chameleon that is 
> making
> 
> use of that point drawing functionality.  The drawmap.php file has a
> fairly long history and this code, I believe, was added pre-Chameleon.
> 
> Although I don't think there is a way in Chameleon to access this
> functionality, it appears that the code is a complete example of how
to 
> add points to a new layer in your mapfile (although I haven't tried it
-
> 
> it looks like it should).
> 
> In a nutshell, what you'll need to do is create a new widget and copy
> the point creation code to it.  This will involve referencing the map 
> object as indicated in question 1 ($this->moMapObject->oMap) as well
as 
> collecting point information (possibly as indicated in question 2 - or

> some other way).
> 
> Hope that helps.
> 
> Regards,
> Bill
> 
> --
> ________________________________________________
> 
>   William A. Bronsema, C.E.T.
>   Applications Developer,
>   DM Solutions Group Inc.
 




More information about the Chameleon mailing list