[Cartoweb-users] new tool to the Toolbar

Pierre GIRAUD pierre.giraud at camptocamp.com
Thu Sep 7 04:25:57 EDT 2006


Jonathan Gillot wrote:

> Hello,
>
> first thanks for your answer i began to despair.
>
> I already have implemented the ToolProvider interface and her 4 
> methods. Its works but when i click on the tool it would not be 
> selected. but if i remove "mainmap.{$tool->id}('map');" from 
> toolbar.tpl it could be selected but nothing occurs (off course).do 
> you think this could be because i don't have write the javascript 
> methods yet? could you give me more details on the way to implement 
> the javascript methods? i'm a little bit confused.
>
> thanks in advance
>
> Jonathan

Hello,

Of course the tool won't work if you don't set the javascript method.
When clicking on a tool, the mainmap.name_of_the_tool() method is 
called. If it doesn't exist, a javascript error occurs.
To get more informations on the javascript errors, I advice you to have 
a javascript debugger. In firefox, there is an great extension called 
Firebug that may help you this way.

If we go back to your needs, as you want a tool that allows user to 
click on the map to send the clicked coordinates to the server, the 
javascript method should look like :

Map.prototype.routing_from = function(aDisplay) {
  // reset event handlers on the map element (required)
  this.resetMapEventHandlers();
 
  // uses the drawing layer as the current one
  this.setCurrentLayer('drawing');
  // the chosen tool will let user to select by point
  this.getDisplay(aDisplay).setTool('sel.point');
  // cursor on map can be changed for this specific tool
  this.getDisplay(aDisplay).docObj.style.cursor = "pointer";
  // when point is selected, do specific stuff
  this.onSelPoint = function(x, y) {
    // store the given coordinates into an form input
    document.forms['carto_form'].routing_from.value = x + "," + y;
    // clear the drawings in the drawing layer
    this.getDisplay(aDisplay).clearLayer('drawing');
    ...
  }
};

Hope this will help you.

Regards

Pierre


More information about the Cartoweb-users mailing list