if (Fse == undefined) { var Fse = {}; } var _accountMap = undefined; // global var so that we can reference map object and change attributes after the fact Fse.getDirections = function(mapSocket,lat,lng,destAddress) { var acctDirectionsService = new google.maps.DirectionsService(); var acctDirectionsDisplay = new google.maps.DirectionsRenderer(); if (mapSocket) { var acctMap = new google.maps.Map(document.getElementById(mapSocket)); acctDirectionsDisplay.setMap(acctMap); } // was originally pushing directions steps up to parent div, but they end up unstyled when // not in same document page as call. This step is done in parent now and hope we don't have // memory issues as a result. //acctDirectionsDisplay.setPanel(parent.document.getElementById(dirSocket)); var request = { origin: new google.maps.LatLng(lat,lng), destination: destAddress, travelMode: google.maps.TravelMode.DRIVING }; acctDirectionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { acctDirectionsDisplay.setDirections(response); } else { alert("Unable to get directions at this time: " + status); } }); } Fse.mapAddress = function(addressString, lat, long, zipcode, mapSocket, mapPlaces, locName ) { if (lat && long && lat != '0' && long != '0' ) { /* lat and long passed */ var _latLng = new google.maps.LatLng(lat, long); var mapOptions = { zoom:14, mapTypeId: google.maps.MapTypeId.ROADMAP, center: _latLng, gestureHandling: 'cooperative', zoomControl: false, streetViewControl: false, mapTypeControl: false } //var acctMap = new google.maps.Map(document.getElementById(mapSocket), mapOptions); _accountMap = new google.maps.Map(document.getElementById(mapSocket), mapOptions); var marker = new google.maps.Marker({ position: _latLng, map: _accountMap, title:"" }); //var infowindow = new google.maps.InfoWindow({ // content: "" //}); //Fse.bindInfoWindow(marker, _accountMap, infowindow, 'This Account'); Fse.mapNearBy( _accountMap, mapPlaces ); } else { /* use address, no lat and long passed in */ var geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': addressString }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { mapOptions = { zoom:14, mapTypeId: google.maps.MapTypeId.ROADMAP, center: results[0].geometry.location, gestureHandling: 'cooperative', zoomControl: false, streetViewControl: false, mapTypeControl: false } _accountMap = new google.maps.Map(document.getElementById(mapSocket), mapOptions); marker = new google.maps.Marker({ position: results[0].geometry.location, map: _accountMap, title:"" }); //var infowindow = new google.maps.InfoWindow({ // content: "" //}); //Fse.bindInfoWindow(marker, _accountMap, infowindow, 'This Account'); Fse.mapNearBy( _accountMap, mapPlaces ); } else { alert("Unable to locate address at this time: " + status); } }); } } Fse.setAccountMapOptions = function(mapOptions) { _accountMap.setOptions(mapOptions); } Fse.mapNearBy = function(acctMap,mapPlaces) { if (!mapPlaces || mapPlaces == '' || mapPlaces == '[none]') { return false; } var _places = JSON.parse( decodeURIComponent(mapPlaces) ); var infowindow = new google.maps.InfoWindow({ content: "" }); const element = document.getElementById('chartApiURL'); const chartApiURLBase = element.getAttribute('href'); for (var i = 0; i < _places.length; i++) { var place = _places[i]; var myLatLng = new google.maps.LatLng(place[1], place[2]); var iconURL = chartApiURLBase + '&chld=' + place[4] + '|' + place[5] var marker = new google.maps.Marker({ position: myLatLng, map: acctMap, icon: iconURL, title: '', zIndex: place[3] }); Fse.bindInfoWindow(marker, acctMap, infowindow, place[0]); } } Fse.bindInfoWindow = function(marker, acctMap, infowindow, strDescription) { google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(strDescription); infowindow.open(acctMap, marker); }); }