[Cartoweb-users] query tools with different icons

Oliver Christen oliver.christen at camptocamp.com
Fri Feb 2 09:33:35 EST 2007


Hi valerio
this is certainly possible but also delicate.

you will need to touch php client side and server side and also some 
javascript.

concerning the tool itself:

for the php, you will probably need to extend the query plugin and add new 
tools definition to the getTools() function.

to help you a bit, new ToolDescription(self::TOOL_QUERY_BY_BBOX, true, 41) 
this will define a new tool, whose name will be defined by 
self::TOOL_QUERY_BY_BBOX (you can use a string like 'mynewquerytool' , the 
notation used here allow us to change the name without changing the code, 
but you dont need to use it).
The name is important as it is the identifiant for that tool which will be 
used in the web interface and also in the javascript. The second parameter 
say if the tool has an icon or not. This is usually true. third is the 
weight, in other words, the place of the tool in the toolbar. There are 
other parameters (see client/ClientPlugin.php) but you probably dont need 
them.

Now the javascript part. All tools action are handled by the dhtmlAPI.js, 
dhtmlFeatures.js and dhtmlInit.js.
This is probably the less userfriendly part of cartoweb.

What you need to do is, in a new javascript file, copy the existing 
properties and methodes of the existing query tool that meet the beahaviour 
you need (for exemple query_by_bbox).

Since the behaviour is the same, you wont have to duplicate this, 
fortunately.
You will have something like :
Map.prototype.mynewquerytool = function(aDisplay) {
  this.selectionBox(aDisplay, 'Query.Perform');
  this.getDisplay(aDisplay).docObj.style.cursor = "help";
};

then include that javascript in your main template header, like the other 
javascript files.

Thats only for "duplicating" a query tool.

Now, for the database switch.... I will do some wild guess as I never had 
such problem before.

If the database connection is set in the layers connection parameter, it 
means :
either you have two layers and activate one or the other depending of the 
query tool selected,
or you need to change the connection on-the-fly depending of the query tool 
selected.

I must say i dont really see how to change the layer on which the query is 
done. Maybe with a filterPostRequest but I think the query plugin use the 
list of activated layers before the query, obtained from the layer plugin. 
And I wouldnt mess with that personally. Maybe someone else has a better 
idea...

To change a layer parameter on-the-fly, you can do that on the server side, 
in the function handlepreDrawing with some use of mapOverlay plugin.
This is done on the server side part of the query plugin, so you will need 
to extend this too.
For that, first, enable the mapOverlay plugin in the server side 
yourproject.ini file (where the other plugins for server side are listed for 
activation)

below is an exemple on how to change some layer properties:

public function handlePreDrawing($request) {
        if (isset($this->selectid) && !empty($this->selectid)) {
         $layer = new LayerOverlay();
         $layer->name = "vue_recenter";
         $layer->data = "position FROM (SELECT * FROM vue_recenter WHERE 
filtre_id = ".$this->selectid.") as foo USING UNIQUE bien_id USING SRID=-1";

         $mapOverlay = $this->serverContext->getPluginManager()->mapOverlay;
         if ($mapOverlay == NULL) {
            throw new CartoserverException('Plugin MapOverlay must be 
activated!');
         }
         // update layer
         $mapOverlay->updateMap($layer);

        }
}

in this case we changed the DATA value from the layer vue_recenter, but you 
can probably do the same with the CONNECTION value.
the important part is you need to pass some parameter from client side to 
server side to activate the change (in the "if" condition). So you need to 
modify a bit the buildRequest() function (client side) to pass that 
parameter (for exemple the name of the tool used) on the server side. on the 
server side, the paramter will be in $request, which directly is available 
in handlePreDrawing.

This is certainly not easy but it is possible ;)

Good luck
Oliver

----- Original Message ----- 
From: "Valerio Noti" <valerionoti at yahoo.it>
To: <cartoweb-users at lists.maptools.org>
Sent: Friday, February 02, 2007 10:37 AM
Subject: [Cartoweb-users] query tools with different icons


> Hello,
> I'd like to duplicate a query tool in cartoweb interface in order to have
> two buttons (different icons) with query functionality but with separate 
> tasks.
> These separate tasks are not cartoweb-dependant (i.e. a different database 
> to connect).
> So perhaps my problem it how to assign two different icons to the same 
> tool.
>
> Any help appreciated
>
> thanks in advance
>
> Valerio
>
> /*
> Valerio Noti
> valerionoti at yahoo.it
> */
> _______________________________________________
> Cartoweb-users mailing list
> Cartoweb-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/cartoweb-users
> 



More information about the Cartoweb-users mailing list