Skip to content

Commit 1d613a0

Browse files
committed
2.1.0
1 parent 7803c21 commit 1d613a0

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.DS_Store
2+
.idea

code/Module.class.php

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class Module extends FormToolsModule
1818
protected $author = "Ben Keen";
1919
protected $authorEmail = "[email protected]";
2020
protected $authorLink = "http://formtools.org";
21-
protected $version = "2.0.2";
22-
protected $date = "2017-11-26";
21+
protected $version = "2.1.0";
22+
protected $date = "2019-10-16";
2323
protected $originLanguage = "en_us";
2424

2525
protected $nav = array(
@@ -30,6 +30,7 @@ public function install($module_id)
3030
{
3131
$db = Core::$db;
3232
$LANG = Core::$L;
33+
$root_url = Core::getRootUrl();
3334

3435
// check it's not already installed (i.e. check for the unique field type identifier)
3536
$field_type_info = FieldTypes::getFieldTypeByIdentifier("google_maps_field");
@@ -70,6 +71,69 @@ public function install($module_id)
7071
mapTypeControl: false
7172
};
7273
74+
function addYourLocationButton(map) {
75+
var controlDiv = document.createElement('div');
76+
77+
var defaultIconOpacity = 0.6;
78+
79+
var bg = document.createElement('button');
80+
bg.style.backgroundColor = '#fff';
81+
bg.style.border = 'none';
82+
bg.style.outline = 'none';
83+
bg.style.width = '40px';
84+
bg.style.height = '40px';
85+
bg.style.borderRadius = '2px';
86+
bg.style.boxShadow = '0 1px 4px rgba(0,0,0,0.3)';
87+
bg.style.cursor = 'pointer';
88+
bg.style.marginRight = '10px';
89+
bg.style.padding = '0';
90+
bg.title = 'Your Location';
91+
controlDiv.appendChild(bg);
92+
93+
var icon = document.createElement('div');
94+
icon.style.margin = '7px';
95+
icon.style.width = '26px';
96+
icon.style.height = '26px';
97+
icon.style.backgroundImage = 'url($root_url/modules/field_type_google_maps/images/location.png)';
98+
icon.style.backgroundSize = '26px 26px';
99+
icon.style.backgroundPosition = '0 0';
100+
icon.style.backgroundRepeat = 'no-repeat';
101+
icon.style.opacity = defaultIconOpacity;
102+
bg.appendChild(icon);
103+
104+
google.maps.event.addListener(map, 'center_changed', function () {
105+
icon.style.opacity = defaultIconOpacity;
106+
});
107+
108+
bg.addEventListener('click', function (e) {
109+
e.preventDefault();
110+
var currOpacity = 0,
111+
animationInterval = setInterval(function () {
112+
currOpacity = currOpacity === defaultIconOpacity ? 0.3 : defaultIconOpacity;
113+
icon.style.opacity = currOpacity;
114+
}, 500);
115+
116+
if (navigator.geolocation) {
117+
navigator.geolocation.getCurrentPosition(function(position) {
118+
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
119+
map.setCenter(latlng);
120+
map.setZoom(8);
121+
clearInterval(animationInterval);
122+
icon.style.opacity = defaultIconOpacity;
123+
}, function () {
124+
clearInterval(animationInterval);
125+
icon.style.opacity = defaultIconOpacity;
126+
}, { timeout: 60000 });
127+
} else {
128+
clearInterval(animationInterval);
129+
icon.style.opacity = defaultIconOpacity;
130+
}
131+
});
132+
133+
controlDiv.index = 1;
134+
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(controlDiv);
135+
}
136+
73137
var initMap = function () {
74138
var gmf_id = $(this).attr("id");
75139
var address_field = $(this).find(".cf_gmf_address");
@@ -99,6 +163,10 @@ public function install($module_id)
99163
google.maps.event.addListener(maps[gmf_id].map, 'zoom_changed', function (e) {
100164
$("#" + gmf_id).find("[name=" + field_name + "_zoom]").val(maps[gmf_id].map.getZoom());
101165
});
166+
167+
if (location.protocol === 'https:') {
168+
addYourLocationButton(maps[gmf_id].map);
169+
}
102170
};
103171
104172
// googleMapsInit may fire before or after DOM ready

images/location.png

5.49 KB
Loading

0 commit comments

Comments
 (0)