Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Mappable Module Problem


Reply


8 Posts   1124 Views

Avatar
cumquat

Community Member, 198 Posts

27 July 2011 at 9:07pm

Hi there,

Anyone out there playing with Uncle Cheese's Mappable Module?

I'm having problems getting it to work, the chances are it's my total lack of understanding :o)

I'm not getting any errors i'm just getting nothing, so i'm guessing that the module isn't actually being called. I have set it up using the instructions on UC's website although i didn't fully understand all the concepts being discussed. I have a page called MemberProfile.php and in that is

class MemberProfile extends DataObject implements Mappable {

   static $db = array (
    'Lat' => 'Varchar',
'Lon' => 'Varchar',
'Type' => "Enum('Station,Contact-Point')"
);
   
   public function getLatitude() {
return $this->Lat;
}

public function getLongitude() {
return $this->Lon;
}

public function getMapContent() {
return GoogleMapUtil::sanitize($this->renderWith('MapBubbleMember'));
}

public function getMapCategory() {
return $this->Type;
}

public function getMapPin() {
return $this->Type."_pin.png";
}

}

I have dev/build and flushed the site.
i have a Google api key set in my site _config.php file
Using modelAdmin i have entered some lat and longs into the database.
On a page i have used the code $MemberProfile.GoogleMap to call the map but nothing appears and no errors anywhere i can see.

I'm guessing there is something major i need to do but i'm just not sure what it is.
Any help would be appreciated.

Cheers

Mick

Avatar
cumquat

Community Member, 198 Posts

1 August 2011 at 7:42pm

Bump, anyone?

Avatar
UncleCheese

4085 Posts

3 August 2011 at 12:14am

For starters I would troubleshoot the following:

1) Does $MemberProfile.Lat return a value? If not, then you either have a scope issue, or the lat/long fields are empty.

If that works..

2) Check your source code to see if any of the Google scripts are being included. You can just search for "maps.google.com"..

If that works..

3) Check for Javascript errors.

---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

Avatar
cumquat

Community Member, 198 Posts

9 August 2011 at 10:16pm

Thanks for the reply,
Ok, I have started from scratch and will list what I have done so far, I'm sure I must have missed out something obvious. The thing is this type of a module could really help the teams I work with so need to get a solution and it's frustrating the hell out of me I don't seem to be able to grasp it.
Right downloaded the module from github, upload it and dev/build.
in the site _config file add the GoogleMapUtil::set_api_key('the key for my domain');
created a php page below,

class HospitalEx extends DataObject implements Mappable {
   static $db = array (
      'Lat' => 'Varchar',
      'Lon' => 'Varchar',
      'Type' => "Enum('Accident and Emergency, Ambulance Station')"
   );
      public function getLatitude() {
      return $this->Lat;
      }
    public function getLongitude() {
      return $this->Lon;
}   
   public function getMapContent() {
      return GoogleMapUtil::sanitize($this->renderWith('MapBubbleMember'));
   }
    public function getMapCategory() {
      return $this->Type;
   }
   public function getMapPin() {
      return $this->Type."_pin.png";
}
}


Uploaded this file and dev/build.
Used a ModelAdmin page to go to HospitalEx table and enter the Lat, Lon and Type.

I have created a page type called HospitalExPage and this has a

static $has_many = array(
      'HospitalEx' => 'HospitalEx'
   );


and on the HospitalEx there is a has one declaration.
The template page HospitalExPage.ss is below,

<div class="typography">
   <% include SideBar %>
      <div id="Content">
         <h1>Hospital Google Maps $ID</h1>
            $HospitalEx.Lat
            $HospitalEx.GoogleMap
      </div>
</div>


If I just have $HospitalEx.Lat it brings back nothing, if I put a control in and use $Lat it brings back data, when I have the $HospitalEx.GoogleMap in it now errors telling me it can't find the template MapBubbleMember.ss
I would put money that I'm being a numpty and just missing something blatantly obvious but I can't see the wood for the trees any more.
It looks like it's not calling the module which leads me to believe i have missed something.

Mick

Avatar
UncleCheese

4085 Posts

10 August 2011 at 7:09am

Yeah, you've got a number of problems here. The biggest one is that there's nothing tying your HospitalEx objects to your page. You've got a has_many set up, but that doesn't mean anything until you have a has_one pointing back to it. There are two ways to solve this -- 1) manage the objects in a DOM on your page, or 2) manage them in modeladmin and have the HospitalPage return an all-inclusive set. Here's the first approach:

HospitalEx.php

// add:
static $has_one = array (
'HospitalPage' => 'HospitalPage'
);

