var mgr = null; var map = null; var sortedMarkers = {}; var markers = [], currentlyOpenedInfoWindow = null; /* -- function mapInitialize() ----------------------------------------------------------------- ** ** -- Initializes a Google Maps object, with static options, for the Plots data ** ** ---------------------------------------------------------------------------------------------- */ function mapInitialize( container_id ) { /* Initialize the map ----------------------------------------------------------------------- */ var myLatLng = new google.maps.LatLng(41.403603771647,-90.21230421660); var myOptions = { zoom: 10, center: myLatLng, panControl: true, streetViewControl: false, mapTypeControl: false, minZoom: 5, // limit zooming out and zooming in, maxZoom: 12, // to avoid straining the quality of the overlay noClear: true }; map = new google.maps.Map(document.getElementById( container_id ), myOptions); google.maps.event.addListenerOnce(map, 'tilesloaded', function() {callMarkers();}); google.maps.event.addListener(map, "click", function () { if (currentlyOpenedInfoWindow != null) currentlyOpenedInfoWindow.close(); }); } function callMarkers() { var $prev_lat = 0, $prev_lng = 0; $('.trial-marker').each(function(i,item){ var lat = $(this).attr('data-lat'); var lng = $(this).attr('data-lon'); var mytitle = $(this).find('h4:first').text(); var $num = (i+1).toString(); var mIcon = { path: google.maps.SymbolPath.CIRCLE, fillOpacity: 1, fillColor: '#ffc325', strokeOpacity: 1, strokeWeight: 1, strokeColor: '#333', scale: 12 }; var $contentDiv = $(this).clone(); $($contentDiv).find('.row').addClass('no-gutters'); var $contentString = $($contentDiv).html() ; var $infowindow = new google.maps.InfoWindow({ content: $contentString }); if ( lat == $prev_lat && lng == $prev_lng){ lat = parseFloat(lat) + .005; lng = parseFloat(lng) + .005; } $prev_lat = lat.toString(); $prev_lng = lng.toString(); var myLatLng = new google.maps.LatLng(lat, lng); var marker = new google.maps.Marker({ position: myLatLng, title: mytitle, map: map, icon: mIcon, label: {color: '#000', fontSize: '12px', fontWeight: '600',text: $num}, }); if (i == 0){map.setCenter(myLatLng);} marker.addListener('click', function() { if (currentlyOpenedInfoWindow != null) currentlyOpenedInfoWindow.close(); $infowindow.open(map, marker); currentlyOpenedInfoWindow = $infowindow; }); markers.push(marker); }); } /* -- HELPER FUNCTIONS FOR MAPS ----------------------------------------------------------------- */ // Create an overlay on the map from a projected image - Maps v3... // Author. John D. Coryat 05/2009 // USNaviguide LLC - http://www.usnaviguide.com // Thanks go to Mile Williams EInsert: http://econym.googlepages.com/einsert.js, Google's GOverlay Example and Bratliff's suggestion... // Opacity code from TPhoto: http://gmaps.tommangan.us/addtphoto.html // This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. // // Parameters: // map: This Map // imageUrl: URL of the image (Mandatory) // bounds: Bounds object of image destination (Mandatory) // Options: // addZoom: Added Zoom factor as a parameter to the imageUrl (include complete parameter, including separater like '?zoom=' // percentOpacity: Default 50, percent opacity to use when the image is loaded 0-100. // id: Default imageUrl, ID of the div // function ProjectedOverlay(map, imageUrl, bounds, opts) { google.maps.OverlayView.call(this); this.map_ = map; this.url_ = imageUrl ; this.bounds_ = bounds ; this.addZ_ = opts.addZoom || '' ; // Add the zoom to the image as a parameter this.id_ = opts.id || this.url_ ; // Added to allow for multiple images this.percentOpacity_ = opts.percentOpacity || 100 ; this.setMap(map); } ProjectedOverlay.prototype = new google.maps.OverlayView(); ProjectedOverlay.prototype.createElement = function() { var panes = this.getPanes() ; var div = this.div_ ; if (!div) { div = this.div_ = document.createElement("div"); div.style.position = "absolute" ; div.setAttribute('id',this.id_) ; this.div_ = div ; this.lastZoom_ = -1 ; if( this.percentOpacity_ ) { this.setOpacity(this.percentOpacity_) ; } panes.overlayLayer.appendChild(div); } } // Remove the main DIV from the map pane ProjectedOverlay.prototype.remove = function() { if (this.div_) { this.setMap(null); this.div_.parentNode.removeChild(this.div_); this.div_ = null; } } // Redraw based on the current projection and zoom level... ProjectedOverlay.prototype.draw = function(firstTime) { // Creates the element if it doesn't exist already. this.createElement(); if (!this.div_) { return ; } var c1 = this.get('projection').fromLatLngToDivPixel(this.bounds_.getSouthWest()); var c2 = this.get('projection').fromLatLngToDivPixel(this.bounds_.getNorthEast()); if (!c1 || !c2) return; // Now position our DIV based on the DIV coordinates of our bounds this.div_.style.width = Math.abs(c2.x - c1.x) + "px"; this.div_.style.height = Math.abs(c2.y - c1.y) + "px"; this.div_.style.left = Math.min(c2.x, c1.x) + "px"; this.div_.style.top = Math.min(c2.y, c1.y) + "px"; // Do the rest only if the zoom has changed... if ( this.lastZoom_ == this.map_.getZoom() ) { return ; } this.lastZoom_ = this.map_.getZoom() ; var url = this.url_ ; if ( this.addZ_ ) { url += this.addZ_ + this.map_.getZoom() ; } this.div_.innerHTML = '' ; } ProjectedOverlay.prototype.setOpacity=function(opacity) { if (opacity < 0) { opacity = 0 ; } if(opacity > 100) { opacity = 100 ; } var c = opacity/100 ; if (typeof(this.div_.style.filter) =='string') { this.div_.style.filter = 'alpha(opacity:' + opacity + ')' ; } if (typeof(this.div_.style.KHTMLOpacity) == 'string' ) { this.div_.style.KHTMLOpacity = c ; } if (typeof(this.div_.style.MozOpacity) == 'string') { this.div_.style.MozOpacity = c ; } if (typeof(this.div_.style.opacity) == 'string') { this.div_.style.opacity = c ; } } function overlayAdd() { var sw = new google.maps.LatLng(25,-126) ; var ne = new google.maps.LatLng(50,-66) ; var bounds = new google.maps.LatLngBounds(sw,ne) ; overlay = new ProjectedOverlay(map, EEGLOBAL.mysite + '/assets/img/us_counties_projected.png', bounds, {}) ; } /* -- function ^checkBounds(allowedBounds LatLng , map Object) ------------------------------ ** ** -- Checks the bounds of the passsed-in map, and disallows panning past them. ** ** ------------------------------------------------------------------------------------------ */ function checkBounds(allowedBounds,map) { if(!allowedBounds.contains(map.getCenter())) { var C = map.getCenter(); var X = C.lng(); var Y = C.lat(); var AmaxX = allowedBounds.getNorthEast().lng(); var AmaxY = allowedBounds.getNorthEast().lat(); var AminX = allowedBounds.getSouthWest().lng(); var AminY = allowedBounds.getSouthWest().lat(); if (X < AminX) {X = AminX;} if (X > AmaxX) {X = AmaxX;} if (Y < AminY) {Y = AminY;} if (Y > AmaxY) {Y = AmaxY;} map.setCenter(new google.maps.LatLng(Y,X)); } } function getVisibleMarkers() { var visibleGroups = []; for (var id in sortedMarkers) { var group = sortedMarkers[id]; if ( ! group.hidden) {visibleGroups.push(group);} } return visibleGroups; }