Contents
Modification of the other HowTo, tested with CartoWeb 3.4.0
There are 4 files, 1 on client side, 2 in common and 1 on server side, as in the original HowTo.
Also, in this example, the database table used may be created with this sql:
SQL code
CREATE TABLE vehicle_data (vhdt_id serial not null, vhdt_x integer, vhdt_y integer, vhdt_name varchar(32));
The plugin files are these:
CLIENT SIDE (ClientPruebaRmVehicle.php)
<?php class ClientPruebaRmVehicle extends ClientPlugin implements ServerCaller { private $vehicleCoords; private $vehicleName; private $type; public function initialize() { $this->vehicleCoords = array(); $this->vehicleCoords['x'] = ''; $this->vehicleCoords['y'] = ''; $this->vehicleName = ''; $this->type = 'line'; $db = $this->getDb(); // here may be any query you need... // this is only a example $sql = 'SELECT * FROM vehicle_data WHERE vhdt_nombre <> 0'; $result = $db->query($sql); if (DB::isError($result)) { throw new CartoclientException($result->getMessage()); } $row = NULL; while ($result->fetchInto($row, DB_FETCHMODE_ASSOC)) { $this->vehicleCoords['x'] = $row['vhdt_x']; $this->vehicleCoords['y'] = $row['vhdt_y']; $this->vehicleName = $row['vhdt_nombre']; } } private function getDb() { require_once('DB.php'); if (is_null($this->db)) { $dsn = "pgsql://username:password@localhost/dbname"; if (!$dsn) { throw new CartoclientException('Search database DSN not found'); } $this->db = DB::connect($dsn); } return $this->db; } /** * @see ServerCaller::buildRequest() */ public function buildRequest() { // we call for a new shape only if we have a x and y if ($this->vehicleCoords['x'] != '' and $this->vehicleCoords['y'] != '') { $newElement = new Point($this->vehicleCoords['x'], $this->vehicleCoords['y']); $styledShape = new StyledShape(); $styledShape->shape = $newElement; $shapeStyle = new StyleOverlay(); $shapeStyle->symbol = $this->type; $shapeStyle->size = 10; $shapeStyle->color->setFromRGB(51, 0, 204); $shapeStyle->outlineColor->setFromRGB(0, 0, 0); $styledShape->shapeStyle = $shapeStyle; $labelStyle = new LabelOverlay(); $labelStyle->font = 'Vera'; $labelStyle->color = new ColorOverlay(); $labelStyle->color->setFromRGB(51, 0, 204); $styledShape->labelStyle = $labelStyle; $styledShape->label = $this->vehicleName; $PruebaRmVehicleRequest = new PruebaRmVehicleRequest(); $PruebaRmVehicleRequest->shapes = array($styledShape); return $PruebaRmVehicleRequest; } } /** * @see ServerCaller::initializeResult() */ public function initializeResult($result) {} /** * @see ServerCaller::handleResult() */ public function handleResult($result) {} ?>
COMMON (PruebaRmVehicle.php)
<?php class PruebaRmVehicleRequest extends CwSerializable { /** * Styled shapes to be drawn * @var array */ public $shapes; /** * @see CwSerializable::unserialize() */ public function unserialize($struct) { $this->shapes = self::unserializeObjectMap($struct, 'shapes', 'StyledShape'); } } /** * Result * @package Plugins */ class PruebaRmVehicleResult {} ?>
COMMON (PruebaRmVehicle.wsdl.inc)
<!-- outline --> <complexType name="Color"> <all> <element name="r" type="xsd:int"/> <element name="g" type="xsd:int"/> <element name="b" type="xsd:int"/> </all> </complexType> <complexType name="ShapeStyle"> <all> <element name="symbol" type="xsd:int"/> <element name="size" type="xsd:int"/> <element name="color" type="types:Color"/> <element name="outlineColor" type="types:Color"/> <element name="backgroundColor" type="types:Color"/> <element name="transparency" type="xsd:int"/> </all> </complexType> <complexType name="LabelStyle"> <all> <element name="font" type="xsd:int"/> <element name="size" type="xsd:int"/> <element name="color" type="types:Color"/> <element name="outlineColor" type="types:Color"/> <element name="backgroundColor" type="types:Color"/> </all> </complexType> <complexType name="StyledShape"> <all> <element name="shapeStyle" type="types:ShapeStyle"/> <element name="labelStyle" type="types:LabelStyle"/> <element name="shape" type="types:Shape"/> <element name="label" type="xsd:string"/> </all> </complexType> <complexType name="ArrayOfStyledShape"> <complexContent> <restriction base="enc11:Array"> <attribute ref="enc11:arrayType" wsdl:arrayType="types:StyledShape[]"/> </restriction> </complexContent> </complexType> <complexType name="OutlineRequest"> <all> <element name="className" type="xsd:string"/> <element name="shapes" type="types:ArrayOfStyledShape"/> <element name="maskMode" type="xsd:boolean"/> </all> </complexType> <complexType name="OutlineResult"> <all> <element name="className" type="xsd:string"/> <element name="area" type="xsd:double"/> </all> </complexType>
SERVER SIDE (ServerPruebaRmVehicle.php)
<?php class ServerPruebaRmVehicle extends ClientResponderAdapter { /** * @var Logger */ private $log; /** * @var objet */ private $shapes; /** * Constructor */ function __construct() { parent::__construct(); $this->log =& LoggerManager::getLogger(__CLASS__); } /** * @see ClientResponder::initializeRequest() */ function initializeRequest($requ) { if ($requ) $this->shapes = $requ->shapes; } /** * Result is set in initializeRequest but Outline must be called * in handlePreDrawing * @see ClientResponder::handlePreDrawing() */ function handlePreDrawing($requ) { if ($requ) { $pluginManager = $this->serverContext->getPluginManager(); if (empty($pluginManager->outline)) throw new CartoserverException("outline plugin not loaded, " . "and needed to draw the new element"); $pluginManager->outline->draw($this->shapes); } } } ?>