Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » Google Maps without Forum

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 2214 Views
  • danqxx
    Avatar
    Community Member
    14 Posts

    Google Maps without Forum Link to this post

    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

  • Hubertus
    Avatar
    Community Member
    14 Posts

    Re: Google Maps without Forum Link to this post

    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!

  • danqxx
    Avatar
    Community Member
    14 Posts

    Re: Google Maps without Forum Link to this post

    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;
    }
    }

  • danqxx
    Avatar
    Community Member
    14 Posts

    Re: Google Maps without Forum Link to this post

    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

  • jolts
    Avatar
    Community Member
    3 Posts

    Re: Google Maps without Forum Link to this post

    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..

    2214 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.