front_idill/src/mosaic/js/localMosaic.js
author bastiena
Tue, 31 Jul 2012 16:26:00 +0200
changeset 58 a28488078053
parent 30 45c889eae324
permissions -rw-r--r--
Front IDILL: search curves modified : search curves exit when event other than many curves detected.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     1
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     2
* This file is part of the TraKERS\Front IDILL package.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     3
*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     4
* (c) IRI <http://www.iri.centrepompidou.fr/>
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     5
*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     6
* For the full copyright and license information, please view the LICENSE
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     7
* file that was distributed with this source code.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     8
*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     9
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    10
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    11
 * Projet : TraKERS
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    12
 * Module : Front IDILL
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    13
 * Fichier : localMosaic.js
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    14
 * 
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    15
 * Auteur : alexandre.bastien@iri.centrepompidou.fr
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    16
 * 
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    17
 * Fonctionnalités : Définit la "classe" mosaïque locale (lors d'un zoom sur une mosaïque) et définit des fonctions d'intéractions.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    18
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    19
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    20
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    21
 * Classe définissant la mosaïque locale.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    22
 * Elle sera toujours de la forme 3x3, même si toutes les cases ne seront pas remplies par des snapshots (cas des bords et coins).
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    23
*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    24
function localMosaic(len, imgToShow, marginWidth)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    25
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    26
    if(imgToShow % len == 0)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    27
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    28
        this.length = len;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    29
        this.imagesToShow = imgToShow;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    30
        this.centerId;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    31
        this.urls = [];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    32
        this.imgs = [];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    33
        this.ids = [];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    34
        this.width;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    35
        this.height;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    36
        this.marginWidth = marginWidth;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    37
        this.zoomed;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    38
        this.snapshotTop;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    39
        this.snapshotLeft;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    40
        this.snapshotWidth;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    41
        this.snapshotHeight;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    42
    }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    43
    else
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    44
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    45
        //Affiche un message d'erreur.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    46
    }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    47
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    48
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    49
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    50
 * Crée la mosaïque locale, qui est une partie de la mosaïque de mosaic.js.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    51
 * Il y a le snapshot sur lequel on a zoomé, et les 8 snapshots voisins.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    52
*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    53
localMosaic.prototype.createLocalMosaic = function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    54
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    55
    var str = '';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    56
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    57
    var t = this.coord1Dto2D(this.centerId);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    58
    var localId;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    59
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    60
    for(var a = t[1] - 1 ; a < t[1] + 2 ; a++)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    61
        for(var b = t[0] - 1 ; b < t[0] + 2 ; b++)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    62
            if(a > -1 && a < this.imagesToShow / this.length && b > -1 && b < this.length)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    63
            {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    64
                localId = this.coord2Dto1D(a, b);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    65
                str += '<div class="snapshotDivs"><img id="snapshot-' + localId + '" class="snapshots" src="snapshots-little/' + this.imgs[localId] + '" /></div>';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    66
            }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    67
            else
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    68
                str += '<div class="blacks"></div>';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    69
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    70
    return str;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    71
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    72
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    73
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    74
 * Permet de charger la mosaïque locale.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    75
*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    76
localMosaic.prototype.loadLocalMosaic = function(snTop, snLeft, snWidth, snHeight, imgsTab, id)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    77
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    78
    //On affecte les chemins vers les images à la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    79
    this.imgs = imgsTab;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    80
    this.centerId = id;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    81
    this.snapshotTop = snTop;//*(newPreMPHeight/initMPHeight) - this.zoomedMargin/2 + (initMPHeight - initMPHeight * this.zoomPercentage)/2 + 'px';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    82
    this.previousMPLeft = snLeft;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    83
    this.snapshotWidth = snWidth;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    84
    this.snapshotHeight = snHeight;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    85
    //On met à jour la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    86
    $('#mainPanel').html(this.createLocalMosaic(id));
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    87
    $('.snapshotDivs').css('width', snWidth).css('height', snHeight).css('margin', this.marginWidth/2);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    88
    // var lMosTop = , newZoomLeft = -this.previousZoomedSN.position().left*(newPreMPWidth/initMPWidth) - this.zoomedMargin/2 + (initMPWidth - initMPWidth * this.zoomPercentage)/2 + 'px';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    89
    $('#mainPanel').css('top', 0).css('left', 0);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    90
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    91
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    92
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    93
 * Change de 1 à 2 dimensions pour les coordonnées des snapshots dans la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    94
*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    95
localMosaic.prototype.coord1Dto2D = function(i)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    96
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    97
    return [i%length, Math.floor(i/this.length)];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    98
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    99
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   100
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   101
 * Change de 2 à 1 dimension pour les coordonnées des snapshots dans la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   102
*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   103
localMosaic.prototype.coord2Dto1D = function(i, j)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   104
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   105
    return j * this.length + i;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   106
}