// -------------------------------------------------------------- // Icon for the red square displayed with the mouse wheel zoom var baseIcon = new GIcon(); baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png"; baseIcon.iconSize = new GSize(20, 34); baseIcon.shadowSize = new GSize(37, 34); baseIcon.iconAnchor = new GPoint(9, 34); baseIcon.infoWindowAnchor = new GPoint(9, 2); baseIcon.infoShadowAnchor = new GPoint(18, 25); var rectIcon = new GIcon(baseIcon, "http://www.ekopobyt.cz/img/gmaps/rect.png", null); // Global variables used with the mouse wheel zoom var mouseLatLng; var zoomRect; // -------------------------------------------------------------- var map; var container; var opacity = 0.4; var NormalLayer = G_NORMAL_MAP.getTileLayers()[0] var SatelliteLayer = G_SATELLITE_MAP.getTileLayers()[0] var satProj = G_SATELLITE_MAP.getProjection(); var normalProj = G_NORMAL_MAP.getProjection(); //var cRight = new GCopyrightCollection('Marcelo'); //var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90, -180), new GLatLng(90, 180)), 0, "Marcelo©2006"); //cRight.addCopyright(copyright); // Defaults -------------------------------------------- var zoom = 10; var centerPoint = new GLatLng(49.268617,15.703368); var wheelZooming = false; function load() { doLoad(); container = document.getElementById("map_canvas"); } function initialize() { if (GBrowserIsCompatible()) { container = document.getElementById("map_canvas"); resizeMap(); map = new GMap2(container, {draggableCursor:"crosshair"}); //container.firstChild.nextSibling.firstChild.nextSibling.target = '_blank'; map.setCenter(centerPoint, zoom); map.setCenter(centerPoint, zoom); //map.addControl(new GMapTypeControl()); GEvent.addListener(map, 'mousemove', mouseMove); GEvent.addListener(map, "moveend", moveEnd); GEvent.addListener(map, "zoomend", zoomEnd); if (true) { map.setMapType(G_PHYSICAL_MAP); } if (false) { var ovcontrol = new GOverviewMapControl(new GSize(120,80)); map.addControl(ovcontrol); var ov_map = ovcontrol.getOverviewMap(); GEvent.addListener(map, 'maptypechanged', function(){ ov_map.setMapType(G_NORMAL_MAP); }); } function createMarker(point, index, caption, img, url) { // Create a lettered icon for this point using our icon class var letter = String.fromCharCode("A".charCodeAt(0) + index); var letteredIcon = new GIcon(baseIcon); letteredIcon.image = "http://www.ekopobyt.cz/img/gmaps/markerA.png"; // Set up our GMarkerOptions object markerOptions = { icon:letteredIcon }; var marker = new GMarker(point, markerOptions); GEvent.addListener(marker, "click", function() { var html = ""; if (url.length > 0) html = html + "" + caption + ""; else html = html + caption; //marker.openInfoWindowHtml(html); marker.openInfoWindowHtml(html); }); return marker; } GEvent.addListener(map, "click", function(overlay, point) { if (overlay){ //marker clicked! } else document.getElementById('coordinates').value = point.x + ',' + point.y; }); var content0 = '
Chaloupky
'; var label0 = new TLabel(); label0.id = 'label0'; label0.anchorLatLng = new GLatLng (49.268617,15.703368); label0.anchorPoint = 'bottomLeft'; label0.content = content0; label0.percentOpacity = 80; map.addTLabel(label0); updateStatusBar(); // Mouse wheel zoom - Attach event handlers ----- map.enableDoubleClickZoom(); map.enableContinuousZoom(); GEvent.addDomListener(container, "DOMMouseScroll", wheelZoom); GEvent.addDomListener(container, "mousewheel", wheelZoom); // ---------------------------------------------- } } // Mouse wheel zoom - Event handler ----- function wheelZoom(event) { if (wheelZooming) { return; } wheelZooming = true; // zoomRect and rectIcon are global variables!!! zoomRect = new GMarker(mouseLatLng,{icon:rectIcon}); map.addOverlay(zoomRect); if (event.cancelable) { event.preventDefault(); } map.closeInfoWindow(); if((event.detail || -event.wheelDelta) < 0) { window.setTimeout(function(){ map.removeOverlay(zoomRect); map.zoomIn(mouseLatLng,true,true); wheelZooming = false; },200); } else { window.setTimeout(function(){ map.removeOverlay(zoomRect); map.zoomOut(mouseLatLng,true); wheelZooming = false; },200); } return false; } // End event handler ----- // Nothing related to mouse wheel zoom below this line --------------------------- function moveEnd() { updateStatusBar(); } function zoomEnd(oldZ,zoom) { updateStatusBar(); } function updateStatusBar() { var center = map.getCenter(); var zoom = map.getZoom(); var bounds = map.getBounds(); var SW = bounds.getSouthWest(); var NE = bounds.getNorthEast(); var oCoords = document.getElementById("coords"); oCoords.innerHTML = 'Map center: (' + center.y.toFixed(6) + ',' + center.x.toFixed(6) + ') - zoom: ' + zoom; oCoords.innerHTML += '
'; oCoords.innerHTML += 'SW: ' + SW.y.toFixed(6) + ', ' + SW.x.toFixed(6); oCoords.innerHTML += '
'; oCoords.innerHTML += 'NE: ' + NE.y.toFixed(6) + ', ' + NE.x.toFixed(6); } function resizeMap() { //container.style.width = document.body.clientWidth - 180 + 'px'; //container.style.height = document.body.clientHeight - 100 + 'px'; if (map) { map.checkResize(); } } function mouseMove(mousePt) { mouseLatLng = mousePt; var zoom = map.getZoom(); var oStatusDiv = document.getElementById("mouseTrack") var mousePx = normalProj.fromLatLngToPixel(mousePt, zoom); oStatusDiv.innerHTML = 'Mouse LatLng: ' + mousePt.y.toFixed(6) + ', ' + mousePt.x.toFixed(6) ; oStatusDiv.innerHTML += '
'; oStatusDiv.innerHTML += 'Mouse Px: ' + mousePx.x + ', ' + mousePx.y; oStatusDiv.innerHTML += '
'; oStatusDiv.innerHTML += 'Tile: ' + Math.floor(mousePx.x / 256) + ', ' + Math.floor(mousePx.y / 256); } window.addEvent('domready', function() { initialize(); }); window.addEvent('unload', function() { GUnload(); });