// JavaScript Document //////// markerwithlabel /** * google-maps-utility-library-v3-markerwithlabel * * @version: 1.1.10 * @author: Gary Little (inspired by code from Marc Ridey of Google). * @contributors: Nicholas McCready * @date: Fri May 13 2016 16:29:58 GMT-0400 (EDT) * @license: Apache License 2.0 */ function inherits(e,t){function s(){}s.prototype=t.prototype,e.superClass_=t.prototype,e.prototype=new s,e.prototype.constructor=e}function MarkerLabel_(e,t){this.marker_=e,this.labelDiv_=document.createElement("div"),this.labelDiv_.style.cssText="position: absolute; overflow: hidden;",this.eventDiv_=document.createElement("div"),this.eventDiv_.style.cssText=this.labelDiv_.style.cssText,this.eventDiv_.setAttribute("onselectstart","return false;"),this.eventDiv_.setAttribute("ondragstart","return false;"),this.crossDiv_=MarkerLabel_.getSharedCross(t)}function MarkerWithLabel(e){(e=e||{}).labelContent=e.labelContent||"",e.labelAnchor=e.labelAnchor||new google.maps.Point(0,0),e.labelClass=e.labelClass||"markerLabels",e.labelStyle=e.labelStyle||{},e.labelInBackground=e.labelInBackground||!1,void 0===e.labelVisible&&(e.labelVisible=!0),void 0===e.crossOnDrag&&(e.crossOnDrag=!0),void 0===e.clickable&&(e.clickable=!0),void 0===e.draggable&&(e.draggable=!1),void 0===e.optimized&&(e.optimized=!1),e.crossImage=e.crossImage||"//maps.gstatic.com/intl/en_us/mapfiles/drag_cross_67_16.png",e.optimized=!1,this.label=new MarkerLabel_(this,e.crossImage),google.maps.Marker.apply(this,arguments)}inherits(MarkerLabel_,google.maps.OverlayView),MarkerLabel_.getSharedCross=function(e){var t;return void 0===MarkerLabel_.getSharedCross.crossDiv&&((t=document.createElement("img")).style.cssText="position: absolute; z-index: 1000002; display: none;",t.style.marginLeft="-8px",t.style.marginTop="-9px",t.src=e,MarkerLabel_.getSharedCross.crossDiv=t),MarkerLabel_.getSharedCross.crossDiv},MarkerLabel_.prototype.onAdd=function(){var e=this;this.getPanes().markerLayer.appendChild(this.labelDiv_),this.getPanes().overlayMouseTarget.appendChild(this.eventDiv_),void 0===MarkerLabel_.getSharedCross.processed&&(this.getPanes().overlayImage.appendChild(this.crossDiv_),MarkerLabel_.getSharedCross.processed=!0),this.addMouseListeners(),this.listeners2_=[google.maps.event.addListener(this.marker_,"clickable_changed",function(){e.setClickable()}),google.maps.event.addListener(this.marker_,"cursor_changed",function(){e.setCursor()}),google.maps.event.addListener(this.marker_,"draggable_changed",function(){e.setClickable()}),google.maps.event.addListener(this.marker_,"position_changed",function(){e.setPosition()}),google.maps.event.addListener(this.marker_,"visible_changed",function(){e.setVisible()}),google.maps.event.addListener(this.marker_,"title_changed",function(){e.setTitle()}),google.maps.event.addListener(this.marker_,"zindex_changed",function(){e.setZIndex()}),google.maps.event.addListener(this.marker_,"labelanchor_changed",function(){e.setAnchor()}),google.maps.event.addListener(this.marker_,"labelclass_changed",function(){e.setStyles()}),google.maps.event.addListener(this.marker_,"labelcontent_changed",function(){e.setContent()}),google.maps.event.addListener(this.marker_,"labelstyle_changed",function(){e.setStyles()}),google.maps.event.addListener(this.marker_,"labelvisible_changed",function(){e.setVisible()})]},MarkerLabel_.prototype.addMouseListeners=function(){var e,t,s,i=this,a=!1,r=!1,l=!1,o=function(e){(e=e||window.event).stopPropagation?e.stopPropagation():e.cancelBubble=!0,e.preventDefault?e.preventDefault():e.returnValue=!1},n=function(e){(e=e||window.event).stopPropagation?e.stopPropagation():e.cancelBubble=!0};this.listeners1_=[google.maps.event.addDomListener(this.eventDiv_,"mouseover",function(e){var t={latLng:i.marker_.getPosition()};i.marker_.getClickable()||i.marker_.getDraggable()?a||(this.style.cursor=i.marker_.getCursor()||"pointer",google.maps.event.trigger(i.marker_,"mouseover",t),o(e)):this.style.cursor=null}),google.maps.event.addDomListener(this.eventDiv_,"mouseout",function(e){var t={latLng:i.marker_.getPosition()};(i.marker_.getClickable()||i.marker_.getDraggable())&&(a||(google.maps.event.trigger(i.marker_,"mouseout",t),o(e)))}),google.maps.event.addDomListener(this.eventDiv_,"mousedown",function(e){var t={latLng:i.marker_.getPosition()};l=!1,(i.marker_.getClickable()||i.marker_.getDraggable())&&(r=!0,google.maps.event.trigger(i.marker_,"mousedown",t),a||o(e))}),google.maps.event.addDomListener(this.eventDiv_,"mouseup",function(t){var s={latLng:i.marker_.getPosition()};r&&(r=!1,google.maps.event.trigger(i.marker_,"mouseup",s),l&&(l=!1,i.crossDiv_.style.display="none",e=!0,google.maps.event.trigger(i.marker_,"dragend",s)),i.marker_.getDraggable()||o(t))}),google.maps.event.addDomListener(this.eventDiv_,"click",function(t){var s={latLng:i.marker_.getPosition()};(i.marker_.getClickable()||i.marker_.getDraggable())&&(e?e=!1:google.maps.event.trigger(i.marker_,"click",s),o(t))}),google.maps.event.addDomListener(this.eventDiv_,"dblclick",function(e){var t={latLng:i.marker_.getPosition()};(i.marker_.getClickable()||i.marker_.getDraggable())&&(google.maps.event.trigger(i.marker_,"dblclick",t),o(e))}),google.maps.event.addListener(this.marker_.getMap(),"mousemove",function(e){var a;r&&i.marker_.getDraggable()&&(l?(e.latLng=new google.maps.LatLng(e.latLng.lat()-t,e.latLng.lng()-s),i.marker_.get("crossOnDrag")&&(a=i.getProjection().fromLatLngToDivPixel(e.latLng),i.crossDiv_.style.left=a.x+"px",i.crossDiv_.style.top=a.y+"px",i.crossDiv_.style.display=""),google.maps.event.trigger(i.marker_,"drag",e)):(t=e.latLng.lat()-i.marker_.getPosition().lat(),s=e.latLng.lng()-i.marker_.getPosition().lng(),l=!0,e.latLng=i.marker_.getPosition(),google.maps.event.trigger(i.marker_,"dragstart",e)))}),google.maps.event.addListener(this.marker_,"dragstart",function(e){i.labelDiv_.style.zIndex=1e6+(this.get("labelInBackground")?-1:1),i.eventDiv_.style.zIndex=i.labelDiv_.style.zIndex}),google.maps.event.addListener(this.marker_,"drag",function(e){this.setPosition(e.latLng)}),google.maps.event.addListener(this.marker_,"dragend",function(e){i.setZIndex()}),google.maps.event.addDomListener(this.eventDiv_,"touchstart",function(e){a=!0,n(e)}),google.maps.event.addDomListener(this.eventDiv_,"touchmove",function(e){n(e)}),google.maps.event.addDomListener(this.eventDiv_,"touchend",function(e){n(e)})]},MarkerLabel_.prototype.removeMouseListeners=function(){var e;if(this.listeners1_)for(e=0;e= 1000) { formattedPrice = formattedPrice / 1000; formattedPrice = '$' + Math.round( formattedPrice ) + 'k'; } else { formattedPrice = '$' + formattedPrice; } return formattedPrice; } function getProperties() { $('.mls-loading').addClass('show'); var theBounds = theMap.getBounds(); /// set the lat/lng in the form fields $('input[name="minLat"]').val(theBounds.toJSON().south); $('input[name="maxLat"]').val(theBounds.toJSON().north); $('input[name="minLng"]').val(theBounds.toJSON().west); $('input[name="maxLng"]').val(theBounds.toJSON().east); //console.log( $("#mlsMapForm").serialize() ); var url = "/themes/irishoward/modules/myrtle-beach-mls/realcfc/mlsnew.cfc?method=searchMLSbyMap"; $.ajax({ type: "POST", url: url, data: $("#mlsMapForm").serialize(), success: function(thedata) { var result = JSON.parse(thedata); var listings = result.LISTINGS.data; //console.log(listings); for (var i = 0; i < listings.length; i++) { //const found = listingArray.find(obj => obj.L_LISTINGID == listings[i].L_LISTINGID); //console.log('found: ' + listings[i].L_LISTINGID + ' ' + found); var obj = $.grep(listingArray, function(obj){return obj.mlsNumber === listings[i].L_LISTINGID;}); console.log('obj: ' + listings[i].L_LISTINGID + ' : ' + obj); var newLatLng = new google.maps.LatLng( listings[i].LMD_MP_LATITUDE, listings[i].LMD_MP_LONGITUDE ); var listingMarker = new MarkerWithLabel({ position: newLatLng, animation: google.maps.Animation.DROP, title: String(listings[i].L_LISTINGID), draggable : false, //map: theMap, icon: myMarker, markerID : listings[i].L_LISTINGID, mlsNumber: listings[i].L_LISTINGID, markerText : String(listings[i].L_LISTINGID), image : listings[i].THUMBNAIL, askingPrice : formatAskingPrice(listings[i].L_ASKINGPRICE), squareFootage : String(listings[i].LM_CHAR10_11), address : String(listings[i].L_ADDRESS), city : String(listings[i].L_CITY), beds : String(listings[i].L_KEYWORD1), baths : String(listings[i].L_KEYWORD2), halfbaths : String(listings[i].L_KEYWORD3), L_numUnits : String(listings[i].L_NUMUNITS), L_class : String(listings[i].L_CLASS), L_numAcres : String(listings[i].L_NUMACRES), L_saleRent : String(listings[i].L_SALERENT), markerSubhead: String(listings[i].L_LISTINGID), labelContent: formatAskingPrice(listings[i].L_ASKINGPRICE), labelAnchor: new google.maps.Point(14, 20), labelClass: "mls-marker-label", labelInBackground: true }); google.maps.event.addListener(listingMarker, 'click', openlistingInfoWindow); function checkMarker(marker) { if ( marker.markerID === listingMarker.markerID ) { return true; } else { return false; } } if ( listingArray.find(checkMarker) == undefined ) { listingMarker.setMap(theMap); listingArray.push(listingMarker); } }//// /for listing in listings $('.mls-loading').removeClass('show'); },//// success error: function (xhr, textStatus, errorThrown){ alert(errorThrown); } }); //ajax }; // getProperties function openlistingInfoWindow(marker) { //console.log(marker); var pLatStr = this.position.lat().toString().substring(0,9); var pLngStr = this.position.lng().toString().substring(0,10); var bedsbaths = `${this.beds}Beds${this.baths}Baths`; //console.log(this.L_class); switch(this.L_class) { case 'MULTI-FAMILY': bedsbaths = `${this.L_numUnits}Units`; break; case 'LAND': bedsbaths = `${this.L_numAcres}Acres`; break; case 'COMMERCIAL/INDUSTRIAL': bedsbaths = `${this.L_numAcres}Acres${this.L_numUnits}Units`; break; default: } var contentString = `
${this.L_class}

