Multi template

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Multi template

pe_lord
I would like to know if Mapserver is able to maintain 2 template (or more) as the same time. I want to maintain a HTML and a JSON template at the same time, depending my call's parameters on my WMS getfeatureinfo.
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

Lime, Steve D (MNIT)

You can certainly have multiple templates associated with the same mapfile by using the template output format. See http://mapserver.org/development/rfc/ms-rfc-36.html... Then you can change templates via WMS or via the queryformat CGI parameter. --Steve

 

From: mapserver-users [mailto:[hidden email]] On Behalf Of pe_lord
Sent: Tuesday, April 18, 2017 8:06 AM
To: [hidden email]
Subject: [mapserver-users] Multi template

 

I would like to know if Mapserver is able to maintain 2 template (or more) as the same time. I want to maintain a HTML and a JSON template at the same time, depending my call's parameters on my WMS getfeatureinfo.


View this message in context: Multi template
Sent from the Mapserver - User mailing list archive at Nabble.com.


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

pe_lord
This post was updated on .
But more specificly, two template on the same layer managing [join], one in html, the other  in json or whatever...

I do not understand how to configure it or which call to make to retrieve the right template...

INFO_FORMAT=text/html
 VS
Queryformat = application/json
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

pe_lord
Here the kind of html template i would like to both call in html and json

I know that i would need to simplify the data in json but it's simply an example:
GetInfo HTML with joins
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

pe_lord
Any another hint to maintain 2 template on same layer?
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

Lime, Steve D (MNIT)

My suggestion is the same as before, use OUTPUTFORMATs. You can define a JSON format and a HTML format and process the same layer through both, including simple joins. The exception here is if you're doing one-to-many joins where the join itself requires a template. In that case you're stuck because there is no way to specify multiple templates for a one-to-many join. Wait! Actually you can, you just have to define the join multiple times, one for JSON and one for HTML - it's inefficient though.


The key here is that you're basically abandoning the TEMPLATE keyword at the layer level. Instead you do:


  OUTPUTFORMAT
    NAME 'json'
    DRIVER 'TEMPLATE'
    MIMETYPE 'application/json'
    FORMATOPTION "FILE=templates/json.tmpl"
    FORMATOPTION 'ATTACHMENT=mapserver.json'
  END

  OUTPUTFORMAT
    NAME 'html'
    DRIVER 'TEMPLATE'
    MIMETYPE 'text/html'
    FORMATOPTION "FILE=templates/html.tmpl"
    FORMATOPTION 'ATTACHMENT=mapserver.html'
  END

In your layer you'd have:


  TEMPLATE void


just to make the layer queryable.


If you're using the CGI you'd use queryformat=json or queryformat=html to switch between them. With WFS/WMS I believe you have to reference the mime type.


Please let me know if you have more questions. This can work well. I have several apps that return JSON, GEOJSON or HTML with a single layer.


Steve


From: mapserver-users <[hidden email]> on behalf of pe_lord <[hidden email]>
Sent: Thursday, April 27, 2017 6:48:13 AM
To: [hidden email]
Subject: Re: [mapserver-users] Multi template
 
Any another hint to maintain 2 template on same layer?



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Multi-template-tp5317599p5318595.html
Sent from the Mapserver - User mailing list archive at Nabble.com.
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users

_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

pe_lord
I'm trying to setup these "DRIVER 'TEMPLATE'"
Few more questions!

1- What is the goal/difference of  
FORMATOPTION "FILE=...."
vs
FORMATOPTION 'ATTACHMENT=...' ?

2- How to not all redirect my query on the same template (json or html). I've tried for an other layer, my Driver template is used instead of the one call into the layer section?
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

Lime, Steve D (MNIT)
FORMATOPTION "FILE=...." defines the actual MapServer template to use so it's required.

FORMATOPTION 'ATTACHMENT=...'  sets an HTTP header value that effectively names the file being returned. That's useful when folks save the response to a file otherwise you see long names like "mapserver?my.map&...". It's not required and is more of a convenience configuration option for your users.

With the mapserv CGI you change template with the qformat parameter. For example, "http://yoursite.com/cgi-bin/mapserv?map=my.map&mode=nquery&mapext=...&qformat=json" would use whatever format is named "json". Just switch that value to get another format.

For WMS I believe you have to pass the mime-type using the FORMAT parameter. WFS probably supports something similar...

Steve

-----Original Message-----
From: mapserver-users [mailto:[hidden email]] On Behalf Of pe_lord
Sent: Monday, May 01, 2017 2:50 PM
To: [hidden email]
Subject: Re: [mapserver-users] Multi template

