Skip to content

Commit

Permalink
- (Feature) Added ability to add circles to a map from the fieldtype.
Browse files Browse the repository at this point in the history
- (Feature) Added new GoogleMaps.Circle class for the plugin.js to plot circles on the front-end
  • Loading branch information
objectivehtml committed Sep 12, 2014
1 parent ef42cec commit 7c08372
Show file tree
Hide file tree
Showing 19 changed files with 3,300 additions and 315 deletions.
2 changes: 1 addition & 1 deletion GoogleMapsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function getName()

public function getVersion()
{
return '0.5.3';
return '0.6.0';
}

public function getDeveloper()
Expand Down
1 change: 1 addition & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
array('label' => 'Routes', 'value' => 'routes'),
array('label' => 'Polygons', 'value' => 'polygons'),
array('label' => 'Polylines', 'value' => 'polylines'),
array('label' => 'Circles', 'value' => 'circles'),
)

);
13 changes: 13 additions & 0 deletions fieldtypes/GoogleMaps_GoogleMapFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ public function onAfterElementSave()
$route->isNew = false;
}
}

foreach($data->circles as $index => $circle)
{
if($circle->deleted)
{
$data->removeCircle($index);
}
else
{
$circle->elementId = $this->element->id;
$circle->isNew = false;
}
}
}

if(isset($this->element->$handle))
Expand Down
39 changes: 39 additions & 0 deletions models/GoogleMaps_CircleModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
namespace Craft;

class GoogleMaps_CircleModel extends BaseModel
{
public function toJson()
{
return json_encode($this->getAttributes());
}

public function getStaticMapParameters()
{
// return 'markers=' . urldecode(!empty($this->address) ? $this->address : $this->lat.','.$this->lng);
}

protected function defineAttributes()
{
return array(
// Location Parameters
'title' => array(AttributeType::String, 'default' => ''),
'content' => array(AttributeType::String, 'default' => ''),
'lat' => array(AttributeType::Number, 'default' => 0),
'lng' => array(AttributeType::Number, 'default' => 0),
'metric' => array(AttributeType::String, 'default' => ''),
'radius' => array(AttributeType::String, 'default' => ''),
'address' => array(AttributeType::String, 'default' => ''),
'addressComponents' => array(AttributeType::Mixed, 'default' => array()),
'hideDetails' => array(AttributeType::Mixed, 'default' => true),
'strokeColor' => array(AttributeType::Mixed, 'default' => null),
'strokeWeight' => array(AttributeType::Mixed, 'default' => null),
'strokeOpacity' => array(AttributeType::Mixed, 'default' => null),
'fillColor' => array(AttributeType::Mixed, 'default' => null),
'fillOpacity' => array(AttributeType::Mixed, 'default' => null),
'isNew' => array(AttributeType::Bool, 'default' => true),
'elementId' => array(AttributeType::Mixed, 'default' => false),
'deleted' => array(AttributeType::Bool, 'default' => false),
);
}
}
80 changes: 74 additions & 6 deletions models/GoogleMaps_MapDataModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ public function __construct($data, $queryParams = false)
}

$this->polylines = $polylines;


$circles = array();

foreach($this->circles as $circle)
{
if(get_class($circle) != 'Craft\GoogleMaps_CircleModel')
{
$circle = GoogleMaps_CircleModel::populateModel((array) $circle);
}

$circles[] = $circle;
}

$this->circles = $circles;
}

public function markers()
Expand Down Expand Up @@ -205,6 +220,35 @@ public function getRoute($index)
return null;
}

public function getCircles()
{
$return = array();

foreach($this->circles as $circle)
{
if(get_class($circle) != 'Craft\GoogleMaps_CircleModel')
{
$circle = GoogleMaps_CircleModel::populateModel((array) $circle);
}

$return[] = $circle;
}

return $return;
}

public function getCircle($index)
{
$circles = $this->getCircles();

if(isset($circles[$index]))
{
return $circles[$index];
}

return null;
}

public function sortByDistanceAsc($a, $b)
{
return $a->distance < $b->distance ? -1 : 1;
Expand All @@ -221,7 +265,8 @@ public function toJson()
'markers' => array(),
'polygons' => array(),
'polylines' => array(),
'routes' => array()
'routes' => array(),
'circles' => array()
);

foreach($this->getMarkers() as $marker)
Expand All @@ -244,6 +289,11 @@ public function toJson()
$return['routes'][] = $route->getAttributes();
}

foreach($this->getCircles() as $circle)
{
$return['circles'][] = $circle->getAttributes();
}

return json_encode($return);
}

Expand All @@ -265,6 +315,24 @@ public function removeMarker($index)
$this->markers = $markers;
}

public function addCircle(GoogleMaps_CircleModel $circle)
{
$circles = $this->circles;

$circles[] = $circle;

$this->circles = $circles;
}

public function removeCircle($index)
{
$circles = $this->circles;

unset($circles[$index]);

$this->circles = $circles;
}

public function addPolygon(GoogleMaps_PolygonModel $polygon)
{
$polylines = $this->polylines;
Expand Down Expand Up @@ -333,11 +401,11 @@ public function getStaticMapModel($options = array())
protected function defineAttributes()
{
return array(
// Location Parameters
'markers' => array(AttributeType::Mixed, 'default' => array()),
'polygons' => array(AttributeType::Mixed, 'default' => array()),
'polylines' => array(AttributeType::Mixed, 'default' => array()),
'routes' => array(AttributeType::Mixed, 'default' => array())
'markers' => array(AttributeType::Mixed, 'default' => array()),
'polygons' => array(AttributeType::Mixed, 'default' => array()),
'polylines' => array(AttributeType::Mixed, 'default' => array()),
'routes' => array(AttributeType::Mixed, 'default' => array()),
'circles' => array(AttributeType::Mixed, 'default' => array())
);

}
Expand Down
5 changes: 4 additions & 1 deletion resources/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@

h2 .oh-google-map-small-text { margin-left: 10px; }

.oh-google-map-margin-bottom, p.oh-google-map-margin-bottom { margin: 0 0 15px !important; }
.oh-google-map-margin-top, p.oh-google-map-margin-top { margin-top: 15px !important; }
.oh-google-map-margin-bottom, p.oh-google-map-margin-bottom { margin-bottom: 15px !important; }
.oh-google-map-margin-left, p.oh-google-map-margin-left { margin-left: 15px !important; }
.oh-google-map-margin-right, p.oh-google-map-margin-right { margin-right: 15px !important; }

.oh-google-map-no-margin { margin: 0 !important; }
.oh-google-map-no-padding { padding: 0 !important; }
Expand Down
2 changes: 1 addition & 1 deletion resources/css/app.min.css

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion resources/css/fieldtype.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@

h2 .oh-google-map-small-text { margin-left: 10px; }

.oh-google-map-margin-bottom, p.oh-google-map-margin-bottom { margin: 0 0 15px !important; }
.oh-google-map-margin-top, p.oh-google-map-margin-top { margin-top: 15px !important; }
.oh-google-map-margin-bottom, p.oh-google-map-margin-bottom { margin-bottom: 15px !important; }
.oh-google-map-margin-left, p.oh-google-map-margin-left { margin-left: 15px !important; }
.oh-google-map-margin-right, p.oh-google-map-margin-right { margin-right: 15px !important; }

.oh-google-map-no-margin { margin: 0 !important; }
.oh-google-map-no-padding { padding: 0 !important; }
Expand Down
Loading

0 comments on commit 7c08372

Please sign in to comment.