${this.L_saleRent} ${this.askingPrice}

${this.address}, ${this.city}

${bedsbaths}
`; listingInfoWindow.setContent(contentString); //listingInfoWindow.close(); listingInfoWindow.open(theMap,this); } function offsetMapCenter(map,offsetX, offsetY){ if ( $(window).width() > 768 ) { var offsetXnew = -(window.innerWidth / 4); map.setCenter(mapCenter); map.panBy(offsetXnew,0); } else { var offsetYnew = -(window.innerHeight / 2.5); map.setCenter(mapCenter); map.panBy(0,offsetYnew); } }; $( window ).resize(function() { //offsetMapCenter(theMap); }); // show/hide markers function setMapOnAll(theMap) { for (var i = 0; i < listingArray.length; i++) { listingArray[i].setMap(theMap); } listingArray = []; }; // Removes the markers from the map, but keeps them in the array. function clearMarkers() { setMapOnAll(null); console.log('clear markers'); } // Shows any markers currently in the array. function showMarkers() { setMapOnAll(theMap); } // show/hide marker labels function showLabels() { for (var i = 0; i < listingArray.length; i++) { listingArray[i].set('labelVisible', true); } }; function hideLabels() { for (var i = 0; i < listingArray.length; i++) { listingArray[i].set('labelVisible', false); } }; function showHideLabelsOnZoom() { console.log( 'mapzoom: ' + theMap.getZoom()); if ( theMap.getZoom() < zLevelHide ) { clearMarkers(); } else { showMarkers(); } }; function findLatInPoints(pointArr,inLat) { // return number of times lat appears in points var result = $.grep(pointArr, function(e){ return e.lat() === inLat; }); return result.length; }// findLat //////////////// markers //////////////// /////////////// end markers /////////////// var gmap_styles = [ { "elementType": "geometry", "stylers": [ { "color": "#d8dbd1" } ] }, { "elementType": "labels.icon", "stylers": [ { "visibility": "off" } ] }, { "elementType": "labels.text.fill", "stylers": [ { "color": "#616161" } ] }, { "elementType": "labels.text.stroke", "stylers": [ { "color": "#f5f5f5" } ] }, { "featureType": "administrative", "elementType": "labels", "stylers": [ { "color": "#203727" } ] }, { "featureType": "administrative", "elementType": "labels.text.stroke", "stylers": [ { "visibility": "off" } ] }, { "featureType": "administrative.land_parcel", "elementType": "labels.text.fill", "stylers": [ { "color": "#bdbdbd" } ] }, { "featureType": "poi", "elementType": "geometry", "stylers": [ { "color": "#eeeeee" } ] }, { "featureType": "poi", "elementType": "labels.text.fill", "stylers": [ { "color": "#757575" } ] }, { "featureType": "poi.park", "elementType": "geometry", "stylers": [ { "color": "#e5e5e5" } ] }, { "featureType": "poi.park", "elementType": "labels.text.fill", "stylers": [ { "color": "#9e9e9e" } ] }, { "featureType": "road", "elementType": "geometry", "stylers": [ { "color": "#ffffff" } ] }, { "featureType": "road.arterial", "elementType": "labels.text.fill", "stylers": [ { "color": "#757575" } ] }, { "featureType": "road.highway", "elementType": "geometry", "stylers": [ { "color": "#dadada" } ] }, { "featureType": "road.highway", "elementType": "labels.text.fill", "stylers": [ { "color": "#616161" } ] }, { "featureType": "road.local", "elementType": "labels.text.fill", "stylers": [ { "color": "#9e9e9e" } ] }, { "featureType": "transit.line", "elementType": "geometry", "stylers": [ { "color": "#e5e5e5" } ] }, { "featureType": "transit.station", "elementType": "geometry", "stylers": [ { "color": "#eeeeee" } ] }, { "featureType": "water", "elementType": "geometry", "stylers": [ { "color": "#a0bbb8" } ] }, { "featureType": "water", "elementType": "labels.text.fill", "stylers": [ { "color": "#9e9e9e" } ] } ];