var totalX = -1; var totalY = -1; var width = ; var height = ; var iconsUrl = ''; var iconsSizeHalf = 0; var iconsCount = 0; var maxLevel = 3; var mapLoadUrl = '/map/data.php'; var x = 0; var y = 0; var level = 0; var zoom = 1; var zoomMax = 1; $(function() { var i; for (i=0; i 0) { mapZoomIn(xx, yy); } else { mapZoomOut(xx, yy); } }) .click(function(event) { var xx = Math.round(( x * width + (event.pageX - $('#mapUp').offset().left) - $('#map').attr('offsetLeft') - (totalX+1) * width ) * zoomMax / zoom); var yy = Math.round(( y * height + (event.pageY - $('#mapUp').offset().top) - $('#map').attr('offsetTop') - (totalY+1) * height ) * zoomMax / zoom); ///////////ADMIN if (mapAdminMode != '') { switch(mapAdminMode) { case 'add': mapAdminAddObject(xx, yy); break; } mapAdminMode = ''; mapAdminModeRedraw(); } /////////////ADMIN }) .draggable({ zIndex: -1, stop: function() { var moveX = 0, moveY = 0; if (Math.abs($('#map').attr('offsetLeft') + (width*(totalX+1))) >= width ) { moveX = Math.round(($('#map').attr('offsetLeft') + (width*(totalX+1))) / width); x -= moveX; } if (Math.abs($('#map').attr('offsetTop') + (height*(totalY+1))) >= height ) { moveY = Math.round(($('#map').attr('offsetTop') + (height*(totalY+1))) / height); y -= moveY; } if ((moveX!=0) || (moveY!=0)) { mapRedraw(); $('#map').offset({ left: $('#map').offset().left - (moveX * width), top: $('#map').offset().top - (moveY * height) }); if (iconsCount > 0) { var i; for (i=0; i 0) { for (i=0; i').insertAfter('#map_5_5'); } iconsCount = data.length; } }, 'json' ) } /////////////ADMIN var mapAdminMode = ''; var mapAdminEngine = '/map/engine.php'; var mapAdminModeText = { 'add': 'Add mode on' }; function mapAdminAdd() { mapAdminMode = 'add'; mapAdminModeRedraw(); } function mapAdminModeRedraw() { $('#mapAdminMode').html( (mapAdminModeText[mapAdminMode]) ?mapAdminModeText[mapAdminMode] :'' ); } function mapAdminAddObject(xx, yy) { $('#mapAdminEdit input:hidden[name="x"]').val(xx); $('#mapAdminEdit input:hidden[name="y"]').val(yy); $('#mapAdminAddForm').show(); } function mapAdminEditClose() { $('#mapAdminAddForm').hide(); mapAdminMode = ''; mapAdminModeRedraw(); } function mapAdminSave() { $.post(mapAdminEngine, { act: 'save', id: $('#mapAdminEdit input:hidden[name="id"]').val(), x: $('#mapAdminEdit input:hidden[name="x"]').val(), y: $('#mapAdminEdit input:hidden[name="y"]').val(), title: $('#mapAdminEdit input:text[name="title"]').val(), body: $('#mapAdminEdit textarea[name="body"]').val(), category: $('#mapAdminEdit select[name="category"]').val() }, function(data) { $('#mapAdminAddForm').hide(); $('#mapAdminMode').html(data); }) $('#mapAdminEdit') } /////////////ADMIN function mapZoomIn(xx, yy) { if (level == maxLevel) return; level ++; zoom *= 2; document.title = yy; xx = (xx * zoom / zoomMax - (totalX+1)*width/2) / width; yy = (yy * zoom / zoomMax - (totalY+1)*height/2) / height; x = Math.floor(xx); y = Math.floor(yy); // $('#map').offset({ // left: Math.round(- width * (totalX - 2 + xx - x)), // top: Math.round(- height * (totalY - 2 + yy - y)) // }); mapRanges(); mapRedraw(); } function mapZoomOut(xx, yy) { if (level == 0) return; level --; zoom /= 2; xx = (xx * zoom / zoomMax - (totalX+1)*width/2) / width; yy = (yy * zoom / zoomMax - (totalY+1)*height/2) / height; x = Math.floor(xx); y = Math.floor(yy); // $('#map').offset({ // left: Math.round(- width * (totalX - 2 + xx - x)), // top: Math.round(- height * (totalY - 2 + yy - y)) // }); mapRanges(); mapRedraw(); } function mapRanges() { if (x < 0) { x = 0; } if (y < 0) { y = 0; } if (x > (Math.floor(zoom - 1) * (totalX+1))) { x = Math.floor(zoom - 1) * (totalX+1); } if (y > (Math.floor(zoom - 1) * (totalY+1))) { y = Math.floor(zoom - 1) * (totalY+1); } } function mapRedraw() { var i, j; for (i=-1; i<=(totalX+1); i++) { for (j=-1; j<=(totalY+1); j++) { $('#map_' + i + '_' + j).attr('src', (( (Math.round(x+i) >= 0) && (Math.round(y+j) >= 0) && (Math.round(x+i) < (totalX+1)*zoom) && (Math.round(y+j) < (totalY+1)*zoom) ) ?'' + level + '/' + Math.round(x + i) + '/' + Math.round(y + j) + '.'map.php?x=' + Math.round(x + i) + '&y=' + Math.round(y + j) + '&level=' + level :'img/null.gif')); } //3 train, 5 vagon, aleksandr, 21:10 kazanskij } mapObjectsLoad(); } function mapUp() { if (y != 0) { y--; mapRedraw(); } } function mapRight() { if (x != (Math.floor(zoom - 1) * (totalX+1)) ) { x++; mapRedraw(); } } function mapLeft() { if (x != 0) { x--; mapRedraw(); } } function mapDown() { if (y != (Math.floor(zoom - 1) * (totalY+1)) ) { y++; mapRedraw(); } }