GoogleMaps macro with xml data source

Using the GoogleMaps Macro with an XML data source

This map is generated from an xml file containing my favorite bars is delft. It is invoked by the following line, which is explained in detail in the section below the map:

ˆGoogleMaps("width=600", "height=400", "xml=http://www.oqapi.nl/cool-bars-in-delft.xml", "xmlContainer=bar", "addressComposition=street;number;city;country", "infoBoxTemplate=_306Wc3rJ-xxWljbX2_CqQ", "showSidebar=1", "nameComposition=name");

 

Explanation of the parameters

width=600

Sets the width of the map to 600 pixels.

height=400

Sets the height of the map to 400 pixels. 

xml=http://oqapi.nl/cool-bars-in-delft.xml

Tells the macro to use an xml file as data source and that it is located at http://oqapi.nl/cool-bars-in-delft.xml.

xmlContainer=bar

If you have a look at the xml file you'll see that all entries are contained within 'bar' tags. This parameter tells the GoogleMaps macro to look inside these tags. If the tags were named 'item' this option could be omitted since 'item' is the default value for this parameter.

addressComposition=street;number;city;country

This parameter tell the GoogleMaps macro how to compose a full address from the field inside the 'bar' tag. In this case these fields are street, number, city, country. The default is address, zip, city, country. 

infoBoxTemplate=_306Wc3rJ-xxWljbX2_CqQ

Since our xml file defines fields that are not in the the default template we'll have to create our own. This template is shown below, and its id is  _306Wc3rJ-xxWljbX2_CqQ

showSidebar=1

We also want a sidebar containing the names of those cool bars for easy access. Click on these names will pan the map to the corresponding bar and open its info cloud. 

nameComposition=name

In order to put the names of the bars in the sidebar we'll  have to tell the GoogleMaps macro how to compose names from the data in the xml file. In this case the name of the bar is contained in tags called 'name'.

Template

Below are the contents of the custom macro I used for this example. As a namespace I chose GoogleMaps, but you can choose whatever namespace you like.

Please note that you cannot use the HEAD part of the templated, because the template is invoked from a macro. 

The template:

<div style="width: 300px">
<b><tmpl_var name></b><br />
<tmpl_var street> <tmpl_var number><br />
<tmpl_var city><br />

<br />
<i><tmpl_var highlights></i>
</div>

<tmpl_if url>
<br />
<a href="<tmpl_var url>">Website</a></tmpl_if>



Login   Visitor   Home