From: Steve Sutton Date: Thu, 23 Aug 2018 14:43:31 +0000 (-0400) Subject: Updating for the new maps X-Git-Tag: v1.0.15^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=a909904c1f2f3e98f7a585741df800c6fd8464ba;p=WP-Themes%2Fmichigantrailmaps.git Updating for the new maps using leaflet and our tile server. --- diff --git a/glm-member-db/views/front/members/detail.html b/glm-member-db/views/front/members/detail.html index 65b258b..7c9f498 100644 --- a/glm-member-db/views/front/members/detail.html +++ b/glm-member-db/views/front/members/detail.html @@ -214,11 +214,22 @@ {if $settings.detail_show_map} - +
-
(map loads here)
+ {if $settings.selected_map_interface == 1} + + + + +
(map loads here)
+ {/if} + {if $settings.selected_map_interface == 2} + + +
(map loads here)
+ {/if}
-
view location
+
view map
@@ -687,6 +698,55 @@ $(this).html(mapBtnTxt); }); + {if $settings.selected_map_interface == 1} + + /* + * Leaflet Map + * API reference: https://leafletjs.com/reference-1.3.2.html + */ + + // Get member location if available, otherwise use this site's default locatgion + var myLocation = false; + {if $member.lat != 0 && $member.lon != 0} + var memberLat = {$member.lat}; + var memberLon = {$member.lon}; + {else} + var memberLat = {$settings.maps_default_lat}}; + var memberLon = {$settings.maps_default_lon}}; + {/if} + + function initMap() { + + var leafletMap = L.map('LeafletMapContainer').setView([memberLat, memberLon], {$settings.maps_default_zoom}); + var leafletTileServer = '{$settings.leaflet_tile_server}/{$settings.leaflet_tile_server_key}/' + {literal}'{z}/{x}/{y}.png'{/literal}; + var leafletMinZoom = 5; + var leafletMaxZoom = 18; + var geocoder; + + + // Tile server + L.tileLayer(leafletTileServer, { + attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Gaslight Media', + minZoom: leafletMinZoom, + maxZoom: leafletMaxZoom, + id: 'nothot' + }).addTo(leafletMap); + + var loadingControl = L.Control.loading({ + separate: true, + delayIndicator: 500 + }); + leafletMap.addControl(loadingControl); + + // Marker + var leafletMarker = L.marker([memberLat, memberLon]).addTo(leafletMap); + + } + + {/if} + + {if $settings.selected_map_interface == 2} + /* * Google Maps * API reference: https://developers.google.com/maps/documentation/javascript/reference @@ -719,119 +779,19 @@ title: '{$member.member|escape}' }); {/if} - // Don't Try HTML5 to get user geolocation - //if(navigator.geolocation) { - //navigator.geolocation.getCurrentPosition(function(position) { - //myLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); - //var pinIcon = new google.maps.MarkerImage( - //'https://maps.google.com/mapfiles/kml/shapes/man.png', - //null, /* size is determined at runtime */ - //null, /* origin is 0,0 */ - //null, /* anchor is bottom center of the scaled image */ - //new google.maps.Size(30, 30) - //); - //var myMarker = new google.maps.Marker({ - //map: map, - //position: myLocation, - //draggable: false, - //animation: google.maps.Animation.DROP, - //title: 'My Location', - //icon: pinIcon, - //zIndex: 100 - //}); - //$('#glm-startLocation').attr('placeholder', 'Leave blank for your current location or enter address here.'); - //}); - //} } // Load map google.maps.event.addDomListener(window, 'load', initMap); + {/if} {/if} {*detail_show_map*} -// Direction code is below, but since we're sending them offsite to google maps this is no longer necessary. -// -// {if $settings.detail_show_directions} -// -// var directionsDisplay; -// var directionsService = new google.maps.DirectionsService(); -// -// // Display map with route from specified location to member location -// function calcRoute() { -// -// // If an address was input, use that, otherwise use detected location if available -// var start = $('#glm-startLocation').val(); -// if (start == '' ) { -// if (myLocation != false) { -// start = myLocation; -// } -// } -// -// // If no start location available, tell user -// if (start == '') { -// alert('No starting location. Please enter address.'); -// return; -// } -// -// // Switch to directions map being visible -// $('#glm-directionsMap-container').removeClass('glm-hidden'); -// $('#glm-locationMap-container').addClass('glm-hidden'); -// $('#glm-showLocationButton').removeClass('glm-hidden'); -// -// // Initialize the directions map with a default center location -// directionsDisplay = new google.maps.DirectionsRenderer(); -// var mapOptions = { -// zoom:7, -// center: memberlocation -// } -// directionsMap = new google.maps.Map(document.getElementById("glm-directionsMap"), mapOptions); -// directionsDisplay.setMap(directionsMap); -// -// // Get directions type selected -// var directionsType = $('#directionsType').find(':selected').val(); -// -// // Specify origin and destination then get route -// var request = { -// origin: start, -// destination: memberlocation, -// travelMode: google.maps.TravelMode[directionsType] -// }; -// directionsService.route(request, function(result, status) { -// if (status == google.maps.DirectionsStatus.OK) { -// directionsDisplay.setDirections(result); -// $('#directions-panel').html(''); -// directionsDisplay.setPanel(document.getElementById('directions-panel')); -// } -// }); -// -// // Check for first map idle (completely loaded) - Check max initial zoom -// var mapLoadedListener = google.maps.event.addListener(directionsMap, 'idle', function() { -// if (directionsMap.getZoom() > 16) { -// this.setZoom(16); -// } -// google.maps.event.removeListener(mapLoadedListener); -// }); -// -// } -// -// // Trigger route map either by button or input of address -// $('#glm-showDirectionsButton' ).click( function() { -// calcRoute(); -// }); -// $('#glm-startLocation' ).change( function() { -// calcRoute(); -// }); -// -// // Switch back to member location map -// $('#glm-showLocationButton').click( function() { -// $('#glm-directionsMap-container').addClass('glm-hidden'); -// $('#glm-locationMap-container').removeClass('glm-hidden'); -// $('#glm-showLocationButton').addClass('glm-hidden'); -// }); -// -// {/if} {*detail_show_directions*} + $(window).load(function(){ + initMap(); + }); }); // jquery diff --git a/glm-member-db/views/front/members/list.html b/glm-member-db/views/front/members/list.html index 3db21ce..0b75ade 100644 --- a/glm-member-db/views/front/members/list.html +++ b/glm-member-db/views/front/members/list.html @@ -45,6 +45,23 @@ Search Terms: {$selected_region = $smarty.request.regionUserSearch[0]} {/if} + {if $settings.selected_map_interface == 1} + + + + + + + + {/if} + + {if $settings.selected_map_interface == 2} + + + {/if} + + + {include file='front/members/header.html'} {apply_filters('glm-member-db-front-members-list-pageTop', '')}
@@ -142,10 +159,20 @@ Search Terms: {/if} {*list_show_search*} {if $settings.list_show_map} - + {apply_filters('glm-member-db-front-members-list-mapTop', '')}
+ + {if $settings.selected_map_interface == 1} + +
+ {/if} + + {if $settings.selected_map_interface == 2} +
(map loads here)
+ {/if} +
{apply_filters('glm-member-db-front-members-list-mapBottom', '')} {/if} @@ -637,11 +664,99 @@ Search Terms: {/if} // settings.list_show_search {if $settings.list_show_map} + + /* + * Map operations + */ + + var startLat = $('#glmLat').val(); + var startLon = $('#glmLng').val(); + var defZoom = Number({$settings.maps_default_zoom}); + + {if $settings.selected_map_interface == 1} + + /* + * Leaflet Map + * API reference: https://leafletjs.com/reference-1.3.2.html + */ + + function initMap() { + + var leafletMap = L.map('LeafletMapContainer').setView([{$settings.maps_default_lat}, {$settings.maps_default_lon}], defZoom); + var leafletTileServer = '{$settings.leaflet_tile_server}/{$settings.leaflet_tile_server_key}/' + {literal}'{z}/{x}/{y}.png'{/literal}; + var leafletMinZoom = 3; + var leafletMaxZoom = 19; + var clusterRadiusMax = 40; + var geocoder; + + // Loading features + var loadingControl = L.Control.loading({ + separate: true, + delayIndicator: 500 + }); + leafletMap.addControl(loadingControl); + + // Init Map + L.tileLayer(leafletTileServer, { + attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Gaslight Media', + minZoom: leafletMinZoom, + maxZoom: leafletMaxZoom, + id: 'nothot' + }).addTo(leafletMap); + + + {if $mapItems} + + {if $settings.use_cluster_markers} + var markerGroup = L.markerClusterGroup({ + maxClusterRadius: clusterRadiusMax + }); + {else} + var markerGroup = L.featureGroup({ + maxClusterRadius: clusterRadiusMax + }); + {/if} + + + {foreach $mapItems as $m} + {if $m.lat != 0 && $m.lon != 0} + + // Create marker for this member and and to Feature Group + var leafletMarker = L.marker([{$m.lat}, {$m.lon}], { title: '{$m.member_name|escape:quotes}' }) + .bindPopup($('#map_info_' + {$m.id}).html()) + .addTo(markerGroup); + + {/if} + {/foreach} + + leafletMap.addLayer(markerGroup); + + // Get outer bounds of all markers in the Feature Group + leafletMap.fitBounds(markerGroup.getBounds()); + + {/if} // havemembers + + // When a marker is clicked, display the pop-up near the center of the map. + + leafletMap.on('popupopen', function(e) { + var px = leafletMap.project(e.popup._latlng); + px.y -= e.popup._container.clientHeight/2; + leafletMap.panTo(leafletMap.unproject(px),{ animate: true }); + }); + + + } + + {/if} + + {if $settings.selected_map_interface == 2} + /* * Google Maps * API reference: https://developers.google.com/maps/documentation/javascript/reference */ + function initMap() { // Create a Google Map object var map = new google.maps.Map(document.getElementById('glm-locationMap'), { @@ -670,7 +785,7 @@ Search Terms: scrollTop: $("#glm-locationMap-container").offset().top-100 }, 400); } - }); + var geocoder = new google.maps.Geocoder(); var bounds = new google.maps.LatLngBounds(); var infowindow = new google.maps.InfoWindow(); @@ -752,14 +867,33 @@ Search Terms: google.maps.event.removeListener(mapLoadedListener); }); + } // initMap + {else} {/if} // havemembers + {/if} {/if} // settings.list_show_map + // Handle Map View/Hide + var mapInitialized = false; + $("#glm-member-list-map-toggle").click( function() { + $(".glm-member-db-{$view}-view").toggleClass("map-opened"); + $(".glm-member-db-{$view}-view").toggleClass("map-closed"); + if (!mapInitialized) { + initMap(); + mapInitialized = true; + } + }); + {if $settings.list_map_show_opened} + // Start with map opened + initMap(); + mapInitialized = true; + {/if} + // Processes click-through counts for website links $('.glm-member-list-website-link').on('click', function() {