[Cartoweb-users] Cartoweb and Ajax

Simon ORTET simon.ortet at silogic.fr
Mon Jul 23 11:57:32 EDT 2007


My mistake:
I changed the 2 lines
/       var mw = pluginOutput.variables.mainmap_width;
       var mh = pluginOutput.variables.mainmap_height; /
with
/       var mw = pluginOutput.variables.mainmap_width+'px;
       var mh = pluginOutput.variables.mainmap_height+'px'; /
and it works fine! :-[

So to sum up for anyone interested:

*Concerning FullExtent in Ajax:*
1. Modify dhtmlInit.js, Map.prototype.fullextent
         /CartoWeb.trigger('Location.FullExtent', "doSubmit()");          /
2. Modify location.ajax.js, buildPostRequest method
         /return 'full_extent=full_extent&'+AjaxHandler.buildPostRequest();/
3. Modify ClientLocation.php
    a. handleHttpPostRequest method:
/if (!empty($request['full_extent'])) {
    $this->locationRequest = $this->handleFullExtent();
    if (!is_null($this->locationRequest)) {
        return;
    }
} /
    b. ajaxHandleAction method to update other plugins:
/        case 'Location.FullExtent':
                $pluginEnabler->disableCoreplugins();
                $pluginEnabler->enablePlugin('location');
                $pluginEnabler->enablePlugin('layers');
                $pluginEnabler->enablePlugin('images');       /    

*Concerning MapSize in Ajax:
*1. Modify mapsize select in cartoclient template to have:
/    onchange="javascript:CartoWeb.trigger('Images.changeMapSize', 
'doSubmit()');"/
2. Add these lines to Images.ajax.js
/AjaxPlugins.Images.Actions.changeMapSize = {
    buildPostRequest: function(argObject) {
        return AjaxHandler.buildPostRequest();
    },
};/
3. Modify handleResponse from Images.ajax;js
        /// Updates mapsize elements
        var mw = pluginOutput.variables.mainmap_width+'px';
        var mh = pluginOutput.variables.mainmap_height+'px';
       
        AjaxHandler.updateDomElement('needJsDiv','style.width',mw);
        AjaxHandler.updateDomElement('needJsDiv','style.height',mh);
        AjaxHandler.updateDomElement('loadbarDiv','style.width',mw);
        AjaxHandler.updateDomElement('loadbarDiv','style.height',mh);
        AjaxHandler.updateDomElement('map','style.width',mw);
        AjaxHandler.updateDomElement('map','style.height',mh);
        AjaxHandler.updateDomElement('map_rootLayer','style.width',mw);
        AjaxHandler.updateDomElement('map_rootLayer','style.height',mh);
        
AjaxHandler.updateDomElement('map_rootLayer','style.clip','rect(0pt, 
'+mw+', '+mh+', 0pt)');
        AjaxHandler.updateDomElement('map_raster','style.width',mw);
        AjaxHandler.updateDomElement('map_raster','style.height',mh);
        
AjaxHandler.updateDomElement('map_raster','style.clip','rect(0px, 
'+mw+', '+mh+', 0px)');
        AjaxHandler.updateDomElement('map_eventPad','style.width',mw);
        AjaxHandler.updateDomElement('map_eventPad','style.height',mh);
        
AjaxHandler.updateDomElement('map_eventPad','style.clip','rect(0px, 
'+mw+', '+mh+', 0px)');
        AjaxHandler.updateDomElement('map_drawing','style.width',mw);
        AjaxHandler.updateDomElement('map_drawing','style.height',mh);
        
AjaxHandler.updateDomElement('map_drawing','style.clip','rect(0px, 
'+mw+', '+mh+', 0px)');/
*
*Thanks again Oliver for your helpfull advices.

Simon Ortet

