* @version 0.1
*/
-
// Load Members Data Class
-require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMembers.php';
/*
* This class exports the currently selected members list
* @return object Class object
*
*/
- public function __construct ($wpdb, $config)
+ public function __construct( $wpdb, $config )
{
// Save WordPress Database object
// Save plugin configuration object
$this->config = $config;
- parent::__construct(false, false);
+ parent::__construct( false, false );
}
*
* Echos JSON string as response and does not return
*/
- public function modelAction ($actionData = false)
+ public function modelAction( $actionData = false )
{
$ret = false;
- $poiAreas = false; // False means to search anywhere
+ $poiAreas = false; // False means to search anywhere
// Get any search string
- $searchText = html_entity_decode( filter_input(INPUT_GET, 'searchText', FILTER_SANITIZE_STRING), ENT_QUOTES | ENT_XML1);
+ $searchText = html_entity_decode( filter_input( INPUT_GET, 'searchText', FILTER_SANITIZE_STRING ),
+ ENT_QUOTES | ENT_XML1 );
- $request = filter_input(INPUT_GET, 'request', FILTER_SANITIZE_STRING);
+ $request = filter_input( INPUT_GET, 'request', FILTER_SANITIZE_STRING );
// Get the target LAT/LON area
- $latMax = filter_input(INPUT_GET, 'latMax', FILTER_VALIDATE_FLOAT);
- $latMin = filter_input(INPUT_GET, 'latMin', FILTER_VALIDATE_FLOAT);
- $lonMax = filter_input(INPUT_GET, 'lonMax', FILTER_VALIDATE_FLOAT);
- $lonMin = filter_input(INPUT_GET, 'lonMin', FILTER_VALIDATE_FLOAT);
-
+ $latMax = filter_input( INPUT_GET, 'latMax', FILTER_VALIDATE_FLOAT );
+ $latMin = filter_input( INPUT_GET, 'latMin', FILTER_VALIDATE_FLOAT );
+ $lonMax = filter_input( INPUT_GET, 'lonMax', FILTER_VALIDATE_FLOAT );
+ $lonMin = filter_input( INPUT_GET, 'lonMin', FILTER_VALIDATE_FLOAT );
// If this is not an "anywhere" search, then build the lat/lon areas
- switch($request) {
+ switch ( $request ) {
- case 'onMap';
+ case 'onMap':
// Check for good LAT/LON data
- if ($latMax && $latMin && $lonMax && $lonMin) {
+ if ( $latMax && $latMin && $lonMax && $lonMin ) {
// Get the previous target LAT/LON area
- $lastLatMax = filter_input(INPUT_GET, 'lastLatMax', FILTER_VALIDATE_FLOAT);
- $lastLatMin = filter_input(INPUT_GET, 'lastLatMin', FILTER_VALIDATE_FLOAT);
- $lastLonMax = filter_input(INPUT_GET, 'lastLonMax', FILTER_VALIDATE_FLOAT);
- $lastLonMin = filter_input(INPUT_GET, 'lastLonMin', FILTER_VALIDATE_FLOAT);
+ $lastLatMax = filter_input( INPUT_GET, 'lastLatMax', FILTER_VALIDATE_FLOAT );
+ $lastLatMin = filter_input( INPUT_GET, 'lastLatMin', FILTER_VALIDATE_FLOAT );
+ $lastLonMax = filter_input( INPUT_GET, 'lastLonMax', FILTER_VALIDATE_FLOAT );
+ $lastLonMin = filter_input( INPUT_GET, 'lastLonMin', FILTER_VALIDATE_FLOAT );
// If this is the first load, request all POIs within map bounds
- if ($lastLatMax == false) {
+ if ( $lastLatMax == false ) {
// Add entire map as area to update
$poiAreas[] = array(
'lonMin' => $lonMin
);
- // Otherwise request only those POIs in the new map areas
+ // Otherwise request only those POIs in the new map areas
} else {
// Check for good last LAT/LON data
- if ($lastLatMax && $lastLatMin && $lastLonMax && $lastLonMin) {
+ if ( $lastLatMax && $lastLatMin && $lastLonMax && $lastLonMin ) {
// Check if there's new area at the top of the map
- if ($latMax > $lastLatMax) {
+ if ( $latMax > $lastLatMax ) {
$poiAreas[] = array(
'area' => 'New at top',
'latMax' => $latMax,
}
// Check if there's new area at the bottom of the map
- if ($latMin < $lastLatMin) {
+ if ( $latMin < $lastLatMin ) {
$poiAreas[] = array(
'area' => 'New at bottom',
'latMax' => $lastLatMin,
}
// Check if there's new area at the left of the map
- if ($lonMin < $lastLonMin) {
+ if ( $lonMin < $lastLonMin ) {
$poiAreas[] = array(
'area' => 'New at left',
'latMax' => $latMax,
}
// Check if there's new area at the right of the map
- if ($lonMax > $lastLonMax) {
+ if ( $lonMax > $lastLonMax ) {
$poiAreas[] = array(
'area' => 'New at right',
'latMax' => $latMax,
'lonMin' => $lastLonMax
);
}
-
}
-
}
-
}
break;
default:
$request = 'onMap';
break;
-
}
- /*
+ /*
* Get map items
*
* (NOTE that while this is for a front-end feature, that feature gets
- * data via AJAX, which is processed by the admin controller.)
+ * data via AJAX, which is processed by the admin controller.)
*
* The array supplied is in the following standardized format. This format is
* used for all generic map items aggregated from multiple sources.
*
- * 'request' What type of request is being made - Request only
- * 'filter' A string filter to use to limit results - Request only
- * 'area' A set of lat/lon areas to get results for (if request = 'onMap') - Request only
- * If false then get all results without regard as to where they are.
- * 'sources' An array of source information for what type of item and which add-on - Each source adds one entry here
- * 'mapItems' Array of new map items to return to NearMe - Each source adds one or more map items here
+ * 'request' What type of request is being made - Request only
+ * 'filter' A string filter to use to limit results - Request only
+ * 'area' A set of lat/lon areas to get results for (if request = 'onMap') - Request only
+ * If false then get all results without regard as to where they are.
+ * 'sources' An array of source information for what type of item and which add-on - Each
+ * source adds one entry here
+ * 'mapItems' Array of new map items to return to NearMe - Each source adds one or more map
+ * items here
*
* array(
- * 'request' => {'onMap', 'anywhere'}
- * 'filter' => {some search string}
- * 'area' => array(
- * // First area to search
- * array(
- * 'latMax' => {lat at North end of area},
- * 'latMin' => {lat at South end of area},
- * 'lonMax' => {lon at East end of area},
- * 'lonMin' => {lon at West end of area}
- * ),
- * // Second area to search
- * array(
- * 'latMax' => {lat at North end of area},
- * 'latMin' => {lat at South end of area},
- * 'lonMax' => {lon at East end of area},
- * 'lonMin' => {lon at West end of area}
- * ),
- * // Additional areas
- * ),
- * 'sources' = array(
- * {addOn Slug} => array(
- * 'addOn' => {addOn Slug},
- * 'type' => {Name to use for the source - Needs to match the 'type' element in map items added by the addOn )
- * ),
- * // Additional sources
- * ),
- * 'mapItems' => array(
- * array(
- * 'type' => {type of item, i.e. 'member', 'event', ...},
- * 'id' => {ID of item for reference},
- * 'lat' => {Latitude},
- * 'lon' => {Longitude},
- * 'name' => {Name of item},
- * 'loc_name' => {Name of Location},
- * 'addr1' => {Address line 1 of location},
- * 'addr2' => {Address line 2 of location},
- * 'city' => {City of location},
- * 'state' => {State code of location},
- * 'zip' => {Postal Code of location},
- * 'phone' => {Contact phone number},
- * 'email' => {Contact E-Mail address},
- * 'url' => {URL of item},
- * 'region' => {Region name, if available},
- * 'categories' => {array of categories - i.e. array( 0 = array( id => {id}, name => {name}), ... )
- * 'descr' => {Description},
- * 'short_descr' => {Short Description},
- * 'detail_page' => {URL of detail page, if available},
- * 'dates' => {Text stating date, dates, or date range},
- * 'times' => {Text stating time, times, or time range}
- * )
- * )
+ * 'request' => {'onMap', 'anywhere'}
+ * 'filter' => {some search string}
+ * 'area' => array(
+ * // First area to search
+ * array(
+ * 'latMax' => {lat at North end of area},
+ * 'latMin' => {lat at South end of area},
+ * 'lonMax' => {lon at East end of area},
+ * 'lonMin' => {lon at West end of area}
+ * ),
+ * // Second area to search
+ * array(
+ * 'latMax' => {lat at North end of area},
+ * 'latMin' => {lat at South end of area},
+ * 'lonMax' => {lon at East end of area},
+ * 'lonMin' => {lon at West end of area}
+ * ),
+ * // Additional areas
+ * ),
+ * 'sources' = array(
+ * {addOn Slug} => array(
+ * 'addOn' => {addOn Slug},
+ * 'type' => {Name to use for the source - Needs to match the 'type' element in map items
+ * added by the addOn )
+ * ),
+ * // Additional sources
+ * ),
+ * 'mapItems' => array(
+ * array(
+ * 'type' => {type of item, i.e. 'member', 'event', ...},
+ * 'id' => {ID of item for reference},
+ * 'lat' => {Latitude},
+ * 'lon' => {Longitude},
+ * 'name' => {Name of item},
+ * 'loc_name' => {Name of Location},
+ * 'addr1' => {Address line 1 of location},
+ * 'addr2' => {Address line 2 of location},
+ * 'city' => {City of location},
+ * 'state' => {State code of location},
+ * 'zip' => {Postal Code of location},
+ * 'phone' => {Contact phone number},
+ * 'email' => {Contact E-Mail address},
+ * 'url' => {URL of item},
+ * 'region' => {Region name, if available},
+ * 'categories' => {array of categories - i.e. array( 0 = array( id => {id}, name =>
+ * {name}), ... )
+ * 'descr' => {Description},
+ * 'short_descr' => {Short Description},
+ * 'detail_page' => {URL of detail page, if available},
+ * 'dates' => {Text stating date, dates, or date range},
+ * 'times' => {Text stating time, times, or time range}
* )
+ * )
+ * )
+ *
+ * Current locations of an "add_filter()" call for this apply_filters() call are...
+ * glm-members-db/setup/adminHooks.php - Aprox Line 200 and below
+ * glm-members-db-events/setup/adminHooks.php - Aprox line 150 and below
*/
- $poiData = apply_filters(
- 'glm-hook-list-map-items-by-latlon',
+ $poiData = apply_filters( 'glm-hook-list-map-items-by-latlon',
array(
- 'request' => $request,
- 'filter' => $searchText,
- 'area' => $poiAreas,
+ 'request' => $request,
+ 'filter' => $searchText,
+ 'area' => $poiAreas,
'sources' => array(),
'mapItems' => array()
- )
- );
+ ) );
- header('Content-type:application/json;charset=utf-8', true);
- echo json_encode($poiData);
+ header( 'Content-type:application/json;charset=utf-8', true );
+ echo json_encode( $poiData );
wp_die();
<div>
Display only items matching this text:
-
- <a id="glmNearMeSearchAnywhere" class="button button-secondary glm-member-button-small">Search All Areas</a>
+
+ <a id="glmNearMeSearchAnywhere" class="button button-secondary glm-member-button-small">Search All Areas</a>
<input id="glmNearMeSearchText" type="text">
</div>
-
+
<p><!-- just adding space here temporarily --></p>
-
+
<div style="height: 2em;">
- <b>My Location:</b>
+ <b>My Location:</b>
<input id="glmMyLocationFollowMe" class="glmMapMyLocationType" type="radio" name="myLocationType" value="track" checked="checked"> Follow Me
<input id="glmMyLocationSet" class="glmMapMyLocationType" type="radio" name="myLocationType" value="set"> Manual Map Selection
<div>
My Location <img src="{$assetsUrl}/MapIcons/standard/woman.png"> (drag to change)
<span id="glm-mapClusterLegend" class="glm-right">
- Clustered locations - Click to view:
+ Clustered locations - Click to view:
<img style="width: 26px; height: auto;" src="{$baseUrl}/js/googleMapsMarkerClusterer/images/m1.png">
<img style="width: 28px; height: auto;" src="{$baseUrl}/js/googleMapsMarkerClusterer/images/m2.png">
<img style="width: 33px; height: auto;" src="{$baseUrl}/js/googleMapsMarkerClusterer/images/m3.png">
<!-List of favorites goes here -->
</div>
</div>
-
+
<div id="nearMe-mouseover-template" class="glm-hidden">
{ name } - Click for more
</div>
-
+
<script type="text/javascript">
jQuery(document).ready(function($) {
-
+
/*
* Google Maps
* API reference: https://developers.google.com/maps/documentation/javascript/reference
*/
-
+
// Settings
var doDetailSection = false; // Show detail section below map
var doPOIListSection = false; // Show a list of map points of interest below map
var clusterMaxZoom = 14; // Maximum map zoom where clustering may take place. Higher number is smaller map area. Set to 1 to effectively dissable clustering.
var clusterMinSize = 3; // Minimum number of markers that may be in a cluster.
var mapLat = {$mapCenterLat}; // Set default map Lat - Default for the current Website
- var mapLon = {$mapCenterLon}; // Set default map Lon - Default for the current Website
+ var mapLon = {$mapCenterLon}; // Set default map Lon - Default for the current Website
var refLat = {$refLat}; // Default location for My Location marker - Lat
var refLon = {$refLon}; // Default location for My Location marker - Lon
var maxAnywhereZoom = 14; // Max zoom in when doing anywhere search
var postionTimeout = 15000; // Maximum amount of time we'll wait for geolocation result - 15 Sec
var geolocationFailCount = 2; // Allow geolocation to fail this many times before switching to manual location settings ('set')
var trackToConsole = false; // Send debug/progress messages to developers console (Firefox)
- var resetPOIsAlways = true; // Always reset all POIs when updating map. Otherwise ones off the map are deleted and the new request is for the entire map.
-
+ var resetPOIsAlways = false; // Always reset all POIs when updating map. Otherwise ones off the map are deleted and the new request is for the entire map.
+
// Set default - Need to make this configurable
var mapLocation = new google.maps.LatLng(mapLat, mapLon);
var refLocation = new google.maps.LatLng(refLat, refLon);
var geolocationFailCounter = 0;
var stopGeolocation = false;
var noProcessAfterZoom = false;
-
-
+
+
function initMap() {
-
+
if (trackToConsole) { console.log('GLM NearMe: initMap()'); }
-
- map = new google.maps.Map(document.getElementById('glm-nearmeMap'), {
- zoom: defZoom,
- disableDefaultUI: false,
- mapTypeId: google.maps.MapTypeId.MAP
+
+ map = new google.maps.Map(document.getElementById('glm-nearmeMap'), {
+ zoom: defZoom,
+ disableDefaultUI: false,
+ mapTypeId: google.maps.MapTypeId.MAP
});
var geocoder = new google.maps.Geocoder();
});
// Create a moveable marker for our currently saved reference location
- myMarker = new google.maps.Marker({
- map: map,
+ myMarker = new google.maps.Marker({
+ map: map,
position: refLocation,
draggable: enableDraggable,
- animation: google.maps.Animation.DROP,
+ animation: google.maps.Animation.DROP,
icon: '{$assetsUrl}/MapIcons/standard/woman.png'
});
-
+
// Get initial user location, but wait a bit for things to get seup.
google.maps.event.addListenerOnce(map, 'idle', function(){
window.setTimeout(getUserLocation, 1000);
curCenter = map.getCenter();
});
-
+
google.maps.event.addListener(myMarker, 'dragend', function(event) {
-// Save My location stuff here
+// Save My location stuff here
});
// Add lister to capture map position and zoom before dragging
map.addListener('dragstart', function() {
-
+
if (trackToConsole) { console.log('GLM NearMe: Drag map started'); }
-
+
// Close map bubble if used
// closeMapBubble();
-
+
});
-
- // On first load get all POIs for current bounds - Don't push position
+
+ // On first load get all POIs for current bounds - Don't push position
dontPushPos = true;
checkNewPOIs(boundsTimeout * 2); // Give things a bit more time to be ready before gettign POIs the first time.
-
+
// Add a click listener for this marker
myMarker.addListener('mouseover', function() {
-
+
if (trackToConsole) { console.log('GLM NearMe: myMarker mouseover'); }
-
+
if (dragging) {
return;
}
content: 'My Selected Location'
});
mapTitle.open(map, this);
-
+
});
-
+
myMarker.addListener('mouseout', function() {
-
+
if (trackToConsole) { console.log('GLM NearMe: myMarker mouseout'); }
-
+
if (dragging) {
return;
}
mapTitle.close();
checkNewPOIs();
-
+
});
myMarker.addListener('dragstart', function() {
-
+
if (trackToConsole) { console.log('GLM NearMe: myMaker dragstart'); }
-
+
dragging = true;
mapTitle.close();
window.clearTimeout(boundsDelayTimer);
-
+
});
myMarker.addListener('dragend', function() {
-
+
if (trackToConsole) { console.log('GLM NearMe: myMarker dragend'); }
-
+
dragging = false;
checkNewPOIs();
-
+
});
// Request update for points of interest when map dragging stops.
map.addListener('dragend', function() {
-
+
if (trackToConsole) { console.log('GLM NearMe: map dragend'); }
-
+
checkNewPOIs();
});
-
+
// Request update for points of interest when map zoom changes.
map.addListener('zoom_changed', function() {
-
+
if (trackToConsole) { console.log('GLM NearMe: map zoom changed'); }
-
+
// Close map bubble if used
// closeMapBubble();
-
+
// Check if we need to get new POIs after this zoom - Dissabled for "everywhere" search
if (!noProcessAfterZoom) {
checkNewPOIs();
if (trackToConsole) { console.log('GLM NearMe: Not calling checkNewPOIs() for this zoom'); }
noProcessAfterZoom = false;
}
-
+
});
-
+
}
// Return to My Location
$('#glmMapGoToMyLocation').on('click', function() {
-
+
if (trackToConsole) { console.log('GLM NearMe: User GoToMyLocation clicked'); }
-
+
noProcessAfterZoom = true;
-
+
// Go to the user's saved postion and default zoom
map.panTo(myMarker.getPosition());
map.setZoom(defZoom)
-
+
// Clear all POIs and run check for new ones.
checkNewPOIs(boundsTimeout, true);
-
+
});
-
+
// Set My Selected Location to center of map
$('#glmMapSetMyLocation').on('click', function() {
-
+
if (trackToConsole) { console.log('GLM NearMe: User SetMyLocation clicked'); }
-
+
myMarker.setPosition(map.getCenter());
});
-
+
// Previous Map Position request by user
$('#glmMapBack').on('click', function() {
-
+
if (trackToConsole) { console.log('GLM NearMe: User MapBack clicked'); }
-
+
// If there's any previous map positions on the stack
- if (mapViewStack.length) {
-
+ if (mapViewStack.length) {
+
if (trackToConsole) { console.log('GLM NearMe: Moving to previous map position'); }
-
+
dontPushPos = true;
-
+
// Get the previons position data
var poppedPos = mapViewStack.pop();
-
+
// Set the map to the popped position
map.panTo(poppedPos.center);
map.setZoom(poppedPos.zoom);
// If there's nothing left on the stack, remove back button
if (!mapViewStack.length) {
-
+
if (trackToConsole) { console.log('GLM NearMe: No previous map postion'); }
-
+
$('#glmMapBack').addClass('glm-hidden');
}
checkNewPOIs();
}
-
+
return false;
});
-
+
// Search Anywhere button is clicked.
$('#glmNearMeSearchAnywhere').click('change', function() {
-
+
// Using getBoundsPOIs here because it's awkward to wait when a button is clicked
getBoundsPOIs(true, true);
-
+
});
// Text search requested
function checkNewPOIs(timeout = boundsTimeout, resetPOIs = resetPOIsAlways, anywhere = false) {
if (trackToConsole) { console.log('GLM NearMe: checkNewPOIs()'); }
-
+
// Reset the delay timer to make sure nothing happens from an earlier dragend
window.clearTimeout(boundsDelayTimer);
-
+
// Set timer to get POIs
boundsDelayTimer = window.setTimeout(getBoundsPOIs, timeout, resetPOIs, anywhere);
-
+
}
-
- /*
+
+ /*
* Get new bounds for map and check for POI changes
- *
+ *
* type 'onMap' or 'anywhere'
* searchText A string that should match any returned results
* resetPOIs true to clear all POIs and reload them all for current map bounds
* Not needed for type 'anywhere' - full reset is assumned
*/
function getBoundsPOIs(resetPOIs = resetPOIsAlways, anywhere = false) {
-
+
if (trackToConsole) { console.log('GLM NearMe: getBoundsPOIs() '); }
-
+
var searchText = $('#glmNearMeSearchText').val();
var request = 'onMap';
if (anywhere) {
request = 'anywhere';
-
+
// If we're currently in "Follow Me" mode, switch to manual
if (trackingType == 'track') {
setMyLocationToManual();
}
-
+
}
-
+
// Get current map view data
mapBounds = map.getBounds();
ne = mapBounds.getNorthEast();
latMin = sw.lat();
lonMax = ne.lng();
lonMin = sw.lng();
-
+
// If "reset" requested, clear last position values
if (resetPOIs) {
lastLatMax = false;
lastLonMax = false;
lastLonMin = false;
}
-
+
// Check if there's been no movement - Don't do anything.
if ( latMax == lastLatMax && latMin == lastLatMin && lonMax == lastLonMax && lonMin == lastLonMin ) {
-
+
if (trackToConsole) { console.log('GLM NearMe: No map change, aborting getBoundsPOIs()'); }
-
+
hideLoadingMsg();
-
+
return;
}
-
+
showLoadingMsg();
-
+
// If there is a previous map position, push that on the stack - unless we've been told not to
if (dontPushPos) {
dontPushPos = false;
} else {
-
+
if (trackToConsole) { console.log('GLM NearMe: Pushing location on stack'); }
-
+
// Push the previous position on the stack
mapViewStack.push({
zoom: curZoom,
center: curCenter
});
-
+
// Show the back button
$('#glmMapBack').removeClass('glm-hidden');
-
+
}
-
+
// Request any POIs in new areas of the map
$.getJSON(
'{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=getPOI&request='+request+'&latMax='+latMax+'&latMin='+latMin+'&lonMax='+lonMax+'&lonMin='+lonMin+'&lastLatMax='+lastLatMax+'&lastLatMin='+lastLatMin+'&lastLonMax='+lastLonMax+'&lastLonMin='+lastLonMin,
'searchText='+searchText,
function( newPOIs ) {
-
+
if (trackToConsole) { console.log('GLM NearMe: Requesting newPOIs'); }
if (trackToConsole) { console.log('GLM NearMe: Number of markers = '+Object.keys(markers).length); }
// If resetPOIs is requested, clear all clusterer markers, all map markers, and our own markers array.
if (resetPOIs) {
-
+
markerClusterer.clearMarkers();
markerClusterer.repaint();
-
+
// map.markers = [];
markers = [];
// markerClusterer.redraw();
-
+
if (trackToConsole) { console.log('GLM NearMe: Clearing all markers.'); }
-
+
// Otherwise remove only markers that are off our map
} else {
-
+
// Delete the POIs that are off our map
for (key in markers) {
-
+
// If reset is requested or this marker is not within our map bounds. remove the marker and delete it
- if (markers[key].getPosition().lat() > latMax || markers[key].getPosition().lat() < latMin ||
+ if (markers[key].getPosition().lat() > latMax || markers[key].getPosition().lat() < latMin ||
markers[key].getPosition().lng() > lonMax || markers[key].getPosition().lng() < lonMin) {
-
+
// Add this marker to the delete queue
delQueue.push(key);
}
-
- }
-
+
+ }
+
if (trackToConsole) { console.log('GLM NearMe: Markers in delete queue = '+Object.keys(delQueue).length); }
// Remove markers in the delete queue from the clusterer and markers array - can't do this in loop above
- var deleted = 0;
+ var deleted = 0;
if (Object.keys(delQueue).length) {
- $.each( delQueue, function(key, value) {
-
+ $.each( delQueue, function(key, value) {
+
// Remove the marker from the clusterer
markerClusterer.removeMarker(markers[value]);
-
+
// Remove the marker from the map
markers[value].setMap(null);
-
+
// Delete our marker
delete markers[value];
-
+
deleted++;
-
+
});
}
- delQueue = []; // Clear delete queue
+ delQueue = []; // Clear delete queue
if (trackToConsole) { console.log('GLM NearMe: Number of markers deleted = '+deleted); }
-
+
}
-
-if (trackToConsole) { console.log('GLM NearMe: Number of markers remaining = '+Object.keys(markers).length); }
-
-
+
+ if (trackToConsole) { console.log('GLM NearMe: Number of markers remaining = '+Object.keys(markers).length); }
+
+
if (trackToConsole) { console.log('GLM NearMe: Processing '+Object.keys(newPOIs.sources).length+' POI sources'); }
-
+
// Add all sources (members, events, ...) to the assignedPushPins array
$.each( newPOIs.sources, function(key, value) {
if (!assignedPushPins[value.type]) {
-
+
if (trackToConsole) { console.log('GLM NearMe: Adding POI type '+value.type); }
-
+
// Pull a new pushpin off the available stack and assign that to this type
pushPin = availPushPins.pop();
pushPinData = { pinFile: pushPin, pinOn: true };
// Add the new pushpin to the map legend
$('#glm-mapLegend').append('<input data-type="'+value.type+'" class="glm-type-select" type="checkbox" checked><img src="{$assetsUrl}/MapIcons/'+pushPin+'"> '+value.type+' ');
-
- }
+
+ }
});
// Re-bind click on ping type for when a pin type is turned on or off by the user
// Note that .upbind().on() prevents the event from being bound multiple times from multiple map moves.
$('.glm-type-select').unbind('click').on('click', function() {
-
+
// Get the type and current visibility state
pinType = $(this).attr('data-type');
- pinVisible = $(this).prop('checked');
-
+ pinVisible = $(this).prop('checked');
+
if (trackToConsole) { console.log('Pin type "'+pinType+' set to '+pinVisible); }
-
+
// Save visibility to the specified assignedPushPins element
assignedPushPins[pinType].pinOn = pinVisible;
-
+
// loop through all current markers and set visibility for any of that type
- for (key in markers) {
+ for (key in markers) {
if (markers[key].type == pinType) {
-
+
// Set marker visibility
markers[key].setVisible(pinVisible);
-
+
// If not visible, remove from clusterer. If visible, add back to clusterer
if (pinVisible) {
markerClusterer.addMarker(markers[key]);
markerClusterer.removeMarker(markers[key]);
}
}
-
+
}
});
-
+
// If we have new POIs
if (newPOIs.mapItems.length > 0) {
- if (trackToConsole) { console.log('GLM NearMe: Processing '+Object.keys(newPOIs.mapItems).length+' new POIs'); }
+ if (trackToConsole) { console.log('GLM NearMe: Processing '+Object.keys(newPOIs.mapItems).length+' new POIs'); }
$.each( newPOIs.mapItems, function(key, value) {
var markerKey = value.type+'_'+value.id+'_'+value.lat+'_'+value.lon;
-
+
// Create marker - add some other information we'll need for each marker
value.position = new google.maps.LatLng(value.lat, value.lon);
marker = new google.maps.Marker({
visible: assignedPushPins[value.type].pinOn,
id: value.type+value.id
})
-
+
// Add a click listener for this marker
marker.addListener('mouseover', function() {
-
+
template = $('#nearMe-mouseover-template').html();
template = template.replace(/{ name }/g, value.name);
// closeMapBubble();
closeMapTitle();
-
+
mapTitle = new google.maps.InfoWindow({
content: template
});
-
+
mapTitle.open(map, this);
-
+
});
-
+
marker.addListener('mouseout', function() {
mapTitle.close();
});
-
+
// Add a click listener for this marker
marker.addListener('click', function() {
-
+
var infotext = '<h4 style="white-space: nowrap;">'+value.name+'</h4>';
var stateComma = '';
-
+
if (value.short_descr) {
infotext += '<p>'+value.short_descr+'</p>';
}
if (doDetailSection) {
$('#nearMe-detail').html(infotext);
}
-
+
if (doMapBubble) {
-
+
var zoomBefore = map.getZoom();
var centerBefore = map.getCenter();
// Close any other existing bubble or title.
-// closeMapBubble();
+ closeMapBubble();
closeMapTitle();
-
+
// Show a map info bubble for this marker
mapBubble = new google.maps.InfoWindow({
content: infotext
mapBubble.open(map, this);
mapBubble.addListener('closeclick', function() {
-
+
// If the map moved when displaying the map bubble, check POIs on close
if (map.getZoom() != zoomBefore || map.getCenter().lat() != centerBefore.lat() || map.getCenter().lng() != centerBefore.lng()) {
-map.panTo(centerBefore);
+ map.panTo(centerBefore);
checkNewPOIs();
}
});
}
-
+
});
- // Save this marker to our markers array
+ // Save this marker to our markers array
markers[marker.id] = marker;
// Also if this marker type is turned on, add marker to Clusterer
// If there's a request to find things anywhere
if (request == 'anywhere' && Object.keys(markers).length) {
-
+
noProcessAfterZoom = true;
-
+
allBounds = new google.maps.LatLngBounds();
-
+
// Find the total extent of all current markers.
for (key in markers) {
allBounds.extend(markers[key].getPosition());
}
-
+
map.fitBounds(allBounds);
-
+
// Enforce minimum zoom
var zoom = map.getZoom();
if (zoom > maxAnywhereZoom) {
- map.setZoom(maxAnywhereZoom);
+ map.setZoom(maxAnywhereZoom);
}
-
+
saveCurrentBounds();
-
+
}
// Remove the loading message
hideLoadingMsg();
-
+
}
);
-
+
saveCurrentBounds();
-
+
}
// Save current bounds as last bounds
function saveCurrentBounds() {
if (trackToConsole) { console.log('GLM NearMe: Set Last Bounds'); }
-
+
lastLatMax = latMax;
lastLatMin = latMin;
lastLonMax = lonMax;
curCenter = map.getCenter();
}
-
-
+
+
// Handle tracking type selection
$('.glmMapMyLocationType').on('change', function() {
-
+
trackingType = $(this).val();
switch (trackingType) {
case 'track':
case 'set':
setMyLocationToManual();
break;
-
+
}
});
-
+
// Try HTML5 geolocation to get user's current location
function getUserLocation() {
-
+
if (trackToConsole) { console.log('GLM NearMe: getUserLocation()'); }
if (!canReadUserLocation) {
if (trackToConsole) { console.log('GLM NearMe: Aborting getUserLocation() - canReadUserLocation = false'); }
- return;
+ return;
}
-
+
stopGeolocation = false;
clearGeolocationTimers();
-
+
// Set timer to catch when user ignores postion request or selects Not Now or geolocation not available
getLocationIngoredTimer = window.setTimeout( function() {
setMyLocationToManual();
return;
}, postionTimeout);
-
-
+
+
// If we can get the user's location
if (navigator.geolocation) {
-
+
if (trackToConsole) { console.log('GLM NearMe: Processing Geolocation'); }
-
+
// Get the user's location
navigator.geolocation.getCurrentPosition(function(position) {
-
+
if (trackToConsole) { console.log('GLM NearMe: Have geolocation as '+position.coords.latitude+', '+position.coords.longitude); }
-
+
if (stopGeolocation) {
-
+
if (trackToConsole) { console.log('GLM NearMe: geolocation stopped'); }
-
+
clearGeolocationTimers();
return;
}
-
+
// Save their current location
myCurrentLocation = {
lat: position.coords.latitude,
canReadUserLocation = true;
window.clearTimeout(getLocationIngoredTimer);
geolocationFailCounter = 0;
-
+
// Set My Location to new lat/lon
myMarker.setPosition(myCurrentLocation);
-
+
// If current location is not on map, recenter map on location
if (!map.getBounds().contains(myMarker.getPosition())) {
- map.panTo(myCurrentLocation);
+ map.panTo(myCurrentLocation);
checkNewPOIs();
}
-
+
// If we can't get the location, then switch to manual
- },
+ },
function(err) {
- if (trackToConsole) { console.log('GLM NearMe: Geolocation error = ' + err.code + ': ' + err.message); }
+ if (trackToConsole) { console.log('GLM NearMe: Geolocation error = ' + err.code + ': ' + err.message); }
if (stopGeolocation) {
-
+
if (trackToConsole) { console.log('GLM NearMe: geolocation stopped'); }
-
+
clearGeolocationTimers();
return;
}
-
+
// Bump fail counter and check if we've reached the end of our patience.
if (++geolocationFailCounter == geolocationFailCount) {
-
+
if (trackToConsole) { console.log('GLM NearMe: Geolocation fail counter exceeded'); }
-
- setMyLocationToManual();
+
+ setMyLocationToManual();
} else {
-
+
if (trackToConsole) { console.log('GLM NearMe: Geolocation fail #'+(geolocationFailCounter-1)); }
-
+
// Start the get location timer again window.clearTimeout(trackingTimer);
trackingTimer = window.setTimeout(getUserLocation, trackPositionInterval);
}
-
- },
+
+ },
{
enableHighAccuracy: highAccuracyPoisition,
timeout: postionTimeout,
maximumAge: trackPositionInterval - 100 // Allows cached position resulting from other requests during interval
-
+
});
-
+
}
}
function setMyLocationToTrack() {
-
+
stopGeolocation = false;
canReadUserLocation = true;
getUserLocation();
$('#glmMapSetMyLocation').addClass('glm-hidden');
-
+
}
function clearGeolocationTimers() {
window.clearTimeout(trackingTimer);
window.clearTimeout(getLocationIngoredTimer);
}
-
+
function setMyLocationToManual() {
-
+
if (trackToConsole) { console.log('GLM NearMe: My Location set to manual'); }
-
+
stopGeolocation = true;
clearGeolocationTimers();
// Dissable tracking and change tracking radio buttons to 'set'
canReadUserLocation = false;
trackingType = 'set';
- $('#glmMyLocationSet').prop('checked', true);
+ $('#glmMyLocationSet').prop('checked', true);
// Let user know that we're doing this.
alert('Your "My Location" setting has been changed to "Manual Map Selection".'+"\n\n"
+'You either selected "Manual Map Selection" or your are doing a search with "Anywhere" selected.'+"\n\n"
+'You may use the "Set My Location Here" button to select the center of the current map as your "My Location" and return to that location as desired.'+"\n\n"
+'You may return to automatically tracking your location by selecting "Follow Me" at any time.');
-
+
$('#glmMapSetMyLocation').removeClass('glm-hidden');
}
function hideLoadingMsg() {
$('#glmMapReload').addClass('glm-hidden');
}
-
+
function closeMapBubble() {
if (mapBubble) {
-// mapBubble.close();
+ mapBubble.close();
}
}
function closeMapTitle() {
// Get it all started
initMap();
-
+
}); // jquery
-
- (function($) { $.fn.catchEnter = function(sel) {
- return this.each(function() {
+
+ (function($) { $.fn.catchEnter = function(sel) {
+ return this.each(function() {
$(this).on('keyup',sel,function(e){
if(e.keyCode == 13)
$(this).trigger("enterkey");
})
- });
+ });
};
})(jQuery);
-
+
</script>
-{include file='front/footer.html'}
\ No newline at end of file
+{include file='front/footer.html'}
\ No newline at end of file