diff --git a/fieldtypes/GoogleMaps_GoogleMapFieldType.php b/fieldtypes/GoogleMaps_GoogleMapFieldType.php index 1ef8a3a..1ba003a 100644 --- a/fieldtypes/GoogleMaps_GoogleMapFieldType.php +++ b/fieldtypes/GoogleMaps_GoogleMapFieldType.php @@ -188,6 +188,18 @@ public function modifyElementsQuery(DbCommand $query, $params = array()) $this->queryParams = array_merge($defaultParams, $params); + if(isset($this->queryParams['latitude'])) + { + $this->queryParams['lat'] = $this->queryParams['latitude']; + unset($this->queryParams['latitude']); + } + + if(isset($this->queryParams['longitude'])) + { + $this->queryParams['lng'] = $this->queryParams['longitude']; + unset($this->queryParams['longitude']); + } + $handle = $this->model->handle; if(isset($this->queryParams['address'])) diff --git a/models/GoogleMaps_MapDataModel.php b/models/GoogleMaps_MapDataModel.php index 7c50408..7309321 100644 --- a/models/GoogleMaps_MapDataModel.php +++ b/models/GoogleMaps_MapDataModel.php @@ -119,12 +119,14 @@ public function getMarkers() $marker = GoogleMaps_MarkerModel::populateModel((array) $marker); } - if($this->queryParams) + if($this->queryParams && $marker->isWithinProximity($this->queryParams)) { - $marker->isWithinProximity($this->queryParams); + $return[] = $marker; + } + else if (!$this->queryParams) + { + $return[] = $marker; } - - $return[] = $marker; } if($this->queryParams) diff --git a/resources/js/plugin.js b/resources/js/plugin.js index 88089a1..6a0d82d 100644 --- a/resources/js/plugin.js +++ b/resources/js/plugin.js @@ -188,6 +188,10 @@ var GoogleMaps = { return this.api.getBounds(); }, + getCenter: function() { + return this.api.getCenter(); + }, + getDiv: function() { return this.api.getDiv(); }, @@ -1107,8 +1111,6 @@ var GoogleMaps = { }, updateMarkerIcons: function() { - var t = this; - _.each(this.getMarkers(), function(marker, i) { if(i < t.getMarkers().length - 1) { var icon = 'http://mt.google.com/vt/icon/text='+String.fromCharCode(65 + i)+'&psize=16&font=fonts/arialuni_t.ttf&color=ff330000&name=icons/spotlight/spotlight-waypoint-a.png&ax=44&ay=48&scale=2'; @@ -1117,10 +1119,10 @@ var GoogleMaps = { var icon = 'http://mt.google.com/vt/icon/text='+String.fromCharCode(65 + i)+'&psize=16&font=fonts/arialuni_t.ttf&color=ff330000&name=icons/spotlight/spotlight-waypoint-b.png&ax=44&ay=48&scale=2'; } - t.getLocation(i).icon = icon; + this.getLocation(i).icon = icon; marker.setIcon(icon); - }); + }, this); }, directionsRequest: function(callback) { @@ -1434,8 +1436,15 @@ var GoogleMaps = { markerOptions: {}, + positionOptions: { + enableHighAccuracy: true, + maximumAge: 1000 + }, + map: false, + hasSetBounds: false, + constructor: function(map, options) { this.map = map; @@ -1446,7 +1455,10 @@ var GoogleMaps = { this.base(options); + console.log(this.positionOptions); + this.api = new GeolocationMarker(this.map.api, this.circleOptions, this.markerOptions); + this.setPositionOptions(this.positionOptions); this.bindEvents(); }, @@ -1516,9 +1528,10 @@ var GoogleMaps = { onGeolocationError: function() {}, onPositionChanged: function() { - if(this.fitBounds) { + if(this.fitBounds && !this.hasSetBounds) { this.map.bounds.extend(this.getPosition()); this.map.fitBounds(this.map.bounds); + this.hasSetBounds = true; } }