[Cartoweb-dev] Implementing extra functionalities

oliver oliver.christen at camptocamp.com
Thu Jun 30 05:46:57 EDT 2005


Hello,

To create a new element at the coordinates of a click, you may create a new
plugin that extends the basic outline plugin.

That plugin will have to act on both client side and server sides.
I would suggest to use an existing plugin (maybe outline) as a template.
see
(http://www.cartoweb.org/doc/xhtml/dev.newplugin.html#dev.newplugin.adapting
) concerning plugin extension.

1) on the client side (
plugins\yournewpluginname\common\ClientYourNewPluginName.php)
create a new tool (see ToolProvider::getTools() ).
Set its type to SHAPE_POINT (JsToolAttributes::SHAPE_POINT). This will allow
the client to retrieve the x and y position where you clicked with the
mouse.

2) also on the client side , you need to add a buildRequest() function where
you will define a new shape element that you will pass to the server side.
Something like that:

public function buildRequest() {

  $newElement = new Point($this->Geo_x, $this->Geo_y);
    //Geo_x and Geo_y are the pixel x y coordinate
  $styledShape = new StyledShape();
  $styledShape->shape = $newElement;

  $shapeStyle = new ShapeStyle();

  $shapeStyle->symbol = $this->type;
    // use this if you want to select a symbole on the fly, set type as the
sympobl to use,
    //see the .sym file that should be in the /server_conf/*yourmap*/ folder
  $shapeStyle->size = 20;
  $shapeStyle->color->setFromRGB(51, 0, 204);
  $shapeStyle->outlineColor->setFromRGB(0, 0, 0);

  $styledShape->shapeStyle = $shapeStyle;

  $yournewpluginnameRequest = new YourNewPluginNameRequest();
  $yournewpluginnameRequest->shapes = array($styledShape);

  return $yournewpluginnameRequest; // see point 3)
}

Also, you may need to convert the x/y values from pixels to geographical
coordinates. See the point2Coords function in the PixelCoordsConverter
Class.
Something like that:

$plugins = $this->cartoclient->getPluginManager();

$imageSize = $plugins->images->getMainmapDimensions();
$bbox = $plugins->location->getLocation();

$pixelPoint = new Point($array_coord[0], $array_coord[1]);
$newpoint = PixelCoordsConverter::point2Coords($pixelPoint, $imageSize,
$bbox);
$this->Geo_x = round($newpoint->x);
$this->Geo_y = round($newpoint->y);

3) you need a common file (
plugins\yournewpluginname\common\YourNewPluginName.php) to handle the
unserialization of the shape element sent from client side to server side.
class YourNewPluginNameRequest extends Serializable {

  /**
   * Styled shapes to be drawn
   * @var array
   */
  public $shapes;

  /**
   * @see Serializable::unserialize()
   */
  public function unserialize($struct) {
    $this->shapes = self::unserializeObjectMap($struct, 'shapes',
                                               'StyledShape');
  }
}

3a) you need to add a wsdl.inc file in your common folder. Simply copy the
one from the plugin outline. This is needed for the serialize/unserialize
function.

4) in the server file (
plugins\yournewpluginname\server\ServerYourNewPluginName.php), recover the
$requ containing the shape and draw it on the map.
see function initializeRequest($requ) and handlePreDrawing($requ).
To draw, simply call $pluginManager->outline->draw($this->shapes) in your
handlePreDrawing function.

5) I would suggest to put the coords of your element in session if you want
it to be persistant. And have your plugin check the session if one element
is stored and recover the coords then follow the normal treatments to draw
it (point 2-4).

That should cover most of the treatment logic.
Replace all "yournewpluginname" by the name you will use for your plugin.

Please note, maybe you will need to get the current cvs version of cartoweb
(available from the cvs link
on www.cartoweb.org) for this this work correctly.

Regards
Oliver Christen



> What I would like to have is the possibility to click the maps as a link
and
> send it to another page like this: page.php?xcoord=320&ycoord=2340. This
is
> just an example ofcourse, but I know it's possible. The other thing is
> putting in a spot on the map using the coordinates I stored. I know that's
> possible as well, but I'll need help with it, I hope you can help me.
>
> yours sincerely,
>
> Yorian van Leeuwen
>
>
> _______________________________________________
> Cartoweb-dev mailing list
> Cartoweb-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/cartoweb-dev
>



More information about the Cartoweb-dev mailing list