[ka-Map-users] Positional parameters in startUp.js and kaMap.js

Paul Spencer pspencer at dmsolutions.ca
Thu Feb 2 13:38:36 EST 2006


David,

good point.  I actually have some other code that parses the query  
string into an array of name/value pairs.  I'll try to locate it and  
stick it in here.  I haven't actually looked at this code before now  
so I didn't realize it was doing this.

Cheers

Paul

On 2-Feb-06, at 1:00 PM, David Badke wrote:

> I have been trying to pass an additional parameter to init.php on  
> the URL - that is, additional to map=xxx, extents=xxx,  
> centerPoint=xxx. I was puzzled as to why the additional parameter  
> never made it to init.php until I examined how startUp.js and  
> kaMpa.js handle the parameters, and was dismayed to find that the  
> URL parameters, despite being of the name=value type, are being  
> treated as positional. That is, kaMap.initialize() assumes that its  
> first parameter is 'map', the second is 'extents', and the third is  
> 'centerPoint', with no possibility of any more parameters.  
> startUp.js also assumes the parameters are positional ('map'  
> followed by 'extents' followed by 'centerPoint'), and feeds the URL  
> parameters to kaMap.initialize() in that order. kaMap.initialize()  
> ignores any additional parameters.
>
> This is a Bad Thing (IMO).
>
> Positional parameters on a URL are not a good idea. The whole  
> concept of name=value parameters is that order of presentation  
> doesn't matter, and any parameter can be omitted. As it is, a URL  
> like 'kamap/index.html?extents=0,0,100,100&map=mymap' will not  
> work; 'map=' has to come first.
>
> Any and all parameters found on the URL (after the ?) should be  
> passed along to init.php as-is; neither startUp.js nor  
> kaMap.initialize() uses them directly, so should not be parsing  
> them. Only init.php needs to parse them.
>
> So instead of this code in startUp.js (myOnLoad() function), which  
> assumes a specific parameter order:
>
>  if (szURL.indexOf("?") != -1) {
>      myParams=szURL.slice(1+szURL.indexOf("?")).split("&");
>      myMap= (myParams[0])? myParams[0].slice(1+myParams[0].indexOf 
> ("=")) : '';
>      myExtents= (myParams[1])? myParams[1].slice(1+myParams 
> [1].indexOf("=")): '';
>      myCenterPoint= (myParams[2])? myParams[2].slice(1+myParams 
> [2].indexOf("=")): '';
>      myMapList = (myParams[3])? myParams[3].slice(1+myParams 
> [3].indexOf("=")): '';
>      myKaMap.initialize(myMap,myExtents,myCenterPoint,myMapList);
>  } else {
>      myKaMap.initialize();
>  }
>
> it should be:
>
>  if (szURL.indexOf("?") != -1) {
>      myKaMap.initialize(szURL.slice(1+szURL.indexOf("?")));
>  } else {
>      myKaMap.initialize();
>  }
>
> and kaMap.initialize() should change from:
>
>    if (arguments.length > 0 && arguments[0] != '')
>    {
>        szURL = szURL + sep + "map="+ arguments[0];
>        sep = "&";
>    }
>    if (arguments.length > 1 && arguments[1] != '')
>    {
>        szURL = szURL + sep + "extents="+ arguments[1];
>        sep = "&";
>    }
>    if (arguments.length > 2 && arguments[2] != '')
>    {
>        szURL = szURL + sep + "centerPoint="+ arguments[2];
>        sep = "&";
>    }
>
> to:
>
>    if (arguments.length > 0 && arguments[0] != '')
>       szURL = szURL + sep + arguments[0];
>
> If kaMap.initialize() needs to be called with internally-generated  
> parameters (ie: not from a URL), the name=value style parameters  
> can be generated and it can be called like:
>
>    kaMap.initialize('map=xxx&extents=xxx&centerPoint=xxx');
>
> so there is no reason for kaMap.initialize() to be working with  
> positional parameters at all.
>
> Just my opinion, but I have to modify the code this way for my  
> project to work. Perhaps there is a better way that does not  
> require me to modify kaMap.js - if so, I would be glad to hear of it.
>
> David
>
> _______________________________________________
> ka-Map-users mailing list
> ka-Map-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/ka-map-users
>

+-----------------------------------------------------------------+
|Paul Spencer                           pspencer at dmsolutions.ca   |
+-----------------------------------------------------------------+
|Applications & Software Development                              |
|DM Solutions Group Inc                 http://www.dmsolutions.ca/|
+-----------------------------------------------------------------+






More information about the ka-Map-users mailing list