[Chameleon] Drawing a Point

Ken Sanderson ken at rockies.ca
Thu Aug 12 12:15:58 EDT 2004


I just set this up two days ago for my own widget. 

I had two problems. First I couldn't get any coords from $szInputCoords,
was always returning with just one value, not two, and otherwise was
just not working right. I did a work around for that, which was
accessing the map coords that CursorPos widget put into the
CursorPos_X/CursorPos_Y text input boxes. Main problem with this, and a
reason I will eventually go back and change it, is that it relies then
on the CursorPos widget being used as well. I think I have made changes
that will fix my problem with the $szInputCoords so likely that's not
your problem, but here is what I did:
            $theX = "";
            $theX = $this->getVar("CursorPos_X");
            $theY = "";
            $theY = $this->getVar("CursorPos_Y");
            $pt->setXY($theX,$theY); 

The other main problem is that setXY needs to be in the units used by
your map. NAV_INPUT_COORDS are pixels values so unless your map units
are pixels its not going to work the way you have it set up. Another
quick and dirty reason I used the CursorPos inputs was because they have
already been converted and I can just input them directly into setXY.
Paul indicated that in geomath.php file (in the widget folder) there is
a function for converting from pixels to geographic coords that can be
used to convert the coords to something setXY can use. Alternately I
also had another interm work around of using the javascript functions
with my click function that converted the pixels to geographic coords
and put them in a hidden input which I then accessed via getVar(). This
works fairly well, removes reliance on another widget, but does mean you
need to add two hidden inputs to your main html template file. 

I think I will be changing mine to work with the NAV_INPUT_COORDS and
the geomath.php functions to convert it, just so my widget is stand
alone and requires no additions other then calling the widget.

Hope that helps,

Ken
Miistakis



-----Original Message-----
From: chameleon-bounces at lists.maptools.org
[mailto:chameleon-bounces at lists.maptools.org] On Behalf Of Ken-ichi
Sent: August 11, 2004 6:04 PM
To: chameleon at lists.maptools.org
Subject: [Chameleon] Drawing a Point


Hi again.  To learn about widget development, I'm trying to make a copy 
of the ZoomIn widget draw a point on the map instead of zooming in.  To 
that end, I've altered the ParseURL method so that the if( $szInputType 
== "POINT" ) clause looks like this:

            if ($szInputType == "POINT")
            {
                $aPixPos = explode(",", $szInputCoords);
               
                //draw a point with MapScript
                $map = $this->moMapNavigator->oSession->oMap;

                $daLayer = ms_newLayerObj($map);
                $daLayer->set("type", MS_LAYER_POINT);
                $daLayer->set("transform", MS_FALSE);
                $daLayer->set("status", MS_ON);
                      
                $class = ms_newClassObj($daLayer);
                $class->set("name", "Temp Class");
                $style = ms_newStyleObj($class);
                $style->color->setRGB(255,0,0);
                $style->set("symbolname", "circle");
                $style->set("size", 10);

                $my_point = ms_newPointObj();
                $my_point->setXY($aPixPos[0],$aPixPos[1]);
                     

                $image = $map->draw();
                     
                $temp = $my_point->draw( $map, $daLayer, $image, 0, 
"Temp Point" );

                if( $temp == MS_SUCCESS ) $daLayer->set("name", $temp);
            }

This successfully adds a layer to the legend with the correct styling, 
but fails to draw the point on the map.  Note that the last line does 
result in setting the name of the new layer to MS_SUCCESS (haven't 
figured out how to use any of Chameleon's debugging capabilities, if 
such things exist), so the draw() method thinks it's working.

Can anyone tell me what I'm doing wrong?  Many thanks.

-Ken-ichi
_______________________________________________
Chameleon mailing list
Chameleon at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/chameleon




More information about the Chameleon mailing list