I'm trying to setup these "DRIVER 'TEMPLATE'"
Few more questions!

1- What is the goal/difference of  
FORMATOPTION "FILE=...."
vs
FORMATOPTION 'ATTACHMENT=...' ?

2- How to not all redirect my query on the same template (json or html).
I've tried for an other layer, my Driver template is used instead of the one
call into the layer section?




--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Multi-template-tp5317599p5318988.html
Sent from the Mapserver - User mailing list archive at Nabble.com.
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

pe_lord
In reply to this post by Lime, Steve D (MNIT)
But how to control the layer to use.
In the case where my templates varies for each layer. Do I have to call an new name at each call like this?

LAYER1  call looks like  : ...&INFO_FORMAT=application/json1
LAYER2  call looks like  : ...&INFO_FORMAT=application/json2


OUTPUTFORMAT
  NAME 'json1'
  DRIVER TEMPLATE
  MIMETYPE 'application/json1; subtype=geojson'
  TEMPLATE 'templ1.js'
END

OUTPUTFORMAT
  NAME 'json2'
  DRIVER TEMPLATE
  MIMETYPE 'application/json2; subtype=geojson'
  TEMPLATE 'templ2.js'
END
 
I don't understant how to control the template calling and redirection to the right template.
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

Lime, Steve D (MNIT)