*
*Simon ORTET a écrit :
> Thanks for your help.
> I managed to deal with the fullextent.
> Concerning mapsizes, it's tricky and here's what i've done:
>
> I modified the handleResponse from Images.ajax.js to update the DOM.
> I catch no error but this script is not working. The image map is at 
> requested size (so no problem in server side) but there's something i 
> don't understand: in the updateDomElement function, instead of 
> 'style.width' the value of property parameter is 'undoClipping'.
> I can't figure out why. I pass a string 'style.width' and i receive 
> 'undoClipping'. But there are no instruction between the call of  
> updateDomElement and it's first line (i tested in step mode with 
> Firebug).
> I didn't find anything on Google neither
>
>
> Here is what i added in the handleResponse method
>        // Updates mapsize elements
>        var mw = pluginOutput.variables.mainmap_width;
>        var mh = pluginOutput.variables.mainmap_height;
>        AjaxHandler.updateDomElement('needJsDiv','style.width',mw);
>        AjaxHandler.updateDomElement('needJsDiv','style.height',mh);
>        AjaxHandler.updateDomElement('loadbarDiv','style.width',mw);
>        AjaxHandler.updateDomElement('loadbarDiv','style.height',mh);
>        AjaxHandler.updateDomElement('map','style.width',mw);
>        AjaxHandler.updateDomElement('map','style.height',mh);
>        AjaxHandler.updateDomElement('map_rootLayer','style.width',mw);
>        AjaxHandler.updateDomElement('map_rootLayer','style.height',mh);
>        AjaxHandler.updateDomElement('map_rootLayer','clip','rect(0pt, 
> '+mw+'px, '+mh+'px, 0pt)');
>        AjaxHandler.updateDomElement('map_raster','style.width',mw);
>        AjaxHandler.updateDomElement('map_raster','style.height',mh);
>        AjaxHandler.updateDomElement('map_raster','clip','rect(0px, 
> '+mw+'px, '+mh+'px, 0px)');
>        AjaxHandler.updateDomElement('map_eventPad','style.width',mw);
>        AjaxHandler.updateDomElement('map_eventPad','style.height',mh);
>        AjaxHandler.updateDomElement('map_eventPad','clip','rect(0px, 
> '+mw+'px, '+mh+'px, 0px)');
>        AjaxHandler.updateDomElement('map_drawing','style.width',mw);
>        AjaxHandler.updateDomElement('map_drawing','style.height',mh);
>        AjaxHandler.updateDomElement('map_drawing','clip','rect(0px, 
> '+mw+'px, '+mh+'px, 0px)');
>
>
> Thanks
>
> Simon Ortet
>
>
>
>
> Oliver Christen a écrit :
>> The problem is some event are not handled in the same way, so simply 
>> faking a post via ajax will not effectively trigger the event.
>> And also Im not even talking about the returned value(s) which are 
>> not formated in the same way.
>>
>> For the fullextent, this was already discussed :
>> http://lists.maptools.org/pipermail/cartoweb-users/2007-February/002058.html 
>>
>> http://lists.maptools.org/pipermail/cartoweb-users/2007-April/002402.html 
>>
>>
>> For mapsize, the idea is the same, but a bit more complicated, as 
>> there are more element in the template that must be updated.
>> The mapsize change is intercepted in the "images" coreplugin. What 
>> you should do is :
>> - change the mapsize template so the change trigger an ajax action 
>> (look at other template for example),
>> - add new functions in images.ajax.js to update the corresponding 
>> elements in the page with the new values. Simply look in the 
>> templates files (cartoclient.tpl and maybe others) where the 
>> variables returned by the images coreplugin (you can see these in 
>> function renderFormPrepare) are used and do the same but with 
>> javascript.
>> I dont think you need to modify the ClientImages.php, as it already 
>> contain the corresponding ajax related functions.
>>
>> regards
>> Oliver
>>
>>
>>> Hi
>>>
>>> Thank for your answer. The functionnalities i need in ajax are 
>>> fullExtent and mapSize.
>>> Well by now i'm trying to implement it on the full extent function. 
>>> Maybe you could tell me wether i took a wrong path.
>>> On the doSubmit function, instead of the myform.submit(); i do a 
>>> x_submitForm(); wich looks like this:
>>>
>>> /function x_submitForm(){
>>>  xShow(xGetElementById('loadbarDiv'));
>>>  var param = AjaxHandler.buildPostRequest();
>>>  var laRequete = new Ajax.Request('/cw/htdocs/x_aeag.php', {method: 
>>> 'post',parameters: param,onComplete: afficherReponse} );
>>> }
>>>
>>> /The file x_aeag.php looks like this:
>>> /<?php
>>> $_ENV['CW3_PROJECT'] = 'aeag';
>>> require_once('client.php');
>>>
>>> header('Content-Type: text/xml');
>>> ?>/
>>>
>>> And then i modified the cartoclient.tpl so it produces an xml stream:
>>> /<?xml version="1.0" encoding="UTF-8"?>/
>>> /<reponse>
>>>    <bbox>{$bboxMinX},{$bboxMinY},{$bboxMaxX},{$bboxMaxY}</bbox>
>>>    <factor>{$factor}</factor>
>>>    <mapunits>{$mapUnits}</mapunits> 
>>> <scalebarUnits>{$scalebarUnits}</scalebarUnits>
>>>    <currentScale>1:{$currentScale}</currentScale>
>>>    <mainmap_path>{$mainmap_path}</mainmap_path>
>>>    <mainmap_width>{$mainmap_width}</mainmap_width>
>>>    <mainmap_height>{$mainmap_height}</mainmap_height>
>>>    <scalebar_path>{$scalebar_path}</scalebar_path>
>>>    <keymap_path>{$keymap_path}</keymap_path>
>>> </reponse>/
>>>
>>> Now my problem is that cartoweb doesn't produce the full extent map 
>>> image. A new image is yet generated but with still the same extent. 
>>> I can't find why...
>>>
>>> regards
>>> Simon Ortet
>>>
>>>
>>> Oliver Christen a écrit :
>>>> Hi
>>>>
>>>> Some plugins and maybe some core functionnalities are not 
>>>> compatible with ajax.
>>>> Simply changing the doSubmit function to only return xmlhttprequest 
>>>> (ajax) is probably not a good idea as it will break in the cases 
>>>> said above.
>>>>
>>>> I would suggest to first identify precisely which functionnalities 
>>>> you use are still using non-ajax mode and then see how to modify 
>>>> these functionnalities so they work with ajax (if possible)
>>>>
>>>> regards
>>>> Oliver
>>>>
>>>> ----- Original Message ----- From: "Simon ORTET" 
>>>> <simon.ortet at silogic.fr>
>>>> To: <cartoweb-users at lists.maptools.org>
>>>> Sent: Thursday, July 19, 2007 10:25 AM
>>>> Subject: [Cartoweb-users] Cartoweb and Ajax
>>>>
>>>>
>>>>> Hi,
>>>>>
>>>>> I'm trying to set Cartoweb as a full Ajax application. So i try to 
>>>>> change the doSubmit function of dhtmlInit.js to make it send the 
>>>>> form through an ajax function.
>>>>> I'd like to know if someone as already done this work, and if 
>>>>> possible to post the code in the list.
>>>>>
>>>>> Thanks
>>>>> _______________________________________________
>>>>> Cartoweb-users mailing list
>>>>> Cartoweb-users at lists.maptools.org
>>>>> http://lists.maptools.org/mailman/listinfo/cartoweb-users
>>>>>
>>>>
>>>>
>>>
>>
>>
> _______________________________________________
> Cartoweb-users mailing list
> Cartoweb-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/cartoweb-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/cartoweb-users/attachments/20070723/26d916f9/attachment.html


More information about the Cartoweb-users mailing list