IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

IGN API Géoportail Discussion :

Openlayers.Layers.TileCache sous geoportail


Sujet :

IGN API Géoportail

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    27
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 27
    Points : 35
    Points
    35
    Par défaut Openlayers.Layers.TileCache sous geoportail
    Pour inclusion dans une prochaine version de Geoportail :
    J'ai réussit à faire marcher la couche Openlayers.Layers.TileCache en dérivant de Geoportal.Layer.Grid et en faisant un mix du code de Geoportal.Layer.WMSC et Openlayers.Layers.TileCache.

    Reste à faire :
    - codage en dur image/png
    - factorisation code entre WMSC et TileCache ?

    Geoportal.Layer.TileCacheNew = OpenLayers.Class(Geoportal.Layer.Grid, {

    extension : null,
    format: "image/png",

    DEFAULT_PARAMS: {
    service: "WMS",
    version: "1.1.1",
    request: "GetMap",
    styles: "",
    exceptions: "application/vnd.ogc.se_inimage",
    format: "image/jpeg"
    },
    isBaseLayer: false,


    initialize: function (E, D, layername,F, C)
    {
    this.layername = layername;
    var B = [];
    F = OpenLayers.Util.upperCaseObject(F);
    B.push(E, D, F, C);
    Geoportal.Layer.Grid.prototype.initialize.apply(this, B);
    OpenLayers.Util.applyDefaults(this.params, OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS));
    if (this.params.TRANSPARENT && this.params.TRANSPARENT.toString().toLowerCase() == "true")
    {
    if ((C == null) || (!C.isBaseLayer))
    {
    this.isBaseLayer = false
    }
    if (this.params.FORMAT == "image/jpeg")
    {
    this.params.FORMAT = OpenLayers.Util.alphaHack() ? "image/gif" : "image/png"
    }
    }

    this.extension = this.format.split('/')[1].toLowerCase();
    this.extension = (this.extension == 'jpg') ? 'jpeg' : this.extension;

    },
    destroy: function ()
    {
    Geoportal.Layer.Grid.prototype.destroy.apply(this, arguments)
    },
    clone: function (B)
    {
    if (B == null)
    {
    B = new Geoportal.Layer.TileCacheNew (this.name, this.url, this.params, this.options)
    }
    B = Geoportal.Layer.Grid.prototype.clone.apply(this, [B]);
    return B
    },



    /**
    * Method: getURL
    *
    * Parameters:
    * bounds - {<OpenLayers.Bounds>}
    *
    * Returns:
    * {String} A string with the layer's url and parameters and also the
    * passed-in bounds and appropriate tile size specified as parameters.
    */
    getURL: function(bounds) {
    var res = this.map.getResolution();
    var bbox = this.maxExtent;
    var size = this.tileSize;
    var tileX = Math.round((bounds.left - bbox.left) / (res * size.w));
    var tileY = Math.round((bounds.bottom - bbox.bottom) / (res * size.h));
    var tileZ = this.serverResolutions != null ?
    OpenLayers.Util.indexOf(this.serverResolutions, res) :
    this.map.getZoom();
    /**
    * Zero-pad a positive integer.
    * number - {Int}
    * length - {Int}
    *
    * Returns:
    * {String} A zero-padded string
    */
    function zeroPad(number, length) {
    number = String(number);
    var zeros = [];
    for(var i=0; i<length; ++i) {
    zeros.push('0');
    }
    return zeros.join('').substring(0, length - number.length) + number;
    }
    var components = [
    this.layername,
    zeroPad(tileZ, 2),
    zeroPad(parseInt(tileX / 1000000), 3),
    zeroPad((parseInt(tileX / 1000) % 1000), 3),
    zeroPad((parseInt(tileX) % 1000), 3),
    zeroPad(parseInt(tileY / 1000000), 3),
    zeroPad((parseInt(tileY / 1000) % 1000), 3),
    zeroPad((parseInt(tileY) % 1000), 3) + '.' + this.extension
    ];
    var path = components.join('/');
    var url = this.url;
    if (url instanceof Array) {
    url = this.selectUrl(path, url);
    }
    url = (url.charAt(url.length - 1) == '/') ? url : url + '/';
    return url + path;
    },

    mergeNewParams: function (D)
    {
    var C = OpenLayers.Util.upperCaseObject(D);
    var B = [C];
    Geoportal.Layer.Grid.prototype.mergeNewParams.apply(this, B)
    },
    getFullRequestString: function (C)
    {
    var B = this.getNativeProjection() || this.map.getProjection();
    this.params.SRS = (B == "none") ? null : B;
    return Geoportal.Layer.Grid.prototype.getFullRequestString.apply(this, arguments)
    },
    addTile: function (E, B, D)
    {
    var C = this.getURL(E);
    return new Geoportal.Tile.Image(this, B, E, C, D)
    },



    getDataExtent: function ()
    {
    return this.maxExtent
    },
    changeBaseLayer: function (B)
    {
    if (OpenLayers.Layer.prototype.changeBaseLayer.apply(this, arguments) === false)
    {
    return false
    }
    if (!this.isBaseLayer)
    {
    if (this.getCompatibleProjection(B.layer) != null)
    {
    if (this.aggregate == undefined)
    {
    this.displayInLayerSwitcher = true
    }
    if (typeof(this.savedStates[B.layer.id]) == "object")
    {
    if (this.savedStates[B.layer.id].opacity != undefined)
    {
    this.opacity = undefined;
    this.setOpacity(this.savedStates[B.layer.id].opacity)
    }
    this.setVisibility(this.savedStates[B.layer.id].visibility)
    }
    else
    {
    this.setVisibility(this.getVisibility() && this.calculateInRange())
    }
    return true
    }
    if (this.getCompatibleProjection(B.baseLayer) != null)
    {
    if (!this.savedStates[B.baseLayer.id])
    {
    this.savedStates[B.baseLayer.id] =
    {
    }
    }
    this.savedStates[B.baseLayer.id].visibility = this.getVisibility();
    this.savedStates[B.baseLayer.id].opacity = this.opacity
    }
    if (this.aggregate == undefined)
    {
    this.displayInLayerSwitcher = false
    }
    this.setVisibility(false)
    }
    return true
    },
    getCompatibleProjection: function (D)
    {
    var C = OpenLayers.Layer.prototype.getCompatibleProjection.apply(this, arguments);
    if (C == null)
    {
    return C
    }
    if (D == null)
    {
    D = this.map.baseLayer;
    if (D == null)
    {
    return undefined
    }
    }
    var E = D.getNativeProjection();
    if (C.isCompatibleWith(E))
    {
    var B = this.restrictedExtent || this.maxExtent;
    if (!B)
    {
    return C
    }
    if (this.map == null)
    {
    B = B.clone().transform(C, E)
    }
    if (D.maxExtent.containsBounds(B, true, true) || B.containsBounds(D.maxExtent, true, true))
    {
    return C
    }
    }
    return null
    },
    CLASS_NAME: "Geoportal.Layer.TileCacheNew"
    });

  2. #2
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut
    Excellent !
    Je regarderai si on peut l'inclure.
    Que veux-tu dire par :

    - codage en dur image/png
    il suffit dans le constructeur de passer l'options avec params.FORMAT à 'image/png' ...

    - factorisation code entre WMSC et TileCache ?
    Pourquoi faire ?)

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    27
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 27
    Points : 35
    Points
    35
    Par défaut
    Nickel alors

    Pour la factorisation du code, c'est optionnel en effet, c'est juste que j'ai fait un gros copié collé de WMSC à la base

Discussions similaires

  1. Réponses: 24
    Dernier message: 23/05/2013, 08h26
  2. Changer le style d'un OpenLayers.Layer.Boxes
    Par Mides dans le forum IGN API Géoportail
    Réponses: 4
    Dernier message: 21/09/2012, 22h30
  3. [Openlayers/GeoExt] Problème sous IE
    Par Arn°oO dans le forum SIG : Système d'information Géographique
    Réponses: 0
    Dernier message: 31/05/2011, 15h36
  4. Gestion du clic sur un OpenLayers.Layer.Vector
    Par Al3x dans le forum IGN API Géoportail
    Réponses: 3
    Dernier message: 22/05/2011, 21h44
  5. [CSS 2] bug bloquant navigation + layer sous IE6
    Par gtraxx dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 19/05/2009, 09h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo