I'm working on a project in which I need to show data next to a Google Maps minimap as user clicks on items of which he desires to see information from.
Basically it works like this:
- User clicks on a label he wishes to see information about
- Browser appends a separate table to the side of the screen using jQuery and Handlebars in which there should be:
- Google Maps instances showing the location the information is from
- The information
Though somehow I cannot manage to get the JS + jQuery + Handlebars combination to work. I understand that I need to create a helper to execute JavaScript code in Handlebars template, but somehow adding a Google Maps instance within the table in the HB template is not working.
Here's the code I'm working on at the moment. Thanks for any help!
Template file:
<script id="entry-template" type="text/x-handlebars-template">
<section class="Info" id={{id}}>
<header class="InfoHeader small" onclick="collapseInfobox(this)">
<p class=""></p>
</header>
<article class="hidden">
<table class="Analyses" border="1">
<tr>
<td class="minimap"><div id="minimap_1_{{id}}" class="minimap">{{miniMap_1 context}}</div></td>
<td class="graph"><div>{{ graph_1 }}</div></td>
</tr>
</table>
</article>
</section>
</script>
<script type="text/javascript">
var HTMLsource = $("#entry-template").html();
var HTMLtemplate = Handlebars.compile(HTMLsource);
</script>
JavaScript code:
function addInfo(id, start, end) {
var context = {
id: id,
};
Handlebars.registerHelper('miniMap_1', function(data) {
var minimapOptions = {
disableDefaultUI: true,
center: new google.maps.LatLng(_Coords.lat, _Coords.lon),
zoom: 13,
};
var minimap1 = new google.maps.Map(document.getElementById(this), minimapOptions);
});
// contentArea is a div section in the page to which the info div should be appended
$("#contentArea").append(HTMLtemplate(context));
}