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 :

Gestion de l'aspect du cartouche "couches"


Sujet :

IGN API Géoportail

  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Avril 2009
    Messages
    874
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2009
    Messages : 874
    Points : 371
    Points
    371
    Par défaut Gestion de l'aspect du cartouche "couches"
    Salut à tous
    Je souhaite élargir le cartouche "Couches".
    Si jouer sur le width du style gpControlLayerSwitcher peut permettre d'élargir la zone globale, comment élargir les zones internes afin de voir en entier (du moins, une plage élargie) des noms des couches.
    Dans l'exemple ci-dessous, voir "Bécassine des marais" à la place de "Bécassine des ...".


    Plus globalement qu'avec mes bidouilles, y a -t-il un moyen simple pour gérer l'aspect du cartouche "Couches".

    Pascal

  2. #2
    Membre averti
    Femme Profil pro
    Consultante SIG
    Inscrit en
    Mars 2011
    Messages
    233
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultante SIG

    Informations forums :
    Inscription : Mars 2011
    Messages : 233
    Points : 356
    Points
    356
    Par défaut
    Pour enlever les "...", il faut surcharger la méthode drawLayer du contrôle LayerSwitcher:
    Au début de la méthode initMap, ajouter ce code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
        Geoportal.Control.LayerSwitcher.prototype.drawLayer= function(layer, i, l, lup, ldown) {
            var doc= this.div.ownerDocument;
            var layers= this.map.layers.slice();
            var groupDiv= this.dataLayersDiv;
            var drawn= false;
            var baseLayer= layer.isBaseLayer;
            var layerState= this.layerStates[i];
            var j;
    
            // don't want baseLayers ...
            if (layer.displayInLayerSwitcher && !baseLayer) {
                drawn= true;
    
                var layerDiv= doc.createElement("div");
                layerDiv.id= this.id+"_"+layer.id;
                layerDiv.className= "gpLayerDivClass";
                if ((this.dataLayers.length %2) == 1) {
                    layerDiv.className+= "Alternate";
                }
                groupDiv.appendChild(layerDiv);
                OpenLayers.Event.observe(
                    layerDiv,
                    "click",
                    OpenLayers.Function.bindAsEventListener(
                        this.onActiveLayer,
                        ({
                            'layer': layer,
                            'layerSwitcher': this
                        })));
    /*
                if (this.activeLayer===layer) {
                    OpenLayers.Element.addClass(layerDiv, "gpLayerDivClassActive");
                }
     */
    
                var dg1= doc.createElement("div");
                dg1.className= "gpLayerNameGroupDivClass";
                layerDiv.appendChild(dg1);
    
                // check data layers if they are visible
                var checked= layer.getVisibility();
                var inputElem= doc.createElement("input");
                inputElem.id= "input_" + layer.id;
                inputElem.name= layer.name;
                inputElem.type= "checkbox";
                inputElem.value= layer.name;
                inputElem.checked= checked;
                inputElem.defaultChecked= checked;
                inputElem.className= 'gpLayerVisibilityClass';
                inputElem.style.autocomplete= "off";
                OpenLayers.Event.observe(
                    inputElem,
                    "mouseup",
                    OpenLayers.Function.bindAsEventListener(
                        this.onInputClick,
                        ({
                            'inputElem': inputElem,
                            'layer': layer,
                            'layerSwitcher': this
                        })));
                dg1.appendChild(inputElem);
    
                // create span
                var labelSpan= doc.createElement("span");
                labelSpan.id= 'label_' + layer.id;
                var label= layer.title || layer.name;
                var layerLab= OpenLayers.i18n(label);
                // convert HTML entities to get the right length :
                var entityBuffer= doc.createElement("textarea");
                entityBuffer.innerHTML= layerLab.replace(/</g,"&lt;").replace(/>/g,"&gt;");
                layerLab= entityBuffer.value;
                entityBuffer= null;
               /* if (layerLab.length >= Geoportal.Control.LayerSwitcher.LAYER_LABEL_MAXLENGTH) {
                    // FIXME : HTML tags within string
                    layerLab= layerLab.substring(0,Geoportal.Control.LayerSwitcher.LAYER_LABEL_REPLACEMENT_INDEX)+
                              Geoportal.Control.LayerSwitcher.LAYER_LABEL_SUFFIX_REPLACEMENT;
                }*/
                labelSpan.innerHTML= layerLab;
                labelSpan.className= "gpLayerSpanClass";
                labelSpan.title= OpenLayers.i18n(label);
                if (!layer.inRange) {
                    labelSpan.className+= "NotInRange";
                }
                if (layer.description || layer.dataURL || layer.metadataURL || layer.legends) {
                    labelSpan.style.cursor= "help";
                    // a pop-up for description, dataURL, metadataURL, ...
                    OpenLayers.Event.observe(
                        labelSpan,
                        "click",
                        OpenLayers.Function.bindAsEventListener(
                            this.onLabelClick,
                            ({
                                'inputElem': inputElem,
                                'layer': layer,
                                'layerSwitcher': this
                            })));
                }
                dg1.appendChild(labelSpan);
    
                //Layers order management:
                var buttons= doc.createElement('div');
                buttons.id='buttonsChangeOrder'+layer.id;
                buttons.className= 'gpButtonsChangeOrderClass';
                dg1.appendChild(buttons);
    
                // Moving a layer up ...
                var buttonUp= doc.createElement('div');
                buttonUp.id="buttonUp_" +layer.id;
                buttonUp.className= "gpButtonUp";
                // if it is the last displayed in layer switcher ...
                if (!lup) {
                    var dils= true;
                    for (j= i+1; j<l-1; j++) {
                        if (!layers[j].isBaseLayer && layers[j].displayInLayerSwitcher) {
                            dils= false;
                            break;
                        }
                    }
                    if (dils) {
                        buttonUp.className+= "Deactive";
                        lup= true;
                    }
                }
                OpenLayers.Event.observe(
                    buttonUp,
                    "click",
                    OpenLayers.Function.bindAsEventListener(
                        this.onButtonUpClick,
                        ({
                            'layerSwitcher':this,
                            'layerRank':i
                        })
                    )
                );
                buttons.appendChild(buttonUp);
    
                //Moving a layer down ...
                var buttonDown= doc.createElement('div');
                buttonDown.id="buttonDown_" +layer.id;
                buttonDown.className= "gpButtonDown";
                // if it is the first displayed in layer switcher ...
                if (!ldown) {
                    var dils= true;
                    for (j= i-1; j>=0; j--) {
                        if (!layers[j].isBaseLayer && layers[j].displayInLayerSwitcher) {
                            dils= false;
                            break;
                        }
                    }
                    if (dils) {
                        buttonDown.className+= "Deactive";
                        ldown= true;
                    }
                }
                OpenLayers.Event.observe(
                    buttonDown,
                    "click",
                    OpenLayers.Function.bindAsEventListener(
                        this.onButtonDownClick,
                        ({
                            'layerSwitcher':this,
                            'layerRank':i
                        })
                    )
                );
                buttons.appendChild(buttonDown);
                var ctrlId= 'loading_'+layer.id;
                var loadingCtrl= this.map.getControl(ctrlId);
                if (loadingCtrl) {
                    dg1.appendChild(loadingCtrl.div);
                } else {
                    var loadingCtrlDiv= doc.createElement('div');
                    loadingCtrlDiv.id= ctrlId;
                    loadingCtrlDiv.className= 'gpControlLoading olControlNoSelect';
                    loadingCtrl= new Geoportal.Control.Loading(
                                        layer, {
                                            id : loadingCtrlDiv.id,
                                            div: loadingCtrlDiv
                                        });
                    dg1.appendChild(loadingCtrlDiv);
                    this.map.addControl(loadingCtrl);
                }
    
                if (layer.preventControls['Geoportal.Control.BasicLayerToolbar']!==true &&
                    ((layer.view && (layer.view.drop || layer.view.zoomToExtent)) ||
                     (layer.opacity!=undefined))) {
                    ctrlId= 'basic_'+layer.id;
                    var basicCtrl= this.map.getControl(ctrlId);
                    if (basicCtrl) {
                        layerDiv.appendChild(basicCtrl.div);
                        for (var ibc= 0, lbc= basicCtrl.controls.length; ibc<lbc; ibc++) {
                            if (basicCtrl.controls[ibc] instanceof Geoportal.Control.LayerOpacity) {
                                basicCtrl.controls[ibc].refreshOpacity();
                                break;
                            }
                        }
                    } else {
                        var basicCtrlDiv= doc.createElement('div');
                        basicCtrlDiv.id= ctrlId;
                        basicCtrlDiv.className= 'gpControlBasicLayerToolbar olControlNoSelect';
                        var basicCtrl= new Geoportal.Control.BasicLayerToolbar(
                                                layer, {
                                                    id : basicCtrlDiv.id,
                                                    div: basicCtrlDiv
                                                });
                        layerDiv.appendChild(basicCtrlDiv);
                        this.map.addControl(basicCtrl);
                    }
                }
    
                if (layer.preventControls['Geoportal.Control.EditingToolbar']!==true) {
                    var preventDrawingControl= false;
                    if (typeof(Geoportal.Control.DrawingToolbar)=='function') {
                        var drawingControls= this.map.getControlsByClass('Geoportal.Control.DrawingToolbar');
                        if (drawingControls.length > 0) {
                            for (var dtc= 0, dtclen= drawingControls.length; dtc<dtclen; dtc++) {
                                if (drawingControls[dtc].mode=='single') {
                                    preventDrawingControl= true;
                                    if (!this.activeLayer) {
                                        this.setActiveLayer(drawingControls[dtc].layer);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    if (!preventDrawingControl) {
                        // editing toolbar (makes provision of ...) :
                        ctrlId= 'edit_'+layer.id;
                        var editCtrl= this.map.getControl(ctrlId);
                        if (editCtrl) {
                            layerDiv.appendChild(editCtrl.div);
                            if (editCtrl.div.childNodes.length>0) {
                                editCtrl.div.style.display= '';
                            } else {
                                editCtrl.div.style.display= 'none';
                            }
                        } else {
                            var editDiv= doc.createElement('div');
                            editDiv.id= ctrlId;
                            editDiv.className= 'gpControlEditingToolbar olControlNoSelect';
                            editDiv.style.display= 'none';
                            layerDiv.appendChild(editDiv);
                        }
                    }
                }
    
                if (layer.preventControls['Geoportal.Control.InformationToolbar']!==true) {
                    if (layer.legends && typeof(Geoportal.Control.InformationToolbar)=='function') {
                        ctrlId= 'info_'+layer.id;
                        var infoCtrl= this.map.getControl(ctrlId);
                        if (infoCtrl) {
                            layerDiv.appendChild(infoCtrl.div);
                            if (infoCtrl.div.childNodes.length>0) {
                                infoCtrl.div.style.display= '';
                            } else {
                                infoCtrl.div.style.display= 'none';
                            }
                        } else {
                            var infoDiv= doc.createElement('div');
                            infoDiv.id= ctrlId;
                            infoDiv.className= 'gpControlInfoToolbar';
                            var infoCtrl= new Geoportal.Control.InformationToolbar(layer, {
                                id : infoDiv.id,
                                div: infoDiv
                            });
                            layerDiv.appendChild(infoDiv);
                            this.map.addControl(infoCtrl);
                        }
                    }
                }
    
                this.dataLayers.push({
                    'layer': layer,
                    'inputElem': inputElem,
                    'labelSpan': labelSpan,
                    'layerDiv': layerDiv
                });
            }
            return {'drawn': drawn, 'lup': lup, 'ldown':ldown};
        }

  3. #3
    Membre habitué
    Homme Profil pro
    Inscrit en
    Février 2010
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 141
    Points : 156
    Points
    156
    Par défaut
    Je reviens sur cette discussion à propos de la taille du contrôle LayerSwitcher.

    Pour éviter les "..." j'ai ajouté, en fonction des noms de mes couches :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Geoportal.Control.LayerSwitcher.LAYER_LABEL_MAXLENGTH = 25;
    Geoportal.Control.LayerSwitcher.LAYER_LABEL_REPLACEMENT_INDEX = 22;
    Pour élargir le contrôle j'ai effectivement ajouté :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <style>
        .gpControlLayerSwitcher.olControlNoSelect.gpMainDivClass
        {
            width: 200px;
        }
    </style>
    Mais je sèche pour allonger le contrôle (et éviter la barre de défilement) : ajouter "height: 256px;" ne produit pas le résultat espéré.

  4. #4
    Membre averti
    Homme Profil pro
    Inscrit en
    Avril 2009
    Messages
    874
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations forums :
    Inscription : Avril 2009
    Messages : 874
    Points : 371
    Points
    371
    Par défaut
    Nickel
    Pour les générations futures, les lignes

    Geoportal.Control.LayerSwitcher.LAYER_LABEL_MAXLENGTH = 50;
    Geoportal.Control.LayerSwitcher.LAYER_LABEL_REPLACEMENT_INDEX = 47;

    sont à ajouter à la fin de la fonction StartAPI.

    Le style, la où vous voulez.

    Fin.

    Merci à tous.

  5. #5
    Membre habitué
    Homme Profil pro
    Inscrit en
    Février 2010
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 141
    Points : 156
    Points
    156
    Par défaut
    Personne n'a d'idée pour mon problème de hauteur de contrôle LayerSwitcher ?
    Comme je l'ai dit, spécifier la propriété "height" de la div de la classe "gpControlLayerSwitcher.olControlNoSelect.gpMainDivClass" ne donne pas le résultat souhaité.

  6. #6
    Membre averti Avatar de Zébulon-21
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    392
    Détails du profil
    Informations personnelles :
    Localisation : France, Côte d'Or (Bourgogne)

    Informations forums :
    Inscription : Mai 2009
    Messages : 392
    Points : 315
    Points
    315
    Par défaut
    Tu trouveras peut-être ton bonheur dans cette discussion

  7. #7
    Membre habitué
    Homme Profil pro
    Inscrit en
    Février 2010
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 141
    Points : 156
    Points
    156
    Par défaut
    Merci pour le conseil qui m'a aidé.

    Finallement j'ai réussi à éviter la barre de défilement avec l'ajout :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <style>
        .gpControlLayerSwitcher.olControlNoSelect.gpMainDivClass
        {
            width: 200px;
        }
        /* Hauteur des onglets pour éviter la barre de défilement */
        .gpGroupDivClass
        {
            min-height: 238px;
        }
    </style>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Fermer / ouvrir dynamiquement le cartouche des couches ?
    Par Zebulon777 dans le forum IGN API Géoportail
    Réponses: 7
    Dernier message: 25/06/2014, 13h39
  2. Réponses: 0
    Dernier message: 07/11/2009, 11h46

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