[mapserver-users] Multi template

Lime, Steve D (MNIT) steve.lime at state.mn.us
Thu May 11 11:31:23 PDT 2017


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:mapserver-users-bounces at lists.osgeo.org] On Behalf Of pe_lord
Sent: Thursday, May 11, 2017 12:36 PM
To: mapserver-users at lists.osgeo.org
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

mapserver-users at lists.osgeo.org<mailto:mapserver-users at lists.osgeo.org>

https://lists.osgeo.org/mailman/listinfo/mapserver-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20170511/73f5f8b5/attachment.htm>


More information about the MapServer-users mailing list