From c9b174b1e367fc1f5f0ccafb5d3e098b2cb998c3 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Mon, 20 Aug 2018 14:30:56 -0400 Subject: [PATCH] Fixed View/Hide map not working and double name on map bubble --- views/front/members/list.html | 307 ++++++++++++++++++---------------- 1 file changed, 162 insertions(+), 145 deletions(-) diff --git a/views/front/members/list.html b/views/front/members/list.html index 4a369f48..e84bcac7 100755 --- a/views/front/members/list.html +++ b/views/front/members/list.html @@ -518,7 +518,7 @@ }); {/if} // settings.list_show_search - {if $settings.list_show_map} + {if $settings.list_show_map} /* * Map operations @@ -534,67 +534,68 @@ * Leaflet Map * API reference: https://leafletjs.com/reference-1.3.2.html */ - - 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 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} + function initMap() { -// var markerGroup = L.featureGroup(); - var markerGroup = L.markerClusterGroup({ - maxClusterRadius: 40 - }); - - {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('{$m.member_name|escape:quotes}
' + $('#map_info_' + {$m.id}).html()) - .addTo(markerGroup); - -// markers.addLayer(leafletMarker); - + 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 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} + + var markerGroup = L.markerClusterGroup({ + maxClusterRadius: 40 + }); + + {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. + {/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 }); + }); + - 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} /* @@ -602,18 +603,16 @@ * 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'), { - center: new google.maps.LatLng({$settings.maps_default_lat}, {$settings.maps_default_lon}), - zoom: {$settings.maps_default_zoom}, - disableDefaultUI: false, - mapTypeId: google.maps.MapTypeId.MAP, - }); + // Create a Google Map object + var map = new google.maps.Map(document.getElementById('glm-locationMap'), { + center: new google.maps.LatLng({$settings.maps_default_lat}, {$settings.maps_default_lon}), + zoom: {$settings.maps_default_zoom}, + disableDefaultUI: false, + mapTypeId: google.maps.MapTypeId.MAP, + }); - $("#glm-member-list-map-toggle").click( function() { - $(".glm-member-db-{$view}-view").toggleClass("map-opened"); - $(".glm-member-db-{$view}-view").toggleClass("map-closed"); var center = map.getCenter(); google.maps.event.trigger(map, "resize"); map.setCenter(center); @@ -629,89 +628,91 @@ $('body,html').animate({ 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(); + } - // Don't Try HTML5 to get user geolocation - //if(navigator.geolocation) { - //navigator.geolocation.getCurrentPosition(function(position) { - //var 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 + var geocoder = new google.maps.Geocoder(); + var bounds = new google.maps.LatLngBounds(); + var infowindow = new google.maps.InfoWindow(); + + // Don't Try HTML5 to get user geolocation + //if(navigator.geolocation) { + //navigator.geolocation.getCurrentPosition(function(position) { + //var 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 + //}); //}); - //}); - //} + //} + + {if $mapItems} + var markers = []; + {foreach $mapItems as $m} + {if $m.lat != 0 && $m.lon != 0} + + // Create a marker for this member + var marker = new google.maps.Marker({ + map: map, + position: new google.maps.LatLng({$m.lat}, {$m.lon}), + draggable: false, + animation: google.maps.Animation.DROP, + title: '{$m.member_name|escape:quotes}', + descr: $('#map_info_' + {$m.id}).html(), + memberID: {$m.member} + }); + + // Add a click listener for this marker + marker.addListener('click', function() { + infowindow.setOptions({ + content: this.descr + }); + infowindow.open(map,this); + }); + + markers.push(marker); + + // Extend the map bounds to include this marker + bounds.extend(marker.position); + + {/if} + {/foreach} + + {if $settings.use_cluster_markers} + var markerCluster = new MarkerClusterer(map, markers, + { + imagePath: '{$baseUrl}/js/googleMapsMarkerClusterer/images/m', + gridSize: 30, + maxZoom: 14, + minimunClusterSize: 3 + }); + {/if} + + // Fit map to bounds of all markers + map.fitBounds(bounds); + + // Check for first map idle (completely loaded) - Check max zoom + var mapLoadedListener = google.maps.event.addListener(map, 'idle', function() { + if (map.getZoom() > 14) { + this.setZoom(14); + } + google.maps.event.removeListener(mapLoadedListener); + }); - {if $mapItems} - var markers = []; - {foreach $mapItems as $m} - {if $m.lat != 0 && $m.lon != 0} - - // Create a marker for this member - var marker = new google.maps.Marker({ - map: map, - position: new google.maps.LatLng({$m.lat}, {$m.lon}), - draggable: false, - animation: google.maps.Animation.DROP, - title: '{$m.member_name|escape:quotes}', - descr: $('#map_info_' + {$m.id}).html(), - memberID: {$m.member} - }); - - // Add a click listener for this marker - marker.addListener('click', function() { - infowindow.setOptions({ - content: this.descr - }); - infowindow.open(map,this); - }); - - markers.push(marker); - - // Extend the map bounds to include this marker - bounds.extend(marker.position); - - {/if} - {/foreach} - - {if $settings.use_cluster_markers} - var markerCluster = new MarkerClusterer(map, markers, - { - imagePath: '{$baseUrl}/js/googleMapsMarkerClusterer/images/m', - gridSize: 30, - maxZoom: 14, - minimunClusterSize: 3 - }); - {/if} - - // Fit map to bounds of all markers - map.fitBounds(bounds); - - // Check for first map idle (completely loaded) - Check max zoom - var mapLoadedListener = google.maps.event.addListener(map, 'idle', function() { - if (map.getZoom() > 14) { - this.setZoom(14); - } - google.maps.event.removeListener(mapLoadedListener); - }); - + } // initMap + {else} @@ -721,6 +722,22 @@ {/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() { -- 2.17.1