// google maps skript pro načtení pointů z XML zdroje $(document).ready(function() { preloadImages(); initializeGMaps(); }); function preloadImages() { if (!document.images) { return; } var image = null; for (var key in icons) { var icon = icons[key]; image = new Image(10, 10); image.src = icon; } image = new Image(10, 10); image.src = "/img/icon-close.gif"; } // pole všech značek var global_markers = new Array(); // pole ikonek var icons = new Array(); // mapa var map; // hranice pro zobrazeni mapy var bounds; var infoWindow; // vytvoříme typy značek icons["type1"] = "/img/map/ico-devel.png"; icons["type2"] = "/img/map/ico-devel-disabled.png"; icons["sale"] = "/img/map/ico-sale.png"; icons["disabled"] = "/img/map/ico-disabled.png"; icons["cheap"] = "/img/icons/cheap-small.png"; icons["design"] = "/img/icons/design-small.png"; icons["ecology"] = "/img/icons/ecology-small.png"; icons["video"] = "/img/icons/video-small.png"; // Inicializace mapy function initializeGMaps() { // určení DIVu, který obsahuje mapu basePoint = new google.maps.LatLng(49.74799973900054, 15.38134765625); var myOptions = { zoom: 7, center: basePoint, navigationControl: true, navigationControlOptions : { style: google.maps.NavigationControlStyle.DEFAULT }, mapTypeControl: true, scaleControl: true, streetViewControl: true, mapTypeId: google.maps.MapTypeId.ROADMAP, scrollwheel: false }; map = new google.maps.Map(document.getElementById("results-map-inner"), myOptions); // Overwrite the getMinimumResolution() and getMaximumResolution() methods google.maps.event.addListener(map, "zoom_changed", function() { if (map.getZoom() < 7) { map.setZoom(7); } }); // vytvorime prazdny objekt pro definici hranic zobrazeni bounds = new google.maps.LatLngBounds(); downloadMap("/index/json-export", true); // listener pro nahrani nemovitosti dle aktualniho vyrezu mapy google.maps.event.addListener(map, "dragend", function() { synchronizeMap(); if ( typeof updateElements == "function") { updateElements(); } }); google.maps.event.addListener(map, "zoomend", function() { synchronizeMap(); if ( typeof updateElements == "function") { updateElements(); } }); } function synchronizeMap() { var span = map.getBounds().toSpan(); var center = map.getBounds().getCenter(); var zoom = map.getZoom(); if (zoom >= 11) { var url = "/hledani/synchronize?lat=" + center.lat() + "&lng=" + center.lng() + "&accuracy=" + span.lat() ; downloadMap(url); } } function downloadMap(url, initialization) { // build map icons from json $.get(url, {}, function(data, responseCode) { var s; var points = data.points; var innerHtml = "Vašemu vyhledávání neodpovídá žádná nabídka.

"; // pokud neni zadnej bod v exportu, tak nastavime hranice na CR if (points.length == 0 && initialization) { basePoint1 = new google.maps.LatLng(51.39372189194996, 12.579345703125); basePoint2 = new google.maps.LatLng(48.050178768479675, 17.6220703125); bounds.extend(basePoint1); bounds.extend(basePoint2); var dialog = $("#dialog"); var message = $("#dialog-message"); dialog.css("display", "block"); message.html(innerHtml); } // for přes všechny body v XML souboru for (var i = 0; i < points.length; i++) { // pokud je jiz marker v poli, tak jej neni potreba pridavat if (global_markers[points[i].id]) { continue; } // souřadnice bodu var point = new google.maps.LatLng(parseFloat(points[i].lng), parseFloat(points[i].lat)); // pridame bod do hranic zobrazeni if (initialization) { bounds.extend(point); } // vytvoreni obsahu s = createContent(points[i]); // vytvoření značky var marker_id = points[i].id; if (!global_markers[marker_id]) { var marker = createMarker(point, s, points[i].label, points[i].icon); // přidání značky do globálního pole global_markers[marker_id] = marker; } } if (initialization) { GM_setViewport(bounds); } }, "json"); } /** * Fixes API problems. * */ function GM_setViewport(bounds, callback) { var desiredSpan = bounds.toSpan(); map.fitBounds(bounds); google.maps.event.addListenerOnce(map, "bounds_changed", function() { //createMarker(bounds.getSouthWest(), "SW" + asdf, "SW" + asdf, "type1"); //createMarker(bounds.getNorthEast(), "NE" + asdf, "NE" + asdf, "type1"); //asdf++; //map.setZoom(map.getZoom() + 1); // GM bugfix while (true) { if (map.getBounds() == null) { break; } var newSpan = map.getBounds().toSpan(); var errorLat = Math.round(Math.abs(newSpan.lat() / desiredSpan.lat())); var errorLng = Math.round(Math.abs(newSpan.lng() / desiredSpan.lng())); var error = Math.min(errorLat, errorLng); //alert(errorLat + " vs " + errorLng + " => " + error); if (error >= 2) { // too large map.setZoom(map.getZoom() + 1); // zoom in } else if (error == 0) { map.setZoom(map.getZoom() - 1); // zoom out } else { break; } } if (typeof callback == "function") { callback(); } }); } function infoClick(i) { google.maps.event.trigger(global_markers[i], "click"); map.setZoom(15); } function createContent(point) { // html obsah informačního okna, které se zobrazi var s = "
"; // test if image exists if (point.img) { s = s + ""; } s = s + "
"; if (point.paid) { s = s + ""; s = s + ""; s = s + ""; } else { s = s + ""; } s = s + ""; // test if url exists if (point.paid) { s = s + "" + point.name + "
"; } else { s = s + "" + point.name + "
"; } s = s + point.label.replace(/2<\/sup>,/, '2,
') + "
"; if (point.paid) { s = s + "Detail »
"; } if (point.cheap > 0) { s = s + "Levné bydlení"; } if (point.design > 0) { s = s + "Designové bydlení"; } if (point.ecology > 0) { s = s + "Eko bydlení"; } if (point.video > 0) { s = s + "Video"; } s = s + "
"; s = s + "
" return s; } // Vytvoří značku, parametry: souřadnice značky, html kód okna, popiska značky, ikona značky function createMarker(point, content, cap, icon_type) { /* create marker */ var size = new google.maps.Size(25, 31); var icon = new google.maps.MarkerImage(icons[icon_type], size); var markerOpts = { position: point, draggable: false, title: cap, icon: icon, maxWidth: 400 }; var marker = new google.maps.Marker(markerOpts); marker.setMap(map); google.maps.event.addListener(marker, "click", function() { createInfoWindow(content, marker); map.panTo(point); //map.setZoom(12); }); return marker; } function createInfoWindow(string, marker) { if (infoWindow) { infoWindow.close(); infoWindow = null; } infoWindow = new google.maps.InfoWindow({ content: string }); infoWindow.open(map, marker); return infoWindow; }