Skip to content

Commit 1d5c858

Browse files
committed
- (Feature) Added new template tag to plot circles without the field type
1 parent 7c08372 commit 1d5c858

File tree

7 files changed

+92
-3
lines changed

7 files changed

+92
-3
lines changed

resources/js/app.compiled.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13916,6 +13916,13 @@ var GoogleMaps = {
1391613916
}
1391713917
});
1391813918

13919+
_.each(this.circles, function(circle) {
13920+
if(!circle.get('deleted')) {
13921+
bounds.union(circle.getBounds());
13922+
boundsChanged = true;
13923+
}
13924+
});
13925+
1391913926
_.each(this.routes, function(route) {
1392013927
_.each(route.getLocations(), function(location) {
1392113928
bounds.extend(new google.maps.LatLng(location.lat, location.lng));

resources/js/app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,13 @@ var GoogleMaps = {
30913091
}
30923092
});
30933093

3094+
_.each(this.circles, function(circle) {
3095+
if(!circle.get('deleted')) {
3096+
bounds.union(circle.getBounds());
3097+
boundsChanged = true;
3098+
}
3099+
});
3100+
30943101
_.each(this.routes, function(route) {
30953102
_.each(route.getLocations(), function(location) {
30963103
bounds.extend(new google.maps.LatLng(location.lat, location.lng));

resources/js/app.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/app/views/Map.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,13 @@
518518
}
519519
});
520520

521+
_.each(this.circles, function(circle) {
522+
if(!circle.get('deleted')) {
523+
bounds.union(circle.getBounds());
524+
boundsChanged = true;
525+
}
526+
});
527+
521528
_.each(this.routes, function(route) {
522529
_.each(route.getLocations(), function(location) {
523530
bounds.extend(new google.maps.LatLng(location.lat, location.lng));

resources/js/plugin.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ var GoogleMaps = {
780780
}));
781781
}
782782
},
783+
783784
getDraggable: function() {
784785
return this.api.getDraggable();
785786
},
@@ -1357,6 +1358,7 @@ var GoogleMaps = {
13571358
content: circle.content,
13581359
fitBounds: t.fitBounds,
13591360
infoWindowOptions: options.infoWindowOptions ? options.infoWindowOptions : {},
1361+
metric: circle.metric,
13601362
options: {
13611363
center: new google.maps.LatLng(circle.lat, circle.lng),
13621364
radius: circle.radius,
@@ -1506,22 +1508,35 @@ var GoogleMaps = {
15061508

15071509
options: {},
15081510

1511+
infoWindowOptions: {},
1512+
15091513
map: false,
15101514

1515+
metric: 'miles',
1516+
15111517
constructor: function(map, options) {
15121518
this.map = map;
15131519

15141520
this.options = {};
15151521

1522+
this.infoWindowOptions = {};
1523+
15161524
this.base(options);
15171525

15181526
this.options.map = this.map.api;
1527+
this.options.radius = this.convertRadiusToMeters(this.options.radius, this.metric);
1528+
1529+
if(this.lat && this.lng) {
1530+
this.options.center = new google.maps.LatLng(this.lat, this.lng);
1531+
}
15191532

15201533
this.api = new google.maps.Circle(this.options);
15211534

15221535
this.bindEvents();
15231536

15241537
this.map.addCircle(this, this.fitBounds);
1538+
1539+
this.createInfoWindow();
15251540
},
15261541

15271542
bindEvents: function() {
@@ -1580,6 +1595,46 @@ var GoogleMaps = {
15801595
});
15811596
},
15821597

1598+
createInfoWindow: function(polygon) {
1599+
if(this.content) {
1600+
this.infoWindow = new google.maps.InfoWindow(_.extend({}, this.infoWindowOptions, {
1601+
content: this.content
1602+
}));
1603+
}
1604+
},
1605+
1606+
convertRadiusToMeters: function(radius, metric) {
1607+
radius = parseFloat(radius);
1608+
1609+
if(metric == 'miles') {
1610+
radius *= 1609.34;
1611+
}
1612+
else if(metric == 'feet') {
1613+
radius *= 0.3048;
1614+
}
1615+
else if(metric == 'kilometers') {
1616+
radius *= 1000;
1617+
}
1618+
1619+
return radius;
1620+
},
1621+
1622+
convertRadiusFromMeters: function(radius, metric) {
1623+
radius = parseFloat(radius);
1624+
1625+
if(metric == 'miles') {
1626+
radius *= 0.000621371;
1627+
}
1628+
else if(metric == 'feet') {
1629+
radius *= 3.28084;
1630+
}
1631+
else if(metric == 'kilometers') {
1632+
radius *= 0.001;
1633+
}
1634+
1635+
return radius;
1636+
},
1637+
15831638
getBounds: function() {
15841639
return this.api.getBounds();
15851640
},
@@ -1650,7 +1705,10 @@ var GoogleMaps = {
16501705

16511706
onCenterChanged: function() {},
16521707

1653-
onClick: function(e) {},
1708+
onClick: function(e) {
1709+
this.infoWindow.open(this.map.api);
1710+
this.infoWindow.setPosition(e.latLng);
1711+
},
16541712

16551713
onDblclick: function() {},
16561714

services/GoogleMaps_TemplatesService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ public function marker($id, $options = array())
131131
craft()->templates->includeJs('new GoogleMaps.Marker('.$id.','.json_encode((object) $options).');');
132132
}
133133

134+
public function circle($id, $options = array())
135+
{
136+
craft()->templates->includeJs('new GoogleMaps.Circle('.$id.','.json_encode((object) $options).');');
137+
}
138+
134139
private function _populateField($result)
135140
{
136141
if ($result['settings'])

variables/GoogleMapsVariable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function polyline($id, $points, $options = array())
5858
return craft()->googleMaps_templates->polyline($id, $points, $options);
5959
}
6060

61+
public function circle($id, $options = array())
62+
{
63+
return craft()->googleMaps_templates->circle($id, $options);
64+
}
65+
6166
public function currentLocation($id, $options = array())
6267
{
6368
return craft()->googleMaps_templates->currentLocation($id, $options);

0 commit comments

Comments
 (0)