var marker_init = true; function init(){ var container = document.getElementById('map'); var options = { center: { lat: 37.5653617, lng: 126.9738027 }, zoom: 15 , scrollwheel: true , }; map = new google.maps.Map(container, options); google.maps.event.addListener(map, 'idle', init_listing); HtmlMarker.prototype = new google.maps.OverlayView(); init_form(); //마커셋팅 setTimeout(function () { get_map_data(); }, 350); map.addListener("zoom_changed", () => { get_map_data(); }); } function call_listing(){ var center = map.getCenter(); //var url = domain + 'lat='+center.lat()+'&lng='+center.lng()+'&zoom='+map.getZoom(); history.replaceState('', '제목'); get_map_data(); /* 지도 매물 마커(시,군,동,지하철 ...) */ get_map_list(0); /* 지도 매물 리스트 */ } function get_map_data(){ var formData = $("#search_form").serialize(); formData+='&zoom='+map.getZoom(); formData+='&swlat='+map.getBounds().getSouthWest().lat(); formData+='&nelat='+map.getBounds().getNorthEast().lat(); formData+='&swlng='+map.getBounds().getSouthWest().lng(); formData+='&nelng='+map.getBounds().getNorthEast().lng(); $.ajax({ type: 'POST', url: "/main/get_json_google", data: formData, dataType: 'json', success: function(jsonData){ $.each(jsonData, function(key, val) { if(key=="query"){ draw_marker(val); } }); } }); } function get_map_list(page){ var formData = $("#search_form").serialize(); formData+='&level='+map.getZoom(); formData+='&swlat='+map.getBounds().getSouthWest().lat(); formData+='&nelat='+map.getBounds().getNorthEast().lat(); formData+='&swlng='+map.getBounds().getSouthWest().lng(); formData+='&nelng='+map.getBounds().getNorthEast().lng(); formData+="&sorting="+$("select[name='sorting']").val(); $.ajax({ type : "POST", url : "/main/get_all_server_list_google/"+page, data : formData, dataType: 'json', success: function(data) { $.each(data, function(key, val) { if(key=="result") { $("#map_search_list").html(val); $(".property-grid a").click(function(){ property_view($(this).data("id")); }); } if(key=="paging") { $("#pagination").html(val); $("#next_page").val(val); init_paging(); } if(key=="total"){ total = val; $("#total_label").html(" " + val + ""); } }); $("#map_search_list").animate({ scrollTop: 0 }, 600); link_init($('.view_product')); //init_like(); } }); } function draw_marker(val){ var param = 0; /* 첫마커배치 이후에만 셋팅되어있는 마커 제거용 */ if(!start){ for(i=0; i < htmlmarkers.length ;i++){ console.log(htmlmarkers); htmlmarkers[i].setMap(null); } } $.each(val, function(key1, val1) { if(start){ start = false; } //위치 var loc = new google.maps.LatLng(val1["lat"], val1["lng"]); //마커 htmlmarkers[key1] = new google.maps.Marker({ position: loc, map: map, title:val1["title"] }); htmlmarkers[key1].addListener("click", () => { product_modal_google(val1["id"]); }); param = key1; }); } function HtmlMarker(position, content, cssText) { this.setValues({ position: position, container: null, content: content, map: map, cssText: cssText }); this.onAdd = function () { var that = this, container = document.createElement('div'), content = this.get('content'), cssText = this.get('cssText') || ''; container.className = 'property-dot'; container.style.cssText = cssText; google.maps.event.addDomListener(container, 'click', function () { google.maps.event.trigger(that, 'click'); }); if (typeof content !== 'undefined') { container.appendChild(content); } else { container.innerHTML = content; } container.style.position = 'absolute'; this.set('container', container) this.getPanes().floatPane.appendChild(container); } this.draw = function () { var pos = this.getProjection().fromLatLngToDivPixel(this.get('position')), container = this.get('container'); container.style.left = pos.x - (container.offsetWidth / 2) + 'px'; container.style.top = pos.y - (container.offsetHeight) + 'px'; } this.onRemove = function () { this.get('container').parentNode.removeChild(this.get('container')); this.set('container', null) } } function init_paging(){ $(".page-link").click(function(e){ e.preventDefault(); var page = $(this).attr("href").substring($(this).attr("href").lastIndexOf('/') + 1); get_map_list(page); $(".property_list_wrapper").animate({ scrollTop: 0 }, 600); }); } /***************************************************** * 더보기 버튼 이벤트 *****************************************************/ function more(){ console.log($("#next_page").val()); right_exists = false; get_map_list($("#next_page").val()); }