HospitalPage.php

static $has_many = array ('Hospitals' => 'HospitalEx');

public function getCMSFields() {
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Hospitals", new DataObjectManager($this));
return $f;
}

Second approach:

Leave the $has_one out of your HospitalEx object, remove the $has_many from your HospitalsPage class, and create a custom function for it.

public function Hospitals() {
return DataObject::get("HospitalEx");
}

HospitalPage.ss (for both options)

All hospitals on a map:
$Hospitals.GoogleMap

Map an individual hospital:
<% control Hospitals %>
$GoogleMap
<% end_control %>

That should get you started..

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
cumquat

Community Member, 198 Posts

10 August 2011 at 7:13pm

Cheers again, i'm getting an error to do with the 'mapbubblemember template not being there? See below. It's on the page that implements mappable i copied this from your example on your site, is this a template i need or is this something that is part of Google maps.

Also just left you a donation for all your continued help past and present, i think it went through although the page did throw up an error after i hit submit.

regards

Mick

[User Warning] None of these templates can be found in theme 'cantech': MapBubbleMember.ss
GET /info/google/

Line 207 in /home/sites/myriadtestsite.co.uk/public_html/subs/cantech/sapphire/core/SSViewer.php
Source

198                unset($this->chosenTemplates[$templateFolder]);
199             }
200          }
201
202          if(isset($_GET['debug_request'])) Debug::message("Final template selections made: " . var_export($this->chosenTemplates, true));
203
204       }
205
206       if(!$this->chosenTemplates) user_error("None of these templates can be found in theme '"
207          . self::current_theme() . "': ". implode(".ss, ", $templateList) . ".ss", E_USER_WARNING);
208          
209    }
210    
211    /**
212     * Returns true if at least one of the listed templates exists
213     */

Trace

None of these templates can be found in theme 'cantech': MapBubbleMember.ss
Line 207 of SSViewer.php
SSViewer->__construct(MapBubbleMember)
Line 332 of ViewableData.php
ViewableData->renderWith(MapBubbleMember)
Line 20 of HospitalEx.php
HospitalEx->getMapContent()
Line 473 of GoogleMapAPI.php
GoogleMapAPI->addMarkerAsObject(HospitalEx)
Line 119 of GoogleMapUtil.php
GoogleMapUtil::get_map(DataObjectSet)
Line 12 of MappableData.php
MappableData->GoogleMap()
call_user_func_array(Array,Array)
Line 693 of Object.php
Object->__call(GoogleMap,Array)
HospitalEx->GoogleMap()
Line 369 of ViewableData.php
ViewableData->obj(GoogleMap,,,1)
Line 446 of ViewableData.php
ViewableData->XML_val(GoogleMap,,1)
Line 284 of .cache.sar.templates.Layout.HospitalExPage.ss
include(/home/sites/myriadtestsite.co.uk/public_html/subs/cantech/silverstripe-cache/.cache.sar.templates.Layout.HospitalExPage.ss)
Line 420 of SSViewer.php
SSViewer->process(HospitalExPage_Controller,Zend_Cache_Frontend_Output)
Line 411 of SSViewer.php
SSViewer->process(HospitalExPage_Controller)
Line 202 of Controller.php
Controller->handleAction(SS_HTTPRequest)
Line 143 of RequestHandler.php
RequestHandler->handleRequest(SS_HTTPRequest)
Line 147 of Controller.php
Controller->handleRequest(SS_HTTPRequest)
Line 199 of ContentController.php
ContentController->handleRequest(SS_HTTPRequest)
Line 184 of ContentController.php
ContentController->handleRequest(SS_HTTPRequest)
Line 67 of ModelAsController.php
ModelAsController->handleRequest(SS_HTTPRequest)
Line 282 of Director.php
Director::handleRequest(SS_HTTPRequest,Session)
Line 125 of Director.php
Director::direct(/info/google/)
Line 127 of main.php

Avatar
UncleCheese

4085 Posts

16 August 2011 at 1:41am

This:

return GoogleMapUtil::sanitize($this->renderWith('MapBubbleMember'));

Is just example code. You can either create your own template for the popup, or just return text.

I did receive your donation, and I was about to send you a personal thank you today. I really appreciate that, and I'll be sure to keep you in mind when I'm looking for SilverSmith testers!

---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

Avatar
cumquat

Community Member, 198 Posts

16 August 2011 at 2:28am

Thats all sorted, many thanks and regards the donation, not a problem you've helped me out a lot with pointers as well as with the modules you make.

Regards

Mick