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

Google Maps without Forum


Reply

5 Posts   2220 Views

Avatar
danqxx

28 January 2009 at 11:31am Community Member, 14 Posts

Hi, I have extended the Maps module with some simple classes that let you put simple maps on a page without the need to have the forum module installed. I want to submit the classes for use by the wider silverstripe community but am not sure how to do this. Need point of contact.
Cheers,
Dan

Avatar
Hubertus

9 February 2009 at 3:33am Community Member, 14 Posts

I was going to the do the same to use GMaps without the forum. I would love to try out your code and provide some feedback on it. Maybe you can attach it to this thread? Thanks!

Avatar
danqxx

9 February 2009 at 9:47am (Last edited: 9 February 2009 9:48am), Community Member, 14 Posts

class MapPage extends Page {
static $db = array(
    //   'apiKey'       =>    'Varchar(255)',
      'centLat'         =>   'Float',
      'centLong'      =>   'Float',
      'zoom'            =>   'Int',
      'width'            =>   'Int',
      'height'         =>   'Int'
);
   
    static $has_one = array(
    );
   
    static $has_many = array(
    );
   
static $many_many = array(
       'Points'          =>   'Point'
);
   
    function getCMSFields() {
       $fields = parent::getCMSFields();
      
       $tablefield = new ManyManyComplexTableField(
                $this,
                'Points',
                'Point',
                array(
                  'Name'                => 'Name'/*,
                  'Lat'                => 'Latitude',
                  'Long'                => 'Longitude'*/
                ),
                'getCMSFields_forPopup'/**/
            );
         //$tablefield->setAddTitle( 'A Point' );
         //$tablefield->setParentClass('MapPage');
   
            
   
   
       //$fields->addFieldToTab('Root.Content.GoogleMap', new TextField('apiKey'));
       $fields->addFieldToTab( 'Root.Content.GoogleMap', new HeaderField( 'Google Maps Settings' ) );
       $fields->addFieldsToTab('Root.Content.GoogleMap', array(
             new TextField('centLat'),
             new TextField('centLong'),
            new TextField('zoom'),
            new TextField('width'),
            new TextField('height')//,
            //$tablefield
             )
         );/**/
       //$fields->addFieldToTab('Root.Content.GoogleMapPoints');
       $fields->addFieldToTab( 'Root.Content.Points', new HeaderField( 'Points on Map' ) );
       $fields->addFieldToTab( 'Root.Content.Points', $tablefield);
      // $fields->addFieldToTab('Root.Content.MapPoints', $tablefield);
            
       return $fields;
   }

}

class MapPage_Controller extends Page_Controller {
   function Content() {
      
         global $GMaps_API_Key;
         
         ContentNegotiator::disable();
         Requirements::css("maps/css/Maps.css");
         Requirements::javascript("http://maps.google.com/maps?file=api&v=2&key=".$GMaps_API_Key);
         
         $dbData = DataObject::get("Point", "`MapPageID` = '{$this->ID}'","",
            " LEFT JOIN `MapPage_Points` ON `PointID` = `Point`.ID");
         
         $map = new GMap('MyMap', $dbData , new GMapPoint($this->centLat ,$this->centLong), $this->zoom, $this->width, $this->height);
         return $this->Content.$map->display();
      
}/**/

}

class Point extends DataObject {

static $db = array(
'Name' => 'Varchar',
'Lat' => 'Float',
'Long' => 'Float'
);
   
    static $belongs_many_many = array(
'MapPages' => 'MapPage'
);

function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'Name' ) );
$fields->push( new TextField( 'Lat' ) );
$fields->push( new TextField( 'Long' ) );
return $fields;
}

   public function toString() {
return $this->Lat.','.$this->Long;
}
}

Avatar
danqxx

9 February 2009 at 9:51am Community Member, 14 Posts

These class provide a page type that doesn't require the forum to work. they extend the initial body of work without changing existing code.
enjoy :)

Avatar
jolts

15 February 2009 at 12:29am Community Member, 3 Posts

hey danqxx, this looks like a really useful script!

unfortunately, I can't seem to get it to function using ss 2.2.3. this is the error output I get

Building Database

Creating database tables
# Newsletter
# Newsletter_SentRecipient
# Newsletter_Recipient
# NewsletterType
# PageComment
# CalendarDateTime
# RecurringDayOfMonth
# RecurringDayOfWeek
# RecurringException
# GMap
# GMapPoint
# Point

FATAL ERROR: Bad class to singleton() - Point
At line 85 in /var/www/test_loc/htdocs/sapphire/core/Core.php

user_error(Bad class to singleton() - Point,256)
line 85 of Core.php

singleton(Point)
line 175 of DatabaseAdmin.php

DatabaseAdmin->doBuild()
line 90 of DatabaseAdmin.php

DatabaseAdmin->build(Array)
line 261 of Controller.php

Controller->run(Array)
line 104 of Director.php

Director::direct(db/build)
line 158 of main.php
Context
Debug (Debug::showError() in line 180 of Debug.php)

* className =

Point

* _SINGLETONS =
o Member =
Database record: Member
+ ID :

0

o Newsletter =
Database record: Newsletter
+ ID :

0

o Newsletter_SentRecipient =
Database record: Newsletter_SentRecipient
+ ID :

0

o Newsletter_Recipient =
Database record: Newsletter_Recipient
+ ID :

0

o NewsletterType =
Database record: NewsletterType
+ ID :

0

o PageComment =
Database record: PageComment
+ ID :

0

o CalendarDateTime =
Database record: CalendarDateTime
+ ID :

0

o RecurringDayOfMonth =
Database record: RecurringDayOfMonth
+ ID :

0

o RecurringDayOfWeek =
Database record: RecurringDayOfWeek
+ ID :

0

o RecurringException =
Database record: RecurringException
+ ID :

0

o GMap =
Database record: GMap
+ ID :

0

o GMapPoint =
Database record: GMapPoint
+ ID :

0

it's having trouble with the Point class? not sure how to resolve the issue.

thanks a lot foryour effort in putting this out there, really hope it's a simple fault at my end..