/* * To change this template, choose Tools | Templates * and open the template in the editor. */ var _map = { url: { inner: "/_front/_ajax/map/inner/", info: "/_front/_ajax/map/info/" }, width: 492, height: 492, left: 'auto', top: 'auto', zoom: { former: 1, current: 1, range: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], rank: 0, _in: function() { _map.zoom.rank = Math.min(_map.zoom.rank + 1, _map.zoom.range.length - 1); _map.zoom.update(); }, _out: function() { _map.zoom.rank = Math.max(0, _map.zoom.rank - 1); _map.zoom.update(); }, update: function() { _map.zoom.current = _map.zoom.range[_map.zoom.rank]; var l_x = $('#map_toDrag').position().left + .5 * $('#map_toDrag').width(); var l_y = $('#map_toDrag').position().top + .5 * $('#map_toDrag').height(); var l_xRatio = l_x / $('#map_constrain').width(); var l_yRatio = l_y / $('#map_constrain').height(); $('#map_toDrag').width(_map.zoom.current * _map.width); $('#map_toDrag').height(_map.zoom.current * _map.height); $('#map_jpg').width(_map.zoom.current * _map.width); $('#map_jpg').height(_map.zoom.current * _map.height); $('#map_constrain').width(2 * _map.zoom.current * _map.width - $('#map').width()); $('#map_constrain').height(2 * _map.zoom.current * _map.height - $('#map').height()); var l_leftConstrain = .5 * ($('#map').width() - $('#map_constrain').width()); var l_topConstrain = .5 * ($('#map').height() - $('#map_constrain').height()); $('#map_constrain').css('left', l_leftConstrain + 'px'); $('#map_constrain').css('top', l_topConstrain + 'px'); var l_xNew = l_xRatio * $('#map_constrain').width(); var l_yNew = l_yRatio * $('#map_constrain').height(); var l_wDrag = $('#map_toDrag').width(); var l_hDrag = $('#map_toDrag').height(); // recalage avec prise en compte du zoom_out _map.left = Math.min(Math.max(0, l_xNew - .5 * l_wDrag), $('#map_constrain').width() - l_wDrag); _map.top = Math.min(Math.max(0, l_yNew - .5 * l_hDrag), $('#map_constrain').height() - l_hDrag); $('#map_toDrag').css('left', _map.left + 'px'); $('#map_toDrag').css('top', _map.top + 'px'); var l_jpgZoom = Math.max(1, _map.zoom.current); $('#map_jpg').attr('src', '/_static/images/map/concess_map' + l_jpgZoom + '.jpg'); var l_scaleTop = 22 * (_map.zoom.current - 1); $('#map_ui_scale').css('background-position', '0px -' + l_scaleTop + 'px'); } }, concess: { mouseover: function() { $('#map_info_container').load( _map.url.info, { id: $(this).attr('id'), left: $(this).offset().left, top: $(this).offset().top }, function(){ $(this).css('display', 'block'); $(this).mouseleave(function(){ $(this).css('display', 'none'); }); } ); } }, init : { mousewheel: { map: function(){ $('#map_toDrag').mousewheel(function(i_event, i_delta){ if (i_delta < 0) { _map.zoom._in(); } else { _map.zoom._out(); } return false; }); } }, drag: { map: function(){ $('#map_toDrag').draggable({ containment: 'parent' }); } }, all: function() { _index.init.jqueryui(function() { _index.init.jquerywheel(function() { _map.init.main(); }); }); }, main: function() { var l_wMap = $('#map').width(); var l_hMap = $('#map').height(); if (l_hMap < _map.height ||l_wMap < _map.width) { _map.zoom.current = (l_hMap > l_wMap) ? (l_hMap / _map.height) : (l_wMap / _map.width); _map.zoom.range.unshift(_map.zoom.current); } $('#map').load( _map.url.inner, { zoom: _map.zoom.current, width: l_wMap, height: l_hMap, left: _map.left, top: _map.top }, function() { _map.init.drag.map(); $('.map_point').mouseover(_map.concess.mouseover); _map.init.mousewheel.map(); } ); $('#map_ui').load('/_front/_templates/map_ui.html'); }, alone: function(i_codConcess) { _index.init.jqueryui(function() { _index.init.jquerywheel(function() { $('#map').load( _map.url.inner, { zoom: _map.zoom.current, width: $('#map').width(), height: $('#map').height(), left: _map.left, top: _map.top, concess: i_codConcess }, function() { _map.init.drag.map(); _map.init.mousewheel.map(); } ); $('#map_ui').load('/_front/_templates/map_ui.html'); }); }); } }, on: false };