dBox with mode=itemquery or itemnquery

Trond Michelsen trondmm-mapserver at CRUSADERS.NO
Mon Aug 28 09:02:29 EDT 2006


On Tue, Jul 25, 2006 at 07:59:07PM -0600, Richard Greenwood wrote:
> So Steve, your suggestions for itemquery (below) work great. In
> mapserv.js I do not see any support for saved queries. Am I missing
> anything? Are saved queries still the way it's done, or is there some
> new and improved method?
> 
> I'm thinking of adding something to mapserv.js like:
> 
>    if (this.savedqueryfile)
>       this.url += '&queryfile=' + this.savedqueryfile;
> 
> Adding an "itemqueryoptions" to the Mapserv object, and a couple
> methods to add and remove a saved query file.
> 
> Using a template like:
> 
>    [img],[shpminx],[shpminy],[shpmaxx],[shpmaxy],[queryfile]
> 
> Is this reasonably consistent with your stuff or am I in left field?

I know this is a bit of an old message, but I thought I'd just say
that I've just started using JSON in my templates, and I'm very
satisfied with how it works.

In this case, the template would look something like this:

{
  img: '[img]',
  shp: [ [shpminx], [shpminy], [shpmaxx], [shpmaxy] ],
  queryfile: '[queryfile]'
}

And my function to parse the template looks like this:

AJAX_getMapObject = function (content) {
    var mapobj;
    try {
	var code = "(// " + content + ")";
	mapobj = eval(code);
    } catch (e) {
	alert("eval failed: " + e.message);
    }
    if (typeof mapobj == "undefined") {
	alert("Could not create mapobject:\n" + req.responseText);
    }
    return mapobj;
};

You invoke it with the responseText from the XMLHttpRequest-object, like this: 

var result = AJAX_getMapObject(req.responseText);

and the variables are now available as properties on result:

var img = result.img;
var shpminx = result.shp[0];

etc.


I also use this on the main requests (i.e. when the user zooms or pans
the map), and that template looks like this:

// start template
{
  mapserver: {
    version: '[version]',
    id:      '[id]',
    host:    '[host]',
    port:    '[port]',
    errmsg:  decodeURIComponent('[errmsg_esc]')
  },
  image: {
    center:   '[center]',
    center_x: '[center_x]',
    center_y: '[center_y]',
    mapsize:  '[mapsize]',
    mapwidth: '[mapwidth]',
    scale:    '[scale]',
    cellsize: '[cellsize]'
  },
  file: {
    img:       '[img]',
    ref:       '[ref]',
    legend:    '[legend]',
    scalebar:  '[scalebar]',
    queryfile: '[queryfile]',
    map:       '[map]'
  },
  map: {
    mapx:   '[mapx]',
    mapy:   '[mapy]',
    maplon: '[maplon]',
    maplat: '[maplat]',
    dx:     '[dx]',
    dy:     '[dy]',
    mapext:        [ [minx],    [miny],    [maxx],    [maxy]    ],
    rawext:        [ [rawminx], [rawminy], [rawmaxx], [rawmaxy] ],
    mapext_latlon: [ [minlon],  [minlat],  [maxlon],  [maxlat]  ],
    refext:        '[refext]'.split(' '),

    mapext_str:        '[mapext]',
    rawext_str:        '[rawext]',
    mapext_latlon_str: '[mapext_latlon]',
    refext_str:        '[refext]'
  },
  layer: {
    layers:        decodeURIComponent('[layers_esc]').split(' '),
    toogle_layers: decodeURIComponent('[toggle_layers_esc]').split(' ')
  },
}
// end template

With this template, I get an object that contains all the variables
that are available from mapserver (except the dynamic ones, of course,
but as far as I can tell, those are only necessary in a completely
javascript-free application.

I'm using decodeURIComponent() combined with the _esc-variant of the
variables that could contain ', to prevent syntax errors during eval().

-- 
Trond Michelsen



More information about the mapserver-users mailing list