Multiple layers can be referenced in a single template. I pasted in a particularly nasty one below that we use for returning JSON based on a map click for about 30 layers. Any time you see [resultset… that’s a different layer. If a layer isn’t present in a query result then it is omitted from the template processing. You can use template includes to bring a bit of organization to this sort of chaos, for example [include src="templates/json/lake.js"] where the path is relative to location of the parent mapfile.

 

Steve

 

// MapServer Template

{'result':{

[resultset layer="state"][feature]  'state':'MN',[/feature][/resultset]

[resultset layer="county"][feature]

  'county': {

    'name': '[CTY_NAME]',

    'id': [COUN],

    'fips': '[CTY_FIPS]'

  },[/feature][/resultset]

[resultset layer="municipality"][feature]

  'municipality': {

    'name': '[MUNI_NAME]',

    'fips': '[FIPS]'

  },[/feature][/resultset]

  'pls': {

[resultset layer="pls"][feature]

    'township': [TOWN],

    'range': [RANG],

    'direction': [RDIR],

    'section': [SECT],

[/feature][/resultset]

[resultset layer="pls.forty"][feature]

    'forty': [item escape="none" name="fort_desc" pattern="^[A-Z]{4}$" nullformat="null" format="'$value'"][/feature][/resultset]

  },

[resultset layer="usgs024k"][feature]  'usgs024k': '[TILE_NAME]',[/feature][/resultset]

[resultset layer="usgs100k"][feature]  'usgs100k': '[TILE_NAME]',[/feature][/resultset]

[resultset layer="usgs250k"][feature]  'usgs250k': '[TILE_NAME]',[/feature][/resultset]

[resultset layer="elevation"][feature]  'elevation': [item name="value_0"],[/feature][/resultset]

  'other_public_land': {

[resultset layer="other_public_land.forestry"][feature]'admin': 'DNR Forestry'[/feature][/resultset]

  },

[resultset layer="state_park"][feature]

  'state_park':{

    'name':'[item name="unit_name"] [item name="unit_type"]',

    'id':'[item name="pgrm_proje" lc="true"]',

    'url':'http://www.dnr.state.mn.us[website_2]'

  },[/feature][/resultset]

[resultset layer="state_trail"][feature]

  'state_trail':{

    'name':'[item name="trail_name"]',

    'id':'[item name="prgm_prj" lc="true"]',

    'url':'http://[website_2]'

  },[/feature][/resultset]

[resultset layer="state_water_trail"][feature]

  'state_water_trail':{

    'name':'[item name="trail_name"] State Water Trail',

    'id':'[item name="prgm_prj" lc="true"]',

    'url':'http://www.dnr.state.mn.us[website_3]'

  },[/feature][/resultset]

[resultset layer="state_forest"][feature]

  'state_forest':{

    'name':'[item name="unit_name"] State Forest',

    'id':'[item name="pgrm_proje" lc="true"]',

    'url':'http://www.dnr.state.mn.us[website_2]'

  },[/feature][/resultset]

[resultset layer="wma"][feature]

  'wma':{

    'name':'[item name="unit_name"][item name="subunit_name" pattern="." format=": $value"]',

    'id':'[item name="uniqueid" lc="true"]',

    'url':'http://www.dnr.state.mn.us/wmas/detail_report.html?id=[item name="uniqueid"]'

  },[/feature][/resultset]

[resultset layer="ama"][feature]

  'ama':{

    'name':'[item name="unit_name"]',

    'id':'[item name="uniqueid" lc="true"]'

  },[/feature][/resultset]

[resultset layer="sna"][feature]

  'sna':{

    'name':'[item name="site_name"]',

    'id':'[item name="bremcode" lc="true"]',

    'url':'http://www.dnr.state.mn.us/snas/detail.html?id=[item name="bremcode" lc=true]'

  },[/feature][/resultset]

[resultset layer="wia"][feature]

  'wia':{

    'name':'[item name="map_title"]',

    'id':'[item name="wia_id" lc="true"]',

    'url':'http://files.dnr.state.mn.us/destinations/wias/detailmaps/[item name="wia_pdf"]'

  },[/feature][/resultset]

[resultset layer="lake"][feature]

  'lake':{

    'name':'[LAKE_NAME]',

    'id':'[DOWLKNUM]'

  },[/feature][/resultset]

[resultset layer="water_access"][feature]

  'water_access':{

    'name':'[item name="fac_name"]',

    'id':'[item name="uniquekey" lc="true"]',

    'url':'http://www.dnr.state.mn.us/maps/compass/pwa.html?map=COMPASS_MAPFILE&mode=indexquery&shapeindex=[shpidx]&qlayer=shor_waspt3_query'

  },[/feature][/resultset]

[resultset layer="hwt"][feature]

  'hwt':{

    'name':'[item name="trail_name"]',

    'id':'hwt[item name="pdfmap_" lc="true"]',

    'url':'http://files.dnr.state.mn.us/hunting/hwt/[item name="pdf_file"]'

  },[/feature][/resultset]

[resultset layer="conservation_officers"]'conservation_officers':[

  [feature trimlast=","]{

    'area':'[item name="station_na"] Enforcement Area',

    'name':'[item name="of_name"]',

    'phone':'[item name="phone"]',

    'radio_call':'[item name="radio_call"]'

  },[/feature]

  ],[/resultset]

  'point':{

    'epsg:26915': [[mapx], [mapy]],

    'epsg:4326': [[maplon], [maplat]]

  }

}}

 

-----Original Message-----
From: mapserver-users [mailto:[hidden email]] On Behalf Of pe_lord
Sent: Thursday, May 11, 2017 12:36 PM
To: [hidden email]
Subject: Re: [mapserver-users] Multi template

 

But how to control the layer to use.

In the case where my templates varies for each layer. Do I have to call an

new name at each call like this?

 

LAYER1  call looks like  : ...&INFO_FORMAT=application/json1

LAYER2  call looks like  : ...&INFO_FORMAT=application/json2

 

 

OUTPUTFORMAT

  NAME 'json1'

  DRIVER TEMPLATE

  MIMETYPE 'application/json1; subtype=geojson'

  TEMPLATE 'templ1.js'

END

 

OUTPUTFORMAT

  NAME 'json2'

  DRIVER TEMPLATE

  MIMETYPE 'application/json2; subtype=geojson'

  TEMPLATE 'templ2.js'

END

I don't understant how to control the template calling and redirection to

the right template.

 

 

 

 

--

View this message in context: http://osgeo-org.1560.x6.nabble.com/Multi-template-tp5317599p5320221.html

Sent from the Mapserver - User mailing list archive at Nabble.com.

_______________________________________________

mapserver-users mailing list

[hidden email]

https://lists.osgeo.org/mailman/listinfo/mapserver-users


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

pe_lord
This is working properly with your proposal.

Reply | Threaded
Open this post in threaded view
|

Re: Multi template

pe_lord
This post was updated on .
One more question.

Can template-output-driven be able to live at the same time as other standard templates? Until now, it seems to me that one supplant the behavior of the other.
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

Lime, Steve D (MNIT)
Yes, you can have both although whenever I've started to use the outputformat-based templating I've abandoned the other approach. If no query format is set then MapServer will revert to the older approach. You can't, however, mix and match the approaches within a single query response. Does that make sense?

-----Original Message-----
From: mapserver-users [mailto:[hidden email]] On Behalf Of pe_lord
Sent: Wednesday, August 23, 2017 10:51 AM
To: [hidden email]
Subject: Re: [mapserver-users] Multi template

One more question.

Can template-output-driven be able to live at the same time as other
standard templates? Until now, it seems to me that supplant the behavior of
the other.




--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Multi-template-tp5317599p5332275.html
Sent from the Mapserver - User mailing list archive at Nabble.com.
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

pe_lord
I understand but I cannot get the same behavior.

Here some mapfile sample:


 
OUTPUTFORMAT
  NAME 'html'
  DRIVER 'TEMPLATE'
  MIMETYPE 'text/html'
  FORMATOPTION "FILE=../templates/html.tmpl"  
  FORMATOPTION 'ATTACHMENT=info.html'
END

LAYER
    NAME A
    ...
    TEMPLATE 'another_template_html.html'
    ...
END

LAYER
    NAME B
    ...
    TEMPLATE 'void' # redirect to template-driven output filtered by the resultset tag [resultset layer="B"]
    ...
END



At this time, with this configuration, I cannot alternate between the 2 methods. I get a correct template from layer B but nothing from LAYER A...


Is it correct? Something wrong?





Reply | Threaded
Open this post in threaded view
|

Re: Multi template

Lime, Steve D (MNIT)
I'll have to setup a quick test to satisfy my own curiosity and report back.

-----Original Message-----
From: mapserver-users [mailto:[hidden email]] On Behalf Of pe_lord
Sent: Wednesday, August 23, 2017 12:31 PM
To: [hidden email]
Subject: Re: [mapserver-users] Multi template

I understand but I cannot get the same behavior.

Here some mapfile sample:


 
OUTPUTFORMAT
  NAME 'html'
  DRIVER 'TEMPLATE'
  MIMETYPE 'text/html'
  FORMATOPTION "FILE=../templates/html.tmpl"  
  FORMATOPTION 'ATTACHMENT=info.html'
END

LAYER
    NAME A
    ...
    TEMPLATE 'another_template_html.html'
    ...
END

LAYER
    NAME B
    ...
    TEMPLATE 'void' # redirect to template-driven output filtered by the
resultset tag [resultset layer="B"]
    ...
END



At this time, with this configuration, I cannot alternate between the 2
methods. I get a correct template from layer B but nothing from LAYER A...


Is it correct? Something wrong?









--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Multi-template-tp5317599p5332287.html
Sent from the Mapserver - User mailing list archive at Nabble.com.
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

pe_lord
I'm on MapServer 7.0.3
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

pe_lord
In reply to this post by Lime, Steve D (MNIT)
What about your own curiosity?
I've retried and I get the same behavior. And you?

Pierre



--
Sent from: http://osgeo-org.1560.x6.nabble.com/Mapserver-User-f4226646.html
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Multi template

Lime, Steve D (MNIT)
Hi Pierre: Ok, I whipped up a test. It is possible to use both the legacy templates and the output format method. The key is setting a value for the WEB object QUERYFORMAT parameter. If that parameter is set to some value that doesn't match any existing OUTPUTFORMAT names then MapServer will use the legacy approach. So this means you can do something like:

WEB
  QUERYFORMAT "default" # use the legacy approach
END

and as long as there is no OUTPUTFORMAT named "default" then MapServer with use the legacy approach. If you don't set QUERYFORMAT or set it to the name of a an existing OUTPUTFORMAT then there is no path to the legacy approach unless you set the CGI parameter qformat to something that doesn't exist.

I hope that's not too confusing.

I have a test case with  two OUTPUTFORMATs and QUERYFORMAT "default"...

  http://maps1.dnr.state.mn.us/cgi-bin/mapserv70?map=/usr/local/mapserver/apps/test/templates/test.map&mode=nquery (gets legacy approach)
  http://maps1.dnr.state.mn.us/cgi-bin/mapserv70?map=/usr/local/mapserver/apps/test/templates/test.map&mode=nquery&qformat=mytemplate1 (gets OUTPUTFORMAT one)
  http://maps1.dnr.state.mn.us/cgi-bin/mapserv70?map=/usr/local/mapserver/apps/test/templates/test.map&mode=nquery&qformat=mytemplate2 (gets OUTPUTFORMAT two)

This is consistent with how I remember setting this up, it's just been awhile and I don't use the legacy approach much anymore.

Steve

-----Original Message-----
From: mapserver-users [mailto:[hidden email]] On Behalf Of pe_lord
Sent: Wednesday, September 06, 2017 7:56 AM
To: [hidden email]
Subject: Re: [mapserver-users] Multi template

What about your own curiosity?
I've retried and I get the same behavior. And you?

Pierre



--
Sent from: http://osgeo-org.1560.x6.nabble.com/Mapserver-User-f4226646.html
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users