4

I'm working on a Silverstripe project which contains geographical areas as part of the ModelAdmin/CMS interface.

Each area has the following information:

  • North-east corner latitude
  • North-east corner longitude
  • South-west corner latitude
  • South-west corner longitude
  • Centre point latitude
  • Centre point longitude

I'd like to be able to embed a simple Google Map showing the bounds so admin users have a visual reference. If I used an iframe and focussed on the centre point (Lat/Lng) it would be very easy using a Literalfield:

public function getCMSFields(){
  $fields = parent::getCMSFields();
  $fields->addFieldToTab(
    'Root.Main',
    LiteralField::Create('DisplayMap', '<iframe width="600" height="450"    
      src="https://www.google.com/maps/embed/v1/view?zoom=11&
      center=-'.$this->Lat.','.$this->Lng.'&key=123456"></iframe>')
    );
    return $fields;
 }

However I'd like the map to show the bound - something that I don't think is possible without Javascript.

What would be the best approach to embed a map in ModelAdmin that shows the bounds of the area?

BaronGrivet
  • 4,364
  • 5
  • 37
  • 52
  • Can you add your own Javascript file to define the bounds? – scrowler Apr 18 '16 at 04:51
  • This is how you can add your own js into CMS admin: Config::inst()->update('LeftAndMain', 'extra_requirements_javascript', array( $project . '/javascript/mymaps.js' )); – Greg Smirnov Apr 20 '16 at 09:07
  • There are some googlemap fields around for backend, e.g https://github.com/BetterBrief/silverstripe-googlemapfield or https://github.com/gordonbanderson/Mappable/blob/3.1/code/MapField.php . IMHO it's better to create a special Field Object for this instead of (ab)using LiteralField.Those special fields can also handle the logic for saving in the right variables. – wmk Apr 27 '16 at 07:05

0 Answers0