Google maps

A place for users and developers of the Xataface to discuss and receive support.

Google maps

Postby tomhousley » Tue Aug 04, 2009 2:08 am

Hello,

I would like to be able to populate a google map with records from a table called tbl_organisations

I have this working fine in PHP outside of xataface, but I can't get the map (even a basic one without any markers pulled from an php generated XML file.

my actions.ini looks like this:

Code: Select all
[map]
    label = Map
    category = table_tabs
    mode = map
    url = "{$this->url('-action=map')}"
    template = Map_View.html
    condition = "$query['-table']=='tbl_organisations'"


my map.php file looks like this:

Code: Select all
<?php
class actions_map {
    function handle(&$params){
        df_display(array(), 'Map_View.html');
    }
}
?>


my Map_View.html file without any google maps stuff looks like this:
Code: Select all
{use_macro file="Dataface_Main_Template.html"}
    {fill_slot name="main_section"}

Some text

    {/fill_slot}
{/use_macro}


The google maps code from http://code.google.com/apis/maps/docume ... ction.html looks like this:

Code: Select all
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=MYGOOGLEMAPSKEY=true_or_false"
            type="text/javascript"></script>
    <script type="text/javascript">

    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        map.setUIToDefault();
      }
    }

    </script>
  </head>
  <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 500px; height: 300px"></div>
  </body>
</html>


I have tried many ways of putting this into Map_View.html without any success.

I would be grateful if someone could show me how the google maps code above can be incorporated into my map tab / Map_View.html

Many thanks, Tom
tomhousley
 
Posts: 52
Joined: Thu Feb 26, 2009 1:02 am
Location: United Kingdom

Postby shannah » Tue Aug 04, 2009 9:20 am

A couple of points:

1. You either need to use the template directive in the actions.ini file, or define a custom action class. But not both. The custom action class overrides the template directive. So you could just skip the whole actions_map class, and just rely on the template=Map_View.html directive to use the correct template.

2. Smarty probably doesn't like the { and } javascript brackets. But don't despair. All you have to do is wrap the javascript in {literal}{/literal} tags to tell smarty to ignore the javascript.

Your Map_View.html file would look like:

Code: Select all
{use_macro file="Dataface_Main_Template.html"}
    {fill_slot name="main_section"}

<script></script>
    <script>
    {literal}
    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        map.setUIToDefault();
      }
    }
    {/literal}
    registerPloneFunction(initialize);
    </script>
    <div></div>
    {/fill_slot}
{/use_macro}


The registerPloneFunction() call is instead of the body onload=".." tag. It registers the initialize function to be run when the window is finished loading. You could also just use window.onload=initialize; However this may overwrite an existing onload handler.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 16 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved