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

Bibliothèques & Frameworks Discussion :

Attribuer différentes couleurs aux markers [LeafLet]


Sujet :

Bibliothèques & Frameworks

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    335
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 335
    Points : 70
    Points
    70
    Par défaut Attribuer différentes couleurs aux markers
    Bonsoir à tous

    après plusieurs après midi de travail j'ai réussi à afficher la carte du monde. mais je bloque toujours sur ces markers

    je voudrais mettre un marker pour paris d'une couleur et des markers d'un 2ème couleur pour les autres lieux de ma variable destination.

    j'ai besoin de votre aide


    Code html : 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
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    <!DOCTYPE html>
    <html lang="fr">
    <head>
    <meta charset="utf-8">
    <title>[Leaflet] Animation déplacement</title>
    <meta name="author" content="Yann" >
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="desciption" content="[Leaflet] Déplacement animé de la carte d'un point à un autre.">
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.css">
    <script src="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.js"></script>
    <style>
    html, body {
      margin: 0;
      padding: 0;
      font: 1em/1.5 Verdana, sans-serif;
    }
    h1, h2, h3 {
      margin-bottom: .5em;
      color: #069;}
    #main {
      margin: 0 auto;
      max-width: 60em;
      border-top: 1px solid transparent;
    }
    .section {
      margin: 0 2em 1em;
    }
    #cde {
      position: relative;
      margin: 1em auto;
    }
    #cadre_carte {
      position: relative;
      height: 37em;
      margin: 0 auto;
      max-width: 50em;
      border: 5px solid #FFF;
      font-size: 1em;
      box-shadow: 0 2px 4px 2px #CCC;
    }
    #carte {
      height: 55%;
      width: 70%;
    }
    #menu_destination {
      display: inline-block;
      z-index: 100000;
      position: absolute;
      top: 1em;
      right: 1em;
      padding: .125em;
      min-width: 10em;
      border: 1px solid #abc;
      font: .8em/1.5 Verdana,sans-serif;
      background: #fff;
      box-shadow: 2px 2px 5px #ccc;
      cursor: pointer;
      -moz-user-select: none;
    }
    #menu_destination h1 {
      margin: 0;
      padding: 0;
      font-size: 1em;
      font-weight: normal;
      color: #000;
      text-align:center;
    }
    #menu_destination h1:hover {
      background: #f4f4f4;
    }
    #menu_destination ul {
      margin: 0;
      padding: 0;
      list-style: none;
      display:none;
    }
    #menu_destination ul li {
      padding: .25em 1em;
      line-height: 1.5em;
      background: #fff;
    }
    /* separator */
    #menu_destination ul li:empty {
      margin: .125em 0;
      padding: 0 1em 1px;
      background: #abc;
    }
    #menu_destination ul li[data-dest]:hover {
      background: #cde;
    }
    #menu_destination ul hr {
      margin: 0;
      padding: 0;
    }
     
    /* déclaration pour les markers */
    .circle {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle-marker {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
    }
    .circle-red {
      border: 5px solid #F00;
    }
    .circle-green {
      border: 5px solid #0A0;
    }
    .circle-animate {
      animation-name: show-hide;
      animation-duration: 1s;
      animation-iteration-count: infinite;
      transform: scale(1);
    }
    @keyframes show-hide {
      0%   { transform: scale(1);}
      50%  { transform: scale(.5);}
      100% { transform: scale(1);}
    }
    </style>
    </head>
    <body>
    <div id="main">
      <div class="header">
        <h1>[Leaflet] Animation déplacement</h1>
      </div>
      <div class="section">  
        <p>Déplacement animé de la carte d'un point à un autre.</p>
      </div>
      <div class="section">
        <div id="cadre_carte">
          <div id="carte"></div>
          <div id="menu_destination">
            <h1>Destination</h1>
            <ul>
              <li data-dest="paris"    >Paris</li>
              <li data-dest="cameroun" >Cameroun</li>
              <li data-dest="comores"  >Comores</li>
              <li data-dest="ethiopie" >Ethiopie</li>
              <li data-dest="guadeloupe"  >Guadeloupe</li>
              <li data-dest="guyane" >Guyane</li>
              <li data-dest="reunion"      >La R&eacute;union</li>
              <li data-dest="madagascar"      >Madagascar</li>         
              <li data-dest="martinique"      >Martinique</li>       
              <li data-dest="maurice"      >Ile Maurice</li>     
              <li data-dest="mayotte"      >Mayotte</li>         
              <li data-dest="tahiti"      >Tahiti</li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <script>
    var oMap;
    var animEnCours = false;
    var destination = {
        "paris" : {
            "libelle" : "Paris",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "cameroun" : {
            "libelle" : "Cameroun",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "comores" : {
            "libelle" : "Comores",
            "point" : L.latLng(-12.14, 44.25),
            "zoom" : 3.5,
        },
        "ethiopie" : {
            "libelle" : "Ethiopie",
            "point" : L.latLng(8.9800, 38.7989),
            "zoom" : 3.5,
        },
        "guadeloupe" : {
            "libelle" : "Guadeloupe",
            "point" : L.latLng(6.265, -61.551),
            "zoom" : 3.5,
        },
        "guyane" : {
            "libelle" : "Guyane",
            "point" : L.latLng(4.144817,-52.8442),
            "zoom" : 3.5,
        },
        "reunion" : {
            "libelle" : "La Réunion",
            "point" : L.latLng(-21.1151, 55.5363),
            "zoom" : 8,
        },
        "madagascar" : {
            "libelle" : "Madagascar",
            "point" : L.latLng(-19.1576, 47.2082),
            "zoom" : 3.5,
        },
        "martinique" : {
            "libelle" : "Martinique",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "maurice" : {
            "libelle" : "Maurice",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "mayotte" : {
            "libelle" : "Mayotte",
            "point" : L.latLng(-12.8096, 45.1307),
            "zoom" : 3.5,
        },
        "tahiti" : {
            "libelle" : "Tahiti",
            "point" : L.latLng(-17.6509, -149.426),
            "zoom" : 3.5,
        },
        //...
    };
    /*var destination = {
     
      'paris':    L.latLng(48.85342, 2.3488),
      'cameroun':      L.latLng(5.76463, 11.75537),
      'comores' :      L.latLng(-12.14, 44.25),
      'ethiopie' :  L.latLng(8.9800, 38.7989),
      'guadeloupe' :      L.latLng(16.265, -61.551),
      'guyane' :      L.latLng(4.144817,-52.8442),
      'reunion' :      L.latLng(-21.1151, 55.5363),
      'madagascar' :      L.latLng(-19.1576, 47.2082),
      'martinique' :      L.latLng(14.64, -61.01669),
      'maurice' :      L.latLng(-20.3484,57.5833),
      'mayotte' :      L.latLng(-12.8096, 45.1307),
      'tahiti' :      L.latLng(-17.6509, -149.426)
    };
    */
    // création des divIcon
    var oIconRed = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-red"></div>'
    });
    var oIconGreen = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-green"></div>'
    });
    // création des markers
    var oMarkerRed   = L.marker( [0,0], {icon: oIconRed});
    var oMarkerGreen = L.marker( [0,0], {icon: oIconGreen});
    // création de la carte
    var zoomInitial = 9; // ce que l'on modifie versus test5 9 au leu de 7
    var zoomTravel  = 3; 
    oMap = L.map('carte', {
        zoomAnimationThreshold: 20, 
        zoomControl: false,          // voir <a href="http://leafletjs.com/reference-1.1.0.html#map-zoomcontrol" target="_blank">http://leafletjs.com/reference-1.1.0...ap-zoomcontrol</a>
        duration: 5,
        center: [ 0, 0 ],
        zoom: 1.1 
    });
    oMap.addLayer( L.tileLayer(
        'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
        {
          attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }
      ));
    // fonction sur click oMap
    oMap.on('click', function (e) {
      // affiche marker vert au click
      oMarkerGreen.setLatLng([e.latlng.lat, e.latlng.lng]).addTo(this);
      oMarkerGreen.on('click', function (e) {
        this.remove(oMap);
      })
    });
     
    function swapMarker(where){
      // supprime marker rouge
      oMarkerRed.remove(oMap);
      // affiche marker vert
      oMarkerGreen.setLatLng(where).addTo(oMap);
      // autorise autre animation
      animEnCours = false;
    }
     
    function gotoDestination(where) {
      // si animation en cours on quitte
      if (animEnCours) {
        return;
      }
      animEnCours = true;
      var zoomCarte = oMap.getZoom();
      // récupération point de départ
      var pointDepart = oMap.hasLayer(oMarkerGreen) ? oMarkerGreen.getLatLng() : oMap.getCenter();
      // place les marker rouge et vert sur destination et départ
      oMarkerRed.setLatLng(where).addTo(oMap);
      oMarkerGreen.setLatLng(pointDepart).addTo(oMap);
      // calcul distance déplacement
      var distance = oMap.distance(pointDepart, where)/1000;
      // calcul durée déplacement
      var delay = distance / 2000;
      // accés direct si distance < 1000 km
      if (distance < 1000) {
      
        // réajuste position et zoom
       console.log(where); 
       switch(where) {
         default :  oMap.setView(L.latLng(0, 0), zoomInitial);
         break;
         case L.latLng(48.85342, 2.3488):
         oMap.setView(where,zoom);
         break;
         case L.latLng(16.265, -61.551):
         oMap.setView(where,8);
         break;}
        // change markers
        swapMarker(where);
      } 
      else {
         // défini action en fin de zoom
        oMap.once('zoomend', function () {
          // déplacement vers destination
          setTimeout(function () {
            // défini action en fin de déplacement
            oMap.once('moveend', function () {
              // on zooom sur destination
              setTimeout(function () {
          // réajuste position et zoom
         switch(where) {
         default :  oMap.setView(where, zoomInitial);
         break;
         case 'paris':
         oMap.setView(where,3);
         break;
         case 'guadeloupe':
         oMap.setView(where,9);
         break;
      }
            // change markers
                swapMarker(where);
              }, 500);  
            });
            // déplacement
            oMap.panTo(where, {
              animate: true,
              duration: delay
            });
          }, 500);
        });
        // ajuste le zoom minimum
        if (zoomCarte === zoomTravel) {
          oMap.fireEvent('zoomend');
        } 
        else {
          oMap.setZoom(zoomTravel);
        }
      }
    }
     
    // gestion du menu destinations
    var oTravel = document.querySelector('#menu_destination');
    oTravel.onclick = function (e) {
      var oSrc = e.target;
      var oDest = oSrc.getAttribute("data-dest");
      if (destination[oDest]) {
        this.querySelector('ul').style.display = 'none';
        gotoDestination(destination[oDest]);
      }
      else {
        this.querySelector('ul').style.display = 'block';
      }
    };
    oTravel.onmouseleave = function (e) {
      this.querySelector('ul').style.display = 'none';
    };
    </script>
    </body>
    </html>

    Merci beaucoup

  2. #2
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 232
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 232
    Points : 15 525
    Points
    15 525
    Par défaut
    dans la fonction "gotoDestination" vous utilisez déjà le marqueur vert pour le point de départ.
    donc si vous voulez utiliser un autre marqueur vert pour Paris à la place du rouge, vous devrez créer un deuxième marqueur vert pour ne pas toucher au marqueur vert du point de départ.

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    335
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 335
    Points : 70
    Points
    70
    Par défaut
    Bonjour,

    J'ai tenté d'ajouter une des lignes juste après la création du marker vert de manière à l'ajouter à la carte (ligne 233) .
    Vu que ça n'a pas fonctionné j'ai décidé comme Mathieu m'a écrit de mettre en commentaires toute la fonction "go to destination" (c'est ce que j'ai compris), mais sans plus de résultats .

    La carte ne s'affiche même plus.

    Voici le code

    Code html : 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
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    <!DOCTYPE html>
    <html lang="fr">
    <head>
    <meta charset="utf-8">
    <title>[Leaflet] Animation déplacement</title>
    <meta name="author" content="yann" >
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="desciption" content="[Leaflet] Déplacement animé de la carte d'un point à un autre.">
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.css">
    <script src="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.js"></script>
    <style>
    html, body {
      margin: 0;
      padding: 0;
      font: 1em/1.5 Verdana, sans-serif;
    }
    h1, h2, h3 {
      margin-bottom: .5em;
      color: #069;}
    #main {
      margin: 0 auto;
      max-width: 60em;
      border-top: 1px solid transparent;
    }
    .section {
      margin: 0 2em 1em;
    }
    #cde {
      position: relative;
      margin: 1em auto;
    }
    #cadre_carte {
      position: relative;
      height: 37em;
      margin: 0 auto;
      max-width: 50em;
      border: 5px solid #FFF;
      font-size: 1em;
      box-shadow: 0 2px 4px 2px #CCC;
    }
    #carte {
      height: 55%;
      width: 70%;
    }
    #menu_destination {
      display: inline-block;
      z-index: 100000;
      position: absolute;
      top: 1em;
      right: 1em;
      padding: .125em;
      min-width: 10em;
      border: 1px solid #abc;
      font: .8em/1.5 Verdana,sans-serif;
      background: #fff;
      box-shadow: 2px 2px 5px #ccc;
      cursor: pointer;
      -moz-user-select: none;
    }
    #menu_destination h1 {
      margin: 0;
      padding: 0;
      font-size: 1em;
      font-weight: normal;
      color: #000;
      text-align:center;
    }
    #menu_destination h1:hover {
      background: #f4f4f4;
    }
    #menu_destination ul {
      margin: 0;
      padding: 0;
      list-style: none;
      display:none;
    }
    #menu_destination ul li {
      padding: .25em 1em;
      line-height: 1.5em;
      background: #fff;
    }
    /* separator */
    #menu_destination ul li:empty {
      margin: .125em 0;
      padding: 0 1em 1px;
      background: #abc;
    }
    #menu_destination ul li[data-dest]:hover {
      background: #cde;
    }
    #menu_destination ul hr {
      margin: 0;
      padding: 0;
    }
     
    /* déclaration pour les markers */
    .circle {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle-marker {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
    }
    .circle-red {
      border: 5px solid #F00;
    }
    .circle-green {
      border: 5px solid #0A0;
    }
    .circle-animate {
      animation-name: show-hide;
      animation-duration: 1s;
      animation-iteration-count: infinite;
      transform: scale(1);
    }
    @keyframes show-hide {
      0%   { transform: scale(1);}
      50%  { transform: scale(.5);}
      100% { transform: scale(1);}
    }
    </style>
    </head>
    <body>
    <div id="main">
      <div class="section">
        <div id="cadre_carte">
          <div id="carte"></div>
        </div>
      </div>
    </div>
    <script>
    var oMap;
    var animEnCours = false;
    var destination = {
        "paris" : {
            "libelle" : "Paris",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "cameroun" : {
            "libelle" : "Cameroun",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "comores" : {
            "libelle" : "Comores",
            "point" : L.latLng(-12.14, 44.25),
            "zoom" : 3.5,
        },
        "ethiopie" : {
            "libelle" : "Ethiopie",
            "point" : L.latLng(8.9800, 38.7989),
            "zoom" : 3.5,
        },
        "guadeloupe" : {
            "libelle" : "Guadeloupe",
            "point" : L.latLng(6.265, -61.551),
            "zoom" : 3.5,
        },
        "guyane" : {
            "libelle" : "Guyane",
            "point" : L.latLng(4.144817,-52.8442),
            "zoom" : 3.5,
        },
        "reunion" : {
            "libelle" : "La Réunion",
            "point" : L.latLng(-21.1151, 55.5363),
            "zoom" : 8,
        },
        "madagascar" : {
            "libelle" : "Madagascar",
            "point" : L.latLng(-19.1576, 47.2082),
            "zoom" : 3.5,
        },
        "martinique" : {
            "libelle" : "Martinique",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "maurice" : {
            "libelle" : "Maurice",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "mayotte" : {
            "libelle" : "Mayotte",
            "point" : L.latLng(-12.8096, 45.1307),
            "zoom" : 3.5,
        },
        "tahiti" : {
            "libelle" : "Tahiti",
            "point" : L.latLng(-17.6509, -149.426),
            "zoom" : 3.5,
        },
        //...
    };
    /*var destination = {
     
      'paris':    L.latLng(48.85342, 2.3488),
      'cameroun':      L.latLng(5.76463, 11.75537),
      'comores' :      L.latLng(-12.14, 44.25),
      'ethiopie' :  L.latLng(8.9800, 38.7989),
      'guadeloupe' :      L.latLng(16.265, -61.551),
      'guyane' :      L.latLng(4.144817,-52.8442),
      'reunion' :      L.latLng(-21.1151, 55.5363),
      'madagascar' :      L.latLng(-19.1576, 47.2082),
      'martinique' :      L.latLng(14.64, -61.01669),
      'maurice' :      L.latLng(-20.3484,57.5833),
      'mayotte' :      L.latLng(-12.8096, 45.1307),
      'tahiti' :      L.latLng(-17.6509, -149.426)
    };
    */
    // création des divIcon
    var oIconRed = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-red"></div>'
    });
    var oIconGreen = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-green"></div>'
    });
    // création des markers
    var oMarkerRed   = L.marker( [48.8534,2.3488], {icon: oIconRed});
    var oMarkerGreen = L.marker( [11.75537,5.76463], {icon: oIconGreen});
    oMarkerGreen.addTo(oMap);
    // création de la carte
    var zoomInitial = 9; // ce que l'on modifie versus test5 9 au leu de 7
    var zoomTravel  = 3; 
    oMap = L.map('carte', {
        zoomAnimationThreshold: 20, 
        zoomControl: false,          // voir <a href="http://leafletjs.com/reference-1.1.0.html#map-zoomcontrol" target="_blank">http://leafletjs.com/reference-1.1.0...ap-zoomcontrol</a>
        duration: 5,
        center: [ 0, 0 ],
        zoom: 1.1 
    });
    oMap.addLayer( L.tileLayer(
        'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
        {
          attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }
      ));
    // fonction sur click oMap
    oMap.on('click', function (e) {
      // affiche marker vert au click
      oMarkerGreen.setLatLng([e.latlng.lat, e.latlng.lng]).addTo(this);
      oMarkerGreen.on('click', function (e) {
        this.remove(oMap);
      })
    });
     
    function swapMarker(where){
      // supprime marker rouge
      oMarkerRed.remove(oMap);
      // affiche marker vert
      oMarkerGreen.setLatLng(where).addTo(oMap);
      // autorise autre animation
      animEnCours = false;
    }
     
     
    /*function gotoDestination(where) {
      // si animation en cours on quitte
      if (animEnCours) {
        return;
      }
      animEnCours = true;
      var zoomCarte = oMap.getZoom();
      // récupération point de départ
      var pointDepart = oMap.hasLayer(oMarkerGreen) ? oMarkerGreen.getLatLng() : oMap.getCenter();
      // place les marker rouge et vert sur destination et départ
      oMarkerRed.setLatLng(where).addTo(oMap);
      oMarkerGreen.setLatLng(pointDepart).addTo(oMap);
      // calcul distance déplacement
      var distance = oMap.distance(pointDepart, where)/1000;
      // calcul durée déplacement
      var delay = distance / 2000;
      // accés direct si distance < 1000 km
      if (distance < 1000) {
      
        // réajuste position et zoom
       console.log(where); 
       switch(where) {
         default :  oMap.setView(L.latLng(0, 0), zoomInitial);
         break;
         case L.latLng(48.85342, 2.3488):
         oMap.setView(where,zoom);
         break;
         case L.latLng(16.265, -61.551):
         oMap.setView(where,8);
         break;}
        // change markers
        swapMarker(where);
      } 
      else {
         // défini action en fin de zoom
        oMap.once('zoomend', function () {
          // déplacement vers destination
          setTimeout(function () {
            // défini action en fin de déplacement
            oMap.once('moveend', function () {
              // on zooom sur destination
              setTimeout(function () {
          // réajuste position et zoom
         switch(where) {
         default :  oMap.setView(where, zoomInitial);
         break;
         case 'paris':
         oMap.setView(where,3);
         break;
         case 'guadeloupe':
         oMap.setView(where,9);
         break;
      }
            // change markers
                swapMarker(where);
              }, 500);  
            });
            // déplacement
            oMap.panTo(where, {
              animate: true,
              duration: delay
            });
          }, 500);
        });
        // ajuste le zoom minimum
        if (zoomCarte === zoomTravel) {
          oMap.fireEvent('zoomend');
        } 
        else {
          oMap.setZoom(zoomTravel);
        }
      }
    }*/
     
    // gestion du menu destinations
    var oTravel = document.querySelector('#menu_destination');
    oTravel.onclick = function (e) {
      var oSrc = e.target;
      var oDest = oSrc.getAttribute("data-dest");
      if (destination[oDest]) {
        this.querySelector('ul').style.display = 'none';
        gotoDestination(destination[oDest]);
      }
      else {
        this.querySelector('ul').style.display = 'block';
      }
    };
    oTravel.onmouseleave = function (e) {
      this.querySelector('ul').style.display = 'none';
    };
    </script>
    </body>
    </html>

    Pouvez-vous m'aider ?

    Merci de vos réponses

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    335
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 335
    Points : 70
    Points
    70
    Par défaut
    Bonne Année à tous,

    J'ai finalement réussi à afficher mes marqueurs sur la carte du monde.
    J'ai ensuite essayé de modifier la couleur de chaque marker pour les différencier il me faudrait maintenant afficher du pays en question à coté du marker.

    Code html : 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
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    <!DOCTYPE html>
    <html lang="fr">
    <head>
    <meta charset="utf-8">
    <title>[Leaflet] Animation déplacement</title>
    <meta name="author" content="yann" >
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="desciption" content="[Leaflet] Déplacement animé de la carte d'un point à un autre.">
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.css">
    <script src="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.js"></script>
    <style>
    html, body {
      margin: 0;
      padding: 0;
      font: 1em/1.5 Verdana, sans-serif;
    }
    h1, h2, h3 {
      margin-bottom: .5em;
      color: #069;}
    #main {
      margin: 0 auto;
      max-width: 60em;
      border-top: 1px solid transparent;
    }
    .section {
      margin: 0 2em 1em;
    }
    #cde {
      position: relative;
      margin: 1em auto;
    }
    #cadre_carte {
      position: relative;
      height: 37em;
      margin: 0 auto;
      max-width: 50em;
      border: 5px solid #FFF;
      font-size: 1em;
      box-shadow: 0 2px 4px 2px #CCC;
    }
    #carte {
      height: 55%;
      width: 70%;
    }
    #menu_destination {
      display: inline-block;
      z-index: 100000;
      position: absolute;
      top: 1em;
      right: 1em;
      padding: .125em;
      min-width: 10em;
      border: 1px solid #abc;
      font: .8em/1.5 Verdana,sans-serif;
      background: #fff;
      box-shadow: 2px 2px 5px #ccc;
      cursor: pointer;
      -moz-user-select: none;
    }
    #menu_destination h1 {
      margin: 0;
      padding: 0;
      font-size: 1em;
      font-weight: normal;
      color: #000;
      text-align:center;
    }
    #menu_destination h1:hover {
      background: #f4f4f4;
    }
    #menu_destination ul {
      margin: 0;
      padding: 0;
      list-style: none;
      display:none;
    }
    #menu_destination ul li {
      padding: .25em 1em;
      line-height: 1.5em;
      background: #fff;
    }
    /* separator */
    #menu_destination ul li:empty {
      margin: .125em 0;
      padding: 0 1em 1px;
      background: #abc;
    }
    #menu_destination ul li[data-dest]:hover {
      background: #cde;
    }
    #menu_destination ul hr {
      margin: 0;
      padding: 0;
    }
     
    /* déclaration pour les markers */
    .circle {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle-marker {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
    }
    .circle-red {
      border: 5px solid #F00;
    }
    .circle-green {
      border: 5px solid #0A0;
    }
    .circle-orange {
      border: 5px solid #F63;
    }
    .circle-bleu {
      border: 5px solid #00F;
    }
    .circle-violet {
      border: 5px solid #909;
    }
    .circle-noir {
      border: 5px solid #FFF;
    }
    .circle-animate {
      animation-name: show-hide;
      animation-duration: 1s;
      animation-iteration-count: infinite;
      transform: scale(1);
    }
    @keyframes show-hide {
      0%   { transform: scale(1);}
      50%  { transform: scale(.5);}
      100% { transform: scale(1);}
    }
    </style>
    </head>
    <body>
    <div id="main">
      <div class="header">
        <h1>[Leaflet] Animation déplacement</h1>
      </div>
      <div class="section">  
        <p>Déplacement animé de la carte d'un point à un autre.</p>
      </div>
      <div class="section">
        <div id="cadre_carte">
          <div id="carte"></div>
          <div id="menu_destination">
            <h1>Destination</h1>
            <ul>
              <li data-dest="paris"    >Paris</li>
              <li data-dest="cameroun" >Cameroun</li>
              <li data-dest="comores"  >Comores</li>
              <li data-dest="ethiopie" >Ethiopie</li>
              <li data-dest="guadeloupe"  >Guadeloupe</li>
              <li data-dest="guyane" >Guyane</li>
              <li data-dest="reunion"      >La R&eacute;union</li>
              <li data-dest="madagascar"      >Madagascar</li>         
              <li data-dest="martinique"      >Martinique</li>       
              <li data-dest="maurice"      >Ile Maurice</li>     
              <li data-dest="mayotte"      >Mayotte</li>         
              <li data-dest="tahiti"      >Tahiti</li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <script>
    var oMap;
    var animEnCours = false;
    var destination = {
        "paris" : {
            "libelle" : "Paris",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "cameroun" : {
            "libelle" : "Cameroun",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "comores" : {
            "libelle" : "Comores",
            "point" : L.latLng(-12.14, 44.25),
            "zoom" : 3.5,
        },
        "ethiopie" : {
            "libelle" : "Ethiopie",
            "point" : L.latLng(8.9800, 38.7989),
            "zoom" : 3.5,
        },
        "guadeloupe" : {
            "libelle" : "Guadeloupe",
            "point" : L.latLng(6.265, -61.551),
            "zoom" : 3.5,
        },
        "guyane" : {
            "libelle" : "Guyane",
            "point" : L.latLng(4.144817,-52.8442),
            "zoom" : 3.5,
        },
        "reunion" : {
            "libelle" : "La Réunion",
            "point" : L.latLng(-21.1151, 55.5363),
            "zoom" : 8,
        },
        "madagascar" : {
            "libelle" : "Madagascar",
            "point" : L.latLng(-19.1576, 47.2082),
            "zoom" : 3.5,
        },
        "martinique" : {
            "libelle" : "Martinique",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "maurice" : {
            "libelle" : "Maurice",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "mayotte" : {
            "libelle" : "Mayotte",
            "point" : L.latLng(-12.8096, 45.1307),
            "zoom" : 3.5,
        },
        "tahiti" : {
            "libelle" : "Tahiti",
            "point" : L.latLng(-17.6509, -149.426),
            "zoom" : 3.5,
        },
        //...
    };
    /*var destination = {
     
      'paris':    L.latLng(48.85342, 2.3488),
      'cameroun':      L.latLng(5.76463, 11.75537),
      'comores' :      L.latLng(-12.14, 44.25),
      'ethiopie' :  L.latLng(8.9800, 38.7989),
      'guadeloupe' :      L.latLng(16.265, -61.551),
      'guyane' :      L.latLng(4.144817,-52.8442),
      'reunion' :      L.latLng(-21.1151, 55.5363),
      'madagascar' :      L.latLng(-19.1576, 47.2082),
      'martinique' :      L.latLng(14.64, -61.01669),
      'maurice' :      L.latLng(-20.3484,57.5833),
      'mayotte' :      L.latLng(-12.8096, 45.1307),
      'tahiti' :      L.latLng(-17.6509, -149.426)
    };
    */
    // création des divIcon
    var oIconRed = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-red"></div>'
    });
    var oIconGreen = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-green"></div>'
    });
    var oIconOrange = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-orange"></div>'
    });
    var oIconBleu = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-bleu"></div>'
    });
    var oIconViolet = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-violet"></div>'
    });
    var oIconNoir = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-noir"></div>'
    });
    // création des markers
    var oMarkerRed   = L.marker( [48.85342, 2.3488], {icon: oIconRed});
    var oMarkerGreen = L.marker( [5.76463, 11.75537], {icon: oIconGreen});
    var oMarkerBleu1 = L.marker( [-12.14, 44.25], {icon: oIconBleu});
    var oMarkerOrange1 = L.marker( [8.9800, 38.7989], {icon: oIconOrange});
    var oMarkerViolet1 = L.marker( [16.265, -61.551], {icon: oIconViolet});
    var oMarkerBleu2 = L.marker( [4.144817,-52.8442], {icon: oIconBleu});
    var oMarkerOrange2 = L.marker( [-21.1151, 55.5363], {icon: oIconOrange});
    var oMarkerNoir = L.marker( [-19.1576, 47.2082], {icon: oIconNoir});
    var oMarkerBleu3 = L.marker( [14.64, -61.01669], {icon: oIconBleu});
    var oMarkerViolet2 = L.marker( [-20.3484,57.5833], {icon: oIconViolet});
    var oMarkerOrange3 = L.marker( [-12.8096, 45.1307], {icon: oIconOrange});
    var oMarkerGreen11 = L.marker( [-17.6509, -149.426], {icon: oIconGreen});
    // création de la carte
    var zoomInitial = 9; // ce que l'on modifie versus test5 9 au leu de 7
    var zoomTravel  = 3; 
    oMap = L.map('carte', {
        zoomAnimationThreshold: 20, 
        zoomControl: false,          // voir <a href="http://leafletjs.com/reference-1.1.0.html#map-zoomcontrol" target="_blank">http://leafletjs.com/reference-1.1.0...ap-zoomcontrol</a>
        duration: 5,
        center: [ 0, 0 ],
        zoom: 1.1 
    });
    oMap.addLayer( L.tileLayer(
        'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
        {
          attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }
      ));
    // place les marker rouge et vert sur destination et départ
        oMarkerRed.addTo(oMap); 
        oMarkerGreen.addTo(oMap);   
        oMarkerBleu1.addTo(oMap);    
        oMarkerOrange1.addTo(oMap);    
        oMarkerViolet1.addTo(oMap);    
        oMarkerBleu2.addTo(oMap);    
        oMarkerOrange2.addTo(oMap);    
        oMarkerNoir.addTo(oMap);    
        oMarkerBleu3.addTo(oMap);    
        oMarkerViolet2.addTo(oMap);    
        oMarkerOrange3.addTo(oMap);    
        oMarkerGreen11.addTo(oMap);   
    // fonction sur click oMap
    oMap.on('click', function (e) {
      // affiche marker vert au click
      oMarkerGreen.setLatLng([e.latlng.lat, e.latlng.lng]).addTo(this);
      oMarkerGreen.on('click', function (e) {
        this.remove(oMap);
      })
    });
     
    function swapMarker(where){
      // supprime marker rouge
      oMarkerRed.remove(oMap);
      // affiche marker vert
      oMarkerGreen.setLatLng(where).addTo(oMap);
      // autorise autre animation
      animEnCours = false;
    }
     
    function gotoDestination(where) {
      // si animation en cours on quitte
      if (animEnCours) {
        return;
      }
      animEnCours = true;
      var zoomCarte = oMap.getZoom();
      // récupération point de départ
      var pointDepart = oMap.hasLayer(oMarkerGreen) ? oMarkerGreen.getLatLng() : oMap.getCenter();
      // place les marker rouge et vert sur destination et départ
      oMarkerRed.setLatLng(where).addTo(oMap);
      oMarkerGreen.setLatLng(pointDepart).addTo(oMap);
      // calcul distance déplacement
      var distance = oMap.distance(pointDepart, where)/1000;
      // calcul durée déplacement
      var delay = distance / 2000;
      // accés direct si distance < 1000 km
      if (distance < 1000) {
      
        // réajuste position et zoom
       console.log(where); 
       switch(where) {
         default :  oMap.setView(L.latLng(0, 0), zoomInitial);
         break;
         case L.latLng(48.85342, 2.3488):
         oMap.setView(where,zoom);
         break;
         case L.latLng(16.265, -61.551):
         oMap.setView(where,8);
         break;}
        // change markers
        swapMarker(where);
      } 
      else {
         // défini action en fin de zoom
        oMap.once('zoomend', function () {
          // déplacement vers destination
          setTimeout(function () {
            // défini action en fin de déplacement
            oMap.once('moveend', function () {
              // on zooom sur destination
              setTimeout(function () {
          // réajuste position et zoom
         switch(where) {
         default :  oMap.setView(where, zoomInitial);
         break;
         case 'paris':
         oMap.setView(where,3);
         break;
         case 'guadeloupe':
         oMap.setView(where,9);
         break;
      }
            // change markers
                swapMarker(where);
              }, 500);  
            });
            // déplacement
            oMap.panTo(where, {
              animate: true,
              duration: delay
            });
          }, 500);
        });
        // ajuste le zoom minimum
        if (zoomCarte === zoomTravel) {
          oMap.fireEvent('zoomend');
        } 
        else {
          oMap.setZoom(zoomTravel);
        }
      }
    }
     
    // gestion du menu destinations
    var oTravel = document.querySelector('#menu_destination');
    oTravel.onclick = function (e) {
      var oSrc = e.target;
      var oDest = oSrc.getAttribute("data-dest");
      if (destination[oDest]) {
        this.querySelector('ul').style.display = 'none';
        gotoDestination(destination[oDest]);
      }
      else {
        this.querySelector('ul').style.display = 'block';
      }
    };
    oTravel.onmouseleave = function (e) {
      this.querySelector('ul').style.display = 'none';
    };
    </script>
    </body>
    </html>

    merci de votre aide

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    335
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 335
    Points : 70
    Points
    70
    Par défaut [leaflet] Affichage du nom de pays à coté des markers
    bonjour à tous,

    j'ai réussi déjà à mettre en place chaque marker que je voulais avec celui pour Paris en rouge et les autres en noir.
    Mais j'aimerais toujours savoir comment afficher à côté de chaque marker le pays en question et puis en regardant la carte je me suis aperçu que certains markers comme la guadeloupe et la martinique d'une part et mayotte, madagascar et les comores de l'autre part, qui se superposent, ce qui gêne pour la lecture.
    Enfin, je voudrais mettre la carte en fond d'écran ; est-ce possible ?

    Je vous donne mon code:

    Code html : 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
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    <!DOCTYPE html>
    <html lang="fr">
    <head>
    <meta charset="utf-8">
    <title>[Leaflet] Animation déplacement</title>
    <meta name="author" content="yann" >
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="desciption" content="[Leaflet] Déplacement animé de la carte d'un point à un autre.">
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.css">
    <script src="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.js"></script>
    <style>
    html, body {
      margin: 0;
      padding: 0;
      font: 1em/1.5 Verdana, sans-serif;
    }
    h1, h2, h3 {
      margin-bottom: .5em;
      color: #069;}
    #main {
      margin: 0 auto;
      max-width: 60em;
      border-top: 1px solid transparent;
    }
    .section {
      margin: 0 2em 1em;
    }
    #cde {
      position: relative;
      margin: 1em auto;
    }
    #cadre_carte {
      position: relative;
      height: 37em;
      margin: 0 auto;
      max-width: 75em;
      border: 5px   font-size: 1em;
      box-shadow: 0 2px 4px 2px #CCC;
    }
    #carte {
      height: 90%;
      width: 55%;
    }
    #menu_destination {
      display: inline-block;
      z-index: 100000;
      position: absolute;
      top: 1em;
      right: 1em;
      padding: .125em;
      min-width: 10em;
      border: 1px solid #abc;
      font: .8em/1.5 Verdana,sans-serif;
      background: #fff;
      box-shadow: 2px 2px 5px #ccc;
      cursor: pointer;
      -moz-user-select: none;
    }
    #menu_destination h1 {
      margin: 0;
      padding: 0;
      font-size: 1em;
      font-weight: normal;
      color: #000;
      text-align:center;
    }
    #menu_destination h1:hover {
      background: #f4f4f4;
    }
    #menu_destination ul {
      margin: 0;
      padding: 0;
      list-style: none;
      display:none;
    }
    #menu_destination ul li {
      padding: .25em 1em;
      line-height: 1.5em;
      background: #fff;
    }
    /* separator */
    #menu_destination ul li:empty {
      margin: .125em 0;
      padding: 0 1em 1px;
      background: #abc;
    }
    #menu_destination ul li[data-dest]:hover {
      background: #cde;
    }
    #menu_destination ul hr {
      margin: 0;
      padding: 0;
    }
     
    /* déclaration pour les markers */
    .circle {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle2 {
      box-sizing: border-box;
      width: 15px;
      height: 15px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle3 {
      box-sizing: border-box;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle4 {
      box-sizing: border-box;
      width: 25px;
      height: 25px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle-marker {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
    }
    .circle-red {
      border: 5px solid #F00;
    }
    .circle-green {
      border: 5px solid #0A0;
    }
    .circle-orange {
      border: 5px solid #F63;
    }
    .circle-bleu {
      border: 5px solid #00F;
    }
    .circle-violet {
      border: 5px solid #909;
    }
    .circle-noir {
      border: 4px solid #000;
    }
    .circle-noir1 {
      border: 2px solid #000;
    }
    .circle-animate {
      animation-name: show-hide;
      animation-duration: 1s;
      animation-iteration-count: infinite;
      transform: scale(1);
    }
    @keyframes show-hide {
      0%   { transform: scale(1);}
      50%  { transform: scale(.5);}
      100% { transform: scale(1);}
    }
    </style>
    </head>
    <body>
    <div id="main">
      <div class="header">
        <h1>[Leaflet] Animation déplacement</h1>
      </div>
      <div class="section">  
        <p>Déplacement animé de la carte d'un point à un autre.</p>
      </div>
      <div class="section">
        <div id="cadre_carte">
          <div id="carte"></div>
          <div id="menu_destination">
            <h1>Destination</h1>
            <ul>
              <li data-dest="paris"    >Paris</li>
              <li data-dest="cameroun" >Cameroun</li>
              <li data-dest="comores"  >Comores</li>
              <li data-dest="ethiopie" >Ethiopie</li>
              <li data-dest="guadeloupe"  >Guadeloupe</li>
              <li data-dest="guyane" >Guyane</li>
              <li data-dest="reunion"      >La R&eacute;union</li>
              <li data-dest="madagascar"      >Madagascar</li>         
              <li data-dest="martinique"      >Martinique</li>       
              <li data-dest="maurice"      >Ile Maurice</li>     
              <li data-dest="mayotte"      >Mayotte</li>         
              <li data-dest="tahiti"      >Tahiti</li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <script>
    var oMap;
    var animEnCours = false;
    var destination = {
        "paris" : {
            "libelle" : "Paris",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "cameroun" : {
            "libelle" : "Cameroun",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "comores" : {
            "libelle" : "Comores",
            "point" : L.latLng(-11.72, 43.25),
            "zoom" : 3.5,
        },
        "ethiopie" : {
            "libelle" : "Ethiopie",
            "point" : L.latLng(8.9800, 38.7989),
            "zoom" : 3.5,
        },
        "guadeloupe" : {
            "libelle" : "Guadeloupe",
            "point" : L.latLng(6.265, -61.551),
            "zoom" : 3.5,
        },
        "guyane" : {
            "libelle" : "Guyane",
            "point" : L.latLng(4.144817,-52.8442),
            "zoom" : 3.5,
        },
        "reunion" : {
            "libelle" : "La Réunion",
            "point" : L.latLng(-21.1151, 55.5363),
            "zoom" : 8,
        },
        "madagascar" : {
            "libelle" : "Madagascar",
            "point" : L.latLng(-18.77, 46.9),
            "zoom" : 3.5,
        },
        "martinique" : {
            "libelle" : "Martinique",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "maurice" : {
            "libelle" : "Maurice",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "mayotte" : {
            "libelle" : "Mayotte",
            "point" : L.latLng(-12.768,45.2286),
            "zoom" : 3.5,
        },
        "tahiti" : {
            "libelle" : "Tahiti",
            "point" : L.latLng(-17.6509, -149.426),
            "zoom" : 3.5,
        },
        //...
    };
    /*var destination = {
     
      'paris':    L.latLng(48.85342, 2.3488),
      'cameroun':      L.latLng(5.76463, 11.75537),
      'comores' :      L.latLng(-11.72, 43.25),
      'ethiopie' :  L.latLng(8.9800, 38.7989),
      'guadeloupe' :      L.latLng(16.265, -61.551),
      'guyane' :      L.latLng(4.144817,-52.8442),
      'reunion' :      L.latLng(-21.1151, 55.5363),
      'madagascar' :      L.latLng(-18.77, 46.9),
      'martinique' :      L.latLng(14.64, -61.01669),
      'maurice' :      L.latLng(-20.3484,57.5833),
      'mayotte' :      L.latLng(-12.768,45.2286),
      'tahiti' :      L.latLng(-17.6509, -149.426)
    };
    */
    // création des divIcon
    var oIconRed = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-red"></div>'
    });
    var oIconGreen = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-green"></div>'
    });
    var oIconOrange = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-orange"></div>'
    });
    var oIconBleu = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-bleu"></div>'
    });
    var oIconViolet = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-violet"></div>'
    });
    var oIconNoir = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-noir"></div>'
    });
    var oIconNoir1a = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle3 circle-noir"></div>'
    });
    var oIconNoir1b = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle4 circle-noir1"></div>'
    });
    // création des markers
    //paris
    var oMarkerRed   = L.marker( [48.85342, 2.3488], {icon: oIconRed});
    //cameroun
    var oMarkerNoir = L.marker( [5.76463, 11.75537], {icon: oIconNoir});
    //comores
    var oMarkerNoir1 = L.marker( [-11.72, 43.25], {icon: oIconNoir});
    //ethiopie
    var oMarkerNoir2 = L.marker( [8.9800, 38.7989], {icon: oIconNoir});
    //guadeloupe
    var oMarkerNoir3 = L.marker( [16.265, -61.551], {icon: oIconNoir1b});
    //guyane
    var oMarkerNoir4 = L.marker( [4.144817,-52.8442], {icon: oIconNoir});
    //la réunion
    var oMarkerNoir5 = L.marker( [-21.1151, 55.5363], {icon: oIconNoir1a});
    //madagascar
    var oMarkerNoir6 = L.marker( [-18.77, 46.9], {icon: oIconNoir});
    //martinique
    var oMarkerNoir7 = L.marker( [14.64, -61.01669], {icon: oIconNoir});
    //maurice
    var oMarkerNoir8 = L.marker( [-20.3484,57.5833], {icon: oIconNoir});
    //mayotte
    var oMarkerNoir9 = L.marker( [-12.768,45.2286], {icon: oIconNoir1a});
    //tahiti
    var oMarkerNoir10 = L.marker( [-17.6509, -149.426], {icon: oIconNoir});
    // création de la carte
    var zoomInitial = 9; // ce que l'on modifie versus test5 9 au leu de 7
    var zoomTravel  = 3; 
    oMap = L.map('carte', {
        zoomAnimationThreshold: 20, 
        zoomControl: false,          // voir <a href="http://leafletjs.com/reference-1.1.0.html#map-zoomcontrol" target="_blank">http://leafletjs.com/reference-1.1.0...ap-zoomcontrol</a>
        duration: 5,
        center: [ 0, 0 ],
        zoom: 1.1 
    });
    oMap.addLayer( L.tileLayer(
        'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
        {
          attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }
      ));
    // place les marker rouge et vert sur destination et départ
        oMarkerRed.addTo(oMap); 
        oMarkerNoir.addTo(oMap);   
        oMarkerNoir1.addTo(oMap);    
        oMarkerNoir2.addTo(oMap);    
        oMarkerNoir3.addTo(oMap);    
        oMarkerNoir4.addTo(oMap);    
        oMarkerNoir5.addTo(oMap);    
        oMarkerNoir6.addTo(oMap);    
        oMarkerNoir7.addTo(oMap);    
        oMarkerNoir8.addTo(oMap);    
        oMarkerNoir9.addTo(oMap);    
        oMarkerNoir10.addTo(oMap);   
    // fonction sur click oMap
    oMap.on('click', function (e) {
      // affiche marker vert au click
      oMarkerGreen.setLatLng([e.latlng.lat, e.latlng.lng]).addTo(this);
      oMarkerGreen.on('click', function (e) {
        this.remove(oMap);
      })
    });
     
    function swapMarker(where){
      // supprime marker rouge
      oMarkerRed.remove(oMap);
      // affiche marker vert
      oMarkerGreen.setLatLng(where).addTo(oMap);
      // autorise autre animation
      animEnCours = false;
    }
     
    function gotoDestination(where) {
      // si animation en cours on quitte
      if (animEnCours) {
        return;
      }
      animEnCours = true;
      var zoomCarte = oMap.getZoom();
      // récupération point de départ
      var pointDepart = oMap.hasLayer(oMarkerGreen) ? oMarkerGreen.getLatLng() : oMap.getCenter();
      // place les marker rouge et vert sur destination et départ
      oMarkerRed.setLatLng(where).addTo(oMap);
      oMarkerGreen.setLatLng(pointDepart).addTo(oMap);
      // calcul distance déplacement
      var distance = oMap.distance(pointDepart, where)/1000;
      // calcul durée déplacement
      var delay = distance / 2000;
      // accés direct si distance < 1000 km
      if (distance < 1000) {
      
        // réajuste position et zoom
       console.log(where); 
       switch(where) {
         default :  oMap.setView(L.latLng(0, 0), zoomInitial);
         break;
         case L.latLng(48.85342, 2.3488):
         oMap.setView(where,zoom);
         break;
         case L.latLng(16.265, -61.551):
         oMap.setView(where,8);
         break;}
        // change markers
        swapMarker(where);
      } 
      else {
         // défini action en fin de zoom
        oMap.once('zoomend', function () {
          // déplacement vers destination
          setTimeout(function () {
            // défini action en fin de déplacement
            oMap.once('moveend', function () {
              // on zooom sur destination
              setTimeout(function () {
          // réajuste position et zoom
         switch(where) {
         default :  oMap.setView(where, zoomInitial);
         break;
         case 'paris':
         oMap.setView(where,3);
         break;
         case 'guadeloupe':
         oMap.setView(where,9);
         break;
      }
            // change markers
                swapMarker(where);
              }, 500);  
            });
            // déplacement
            oMap.panTo(where, {
              animate: true,
              duration: delay
            });
          }, 500);
        });
        // ajuste le zoom minimum
        if (zoomCarte === zoomTravel) {
          oMap.fireEvent('zoomend');
        } 
        else {
          oMap.setZoom(zoomTravel);
        }
      }
    }
     
    // gestion du menu destinations
    var oTravel = document.querySelector('#menu_destination');
    oTravel.onclick = function (e) {
      var oSrc = e.target;
      var oDest = oSrc.getAttribute("data-dest");
      if (destination[oDest]) {
        this.querySelector('ul').style.display = 'none';
        gotoDestination(destination[oDest]);
      }
      else {
        this.querySelector('ul').style.display = 'block';
      }
    };
    oTravel.onmouseleave = function (e) {
      this.querySelector('ul').style.display = 'none';
    };
    </script>
    </body>
    </html>

    Merci de votre aide

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    335
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 335
    Points : 70
    Points
    70
    Par défaut affichage d'une carte leaflet
    grâce à vos conseils et des recherches perso, je suis parvenu à afficher la carte leaflet comme je voulais sur le test mais quand j'ai essayé de recopier ce test dans mon html final il doit y avoir quelque chose qui n'a pas fonctionné. voici le code du html final :

    Code html : 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
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    <!DOCTYPE html>
    <!--[if lt IE 7 ]> <html class="no-js ie6"> <![endif]-->
    <!--[if IE 7 ]>    <html class="no-js ie7"> <![endif]-->
    <!--[if IE 8 ]>    <html class="no-js ie8"> <![endif]-->
    <!--[if IE 9 ]>    <html class="no-js ie9"> <![endif]-->
    <!--[if (gt IE 9)|!(IE)]><!--> <html lang="fr"> <!--<![endif]-->
    	<head>
        <meta http-equiv="content-type"	charset="UTF-8">
        <title>MMT DALAL Fr&egrave;res</title>
    	  <link rel="shortcut icon" type="image/png"  href="favicon.png" />
    	  <meta name="viewport" content="width=device-width">
    	  <style>
    #main {
      margin: 0 auto;
      max-width: 60em;
    #cadre_carte {
      position: relative;
      height: 37em;
      margin: 0 auto;
      max-width: 75em;
      border: 5px   font-size: 1em;
      box-shadow: 0 2px 4px 2px #CCC;
    }
    #carte {
      height: 50%
      width: 30%;
    }
     
    /* déclaration pour les markers */
    .circle {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle2 {
      box-sizing: border-box;
      width: 15px;
      height: 15px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle3 {
      box-sizing: border-box;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle4 {
      box-sizing: border-box;
      width: 25px;
      height: 25px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle-marker {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
    }
    .circle-red {
      border: 5px solid #F00;
    }
    .circle-green {
      border: 5px solid #0A0;
    }
    .circle-orange {
      border: 5px solid #F63;
    }
    .circle-bleu {
      border: 5px solid #00F;
    }
    .circle-violet {
      border: 5px solid #909;
    }
    .circle-noir {
      border: 4px solid #000;
    }
    .circle-noir1 {
      border: 2px solid #000;
    }
    .circle-animate {
      animation-name: show-hide;
      animation-duration: 1s;
      animation-iteration-count: infinite;
      transform: scale(1);
    }
    @keyframes show-hide {
      0%   { transform: scale(1);}
      50%  { transform: scale(.5);}
      100% { transform: scale(1);}
    }
    </style>
    		<!--[if lt IE 9]>
    	    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    	<![endif]-->
    	</head>
    	<body>
    		<header>
                   <figure id='mylogo'> 
         			<img src="img/logo.jpg" alt="logo">
                   </figure>
                   <div id="titrePrincipal">			
         			<h1><span class="maj">poipl</span>r&egrave;res</h1>
         	         	<span id="text">
            		          <span class="maj">n</span>um&eacute;ro de <span class="maj">t</span>&eacute;l&eacute;phone :
            		          +33 (0)1 2x xx xx xx  
            		          <br>
            		          <span class="maj">a</span>dresse <span class="maj">p</span>ostale :
            		           75014 PARIS
            		          <br>
            		          <span class="maj">a</span>dresse <span class="maj">e</span>-mail : 
            		          <a class="con" href="mailto:poipl@wanadoo.fr">poipl@wanadoo.fr</a></p>
       		          </span> 
         		</div>
    			<form class="formLang">
    				<label for="l"><span class="maj">c</span>hoisissez votre langue :</label>
    				<select class="selLang" name="l">
    					<option class="fr" value="fr" label="true" selected="selected"><span class="maj">f</span>ran&ccedil;ais</option>
    					<option class="en" value="en"><span class="maj">e</span>nglish</option>
    				</select>
    			</form>
    			<nav>
    			<span class="ent"><span class="maj">n</span>otre <span class="maj">e</span>ntreprise</span>
    				<span class="pro"><span class="maj">n</span>os <span class="maj">p</span>roduits</span>
    				<span class="cli"><span class="maj">n</span>otre <span class="maj">c</span>lient&egrave;le</span>
    				<span class="mar"><span class="maj">n</span>os <span class="maj">m</span>arch&eacute;s</span>
    				<span class="tem"><span class="maj">t</span>&eacute;moignages</span>
    			</nav>
    .		</header>
       	<section>
       	<div id="main">
      <div class="header">
      <div class="section">
        <div id="cadre_carte">
          <div id="carte">yann est intelligent </div>
          et capable 
         </div>
      </div>
    </div>
       		<article></article>
       	</section>
       	<footer>
       	      <q class="italic"><span class="maj">s</span>ite <span class="maj">w</span>eb r&eacute;alis&eacute; par <a href="mail to:site.super25@gmail.com "><span class="maj">y</span>po <span class="maj">pouiop</span></a></q>
       	</footer>
       <script>
    var oMap;
    var animEnCours = false;
    var destination = {
        "paris" : {
            "libelle" : "Paris",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "cameroun" : {
            "libelle" : "Cameroun",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "comores" : {
            "libelle" : "Comores",
            "point" : L.latLng(-11.72, 43.25),
            "zoom" : 3.5,
        },
        "ethiopie" : {
            "libelle" : "Ethiopie",
            "point" : L.latLng(8.9800, 38.7989),
            "zoom" : 3.5,
        },
        "guadeloupe" : {
            "libelle" : "Guadeloupe",
            "point" : L.latLng(6.265, -61.551),
            "zoom" : 3.5,
        },
        "guyane" : {
            "libelle" : "Guyane",
            "point" : L.latLng(4.144817,-52.8442),
            "zoom" : 3.5,
        },
        "reunion" : {
            "libelle" : "La Réunion",
            "point" : L.latLng(-21.1151, 55.5363),
            "zoom" : 8,
        },
        "madagascar" : {
            "libelle" : "Madagascar",
            "point" : L.latLng(-18.77, 46.9),
            "zoom" : 3.5,
        },
        "martinique" : {
            "libelle" : "Martinique",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "maurice" : {
            "libelle" : "Maurice",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "mayotte" : {
            "libelle" : "Mayotte",
            "point" : L.latLng(-12.768,45.2286),
            "zoom" : 3.5,
        },
        "tahiti" : {
            "libelle" : "Tahiti",
            "point" : L.latLng(-17.6509, -149.426),
            "zoom" : 3.5,
        },
        //...
    };
    /*var destination = {
     
      'paris':    L.latLng(48.85342, 2.3488),
      'cameroun':      L.latLng(5.76463, 11.75537),
      'comores' :      L.latLng(-11.72, 43.25),
      'ethiopie' :  L.latLng(8.9800, 38.7989),
      'guadeloupe' :      L.latLng(16.265, -61.551),
      'guyane' :      L.latLng(4.144817,-52.8442),
      'reunion' :      L.latLng(-21.1151, 55.5363),
      'madagascar' :      L.latLng(-18.77, 46.9),
      'martinique' :      L.latLng(14.64, -61.01669),
      'maurice' :      L.latLng(-20.3484,57.5833),
      'mayotte' :      L.latLng(-12.768,45.2286),
      'tahiti' :      L.latLng(-17.6509, -149.426)
    };
    */
    // création des divIcon
    var oIconRed = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-red"></div>'
    });
    var oIconGreen = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-green"></div>'
    });
    var oIconOrange = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-orange"></div>'
    });
    var oIconBleu = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-bleu"></div>'
    });
    var oIconViolet = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-violet"></div>'
    });
    var oIconNoir = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-noir"></div>'
    });
    var oIconNoir1a = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle3 circle-noir"></div>'
    });
    var oIconNoir1b = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle4 circle-noir1"></div>'
    });
    // création des markers
    //paris
    var oMarkerRed   = L.marker( [48.85342, 2.3488], {icon: oIconRed});
    //cameroun
    var oMarkerNoir = L.marker( [5.76463, 11.75537], {icon: oIconNoir});
    //comores
    var oMarkerNoir1 = L.marker( [-11.72, 43.25], {icon: oIconNoir});
    //ethiopie
    var oMarkerNoir2 = L.marker( [8.9800, 38.7989], {icon: oIconNoir});
    //guadeloupe
    var oMarkerNoir3 = L.marker( [16.265, -61.551], {icon: oIconNoir1b});
    //guyane
    var oMarkerNoir4 = L.marker( [4.144817,-52.8442], {icon: oIconNoir});
    //la réunion
    var oMarkerNoir5 = L.marker( [-21.1151, 55.5363], {icon: oIconNoir1a});
    //madagascar
    var oMarkerNoir6 = L.marker( [-18.77, 46.9], {icon: oIconNoir});
    //martinique
    var oMarkerNoir7 = L.marker( [14.64, -61.01669], {icon: oIconNoir});
    //maurice
    var oMarkerNoir8 = L.marker( [-20.3484,57.5833], {icon: oIconNoir});
    //mayotte
    var oMarkerNoir9 = L.marker( [-12.768,45.2286], {icon: oIconNoir1a});
    //tahiti
    var oMarkerNoir10 = L.marker( [-17.6509, -149.426], {icon: oIconNoir});
    // création de la carte
    var zoomInitial = 9; // ce que l'on modifie versus test5 9 au leu de 7
    var zoomTravel  = 3; 
    oMap = L.map('carte', {
        zoomAnimationThreshold: 20, 
        zoomControl: false,          // voir <a href="http://leafletjs.com/reference-1.1.0.html#map-zoomcontrol" target="_blank">http://leafletjs.com/reference-1.1.0...ap-zoomcontrol</a>
        duration: 5,
        center: [ 0, 0 ],
        zoom: 1.1 
    });
    oMap.addLayer( L.tileLayer(
        'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
        {
          attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }
      ));
    // place les marker rouge et vert sur destination et départ
        oMarkerRed.addTo(oMap); 
        oMarkerNoir.addTo(oMap);   
        oMarkerNoir1.addTo(oMap);    
        oMarkerNoir2.addTo(oMap);    
        oMarkerNoir3.addTo(oMap);    
        oMarkerNoir4.addTo(oMap);    
        oMarkerNoir5.addTo(oMap);    
        oMarkerNoir6.addTo(oMap);    
        oMarkerNoir7.addTo(oMap);    
        oMarkerNoir8.addTo(oMap);    
        oMarkerNoir9.addTo(oMap);    
        oMarkerNoir10.addTo(oMap);   
    // fonction sur click oMap
    oMap.on('click', function (e) {
      // affiche marker vert au click
      oMarkerGreen.setLatLng([e.latlng.lat, e.latlng.lng]).addTo(this);
      oMarkerGreen.on('click', function (e) {
        this.remove(oMap);
      })
    });
     
    function swapMarker(where){
      // supprime marker rouge
      oMarkerRed.remove(oMap);
      // affiche marker vert
      oMarkerGreen.setLatLng(where).addTo(oMap);
      // autorise autre animation
      animEnCours = false;
    }
     
    function gotoDestination(where) {
      // si animation en cours on quitte
      if (animEnCours) {
        return;
      }
      animEnCours = true;
      var zoomCarte = oMap.getZoom();
      // récupération point de départ
      var pointDepart = oMap.hasLayer(oMarkerGreen) ? oMarkerGreen.getLatLng() : oMap.getCenter();
      // place les marker rouge et vert sur destination et départ
      oMarkerRed.setLatLng(where).addTo(oMap);
      oMarkerGreen.setLatLng(pointDepart).addTo(oMap);
      // calcul distance déplacement
      var distance = oMap.distance(pointDepart, where)/1000;
      // calcul durée déplacement
      var delay = distance / 2000;
      // accés direct si distance < 1000 km
      if (distance < 1000) {
      
        // réajuste position et zoom
       console.log(where); 
       switch(where) {
         default :  oMap.setView(L.latLng(0, 0), zoomInitial);
         break;
         case L.latLng(48.85342, 2.3488):
         oMap.setView(where,zoom);
         break;
         case L.latLng(16.265, -61.551):
         oMap.setView(where,8);
         break;}
        // change markers
        swapMarker(where);
      } 
      else {
         // défini action en fin de zoom
        oMap.once('zoomend', function () {
          // déplacement vers destination
          setTimeout(function () {
            // défini action en fin de déplacement
            oMap.once('moveend', function () {
              // on zooom sur destination
              setTimeout(function () {
          // réajuste position et zoom
         switch(where) {
         default :  oMap.setView(where, zoomInitial);
         break;
         case 'paris':
         oMap.setView(where,3);
         break;
         case 'guadeloupe':
         oMap.setView(where,9);
         break;
      }
            // change markers
                swapMarker(where);
              }, 500);  
            });
            // déplacement
            oMap.panTo(where, {
              animate: true,
              duration: delay
            });
          }, 500);
        });
        // ajuste le zoom minimum
        if (zoomCarte === zoomTravel) {
          oMap.fireEvent('zoomend');
        } 
        else {
          oMap.setZoom(zoomTravel);
        }
      }
    }
     
    // gestion du menu destinations
    var oTravel = document.querySelector('#menu_destination');
    oTravel.onclick = function (e) {
      var oSrc = e.target;
      var oDest = oSrc.getAttribute("data-dest");
      if (destination[oDest]) {
        this.querySelector('ul').style.display = 'none';
        gotoDestination(destination[oDest]);
      }
      else {
        this.querySelector('ul').style.display = 'block';
      }
    };
    oTravel.onmouseleave = function (e) {
      this.querySelector('ul').style.display = 'none';
    };
    </script>	
    	</body>
    </html>

    pouvez-vous m'aider à afficher la carte ?

  7. #7
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 232
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 232
    Points : 15 525
    Points
    15 525
    Par défaut
    Déjà vous avez oublié d'inclure les scripts et feuilles de style de Leaflet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.css"/>
    <script src="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.js"></script>
    ensuite revoyez le code CSS qui est dans les balises "style", il n'est pas valide.

  8. #8
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    335
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 335
    Points : 70
    Points
    70
    Par défaut
    merci Matthieu. je vérifie les balises

  9. #9
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    335
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 335
    Points : 70
    Points
    70
    Par défaut
    je suis désolé d'avoir oublié ces balises, je les ai donc ajoutées. j'ai pensé à mon code javascript qui faisait encore appel à l'élément "menu destination" qui dans mon nouveau "html" n'existait plus je l'ai donc supprimé mais par contre je ne vois pas ce qu'il manque dans mon "style" . Je vous redonne mon code "rectifié" :

    Code html : 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
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    <!DOCTYPE html>
    <!--[if lt IE 7 ]> <html class="no-js ie6"> <![endif]-->
    <!--[if IE 7 ]>    <html class="no-js ie7"> <![endif]-->
    <!--[if IE 8 ]>    <html class="no-js ie8"> <![endif]-->
    <!--[if IE 9 ]>    <html class="no-js ie9"> <![endif]-->
    <!--[if (gt IE 9)|!(IE)]><!--> <html lang="fr"> <!--<![endif]-->
    	<head>
        <meta http-equiv="content-type"	charset="UTF-8">
        <title>Mpopi Fr&egrave;res</title>
        <link rel="stylesheet" type="text/css" href="css/2018 01 07 site v0.css" />
    	  <link rel="shortcut icon" type="image/png"  href="favicon.png" />
    	  <meta name="viewport" content="width=device-width">
    	  <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.css">
           <script src="http://cdn.leafletjs.com/leaflet/v1.0.3/leaflet.js"></script>
    	  <style>
    #main {
      margin: 0 auto;
      max-width: 60em;
      }
    #cadre_carte {
      max-width: 75em;
      border: 5px   font-size: 1em;
      box-shadow: 0 2px 4px 2px #CCC;
    }
    #carte {
      height: 50%;
      width: 30%;
    }
     
    /* déclaration pour les markers */
    .circle {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle2 {
      box-sizing: border-box;
      width: 15px;
      height: 15px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle3 {
      box-sizing: border-box;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle4 {
      box-sizing: border-box;
      width: 25px;
      height: 25px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle-marker {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
    }
    .circle-red {
      border: 5px solid #F00;
    }
    .circle-green {
      border: 5px solid #0A0;
    }
    .circle-orange {
      border: 5px solid #F63;
    }
    .circle-bleu {
      border: 5px solid #00F;
    }
    .circle-violet {
      border: 5px solid #909;
    }
    .circle-noir {
      border: 4px solid #000;
    }
    .circle-noir1 {
      border: 2px solid #000;
    }
    .circle-animate {
      animation-name: show-hide;
      animation-duration: 1s;
      animation-iteration-count: infinite;
      transform: scale(1);
    }
    @keyframes show-hide {
      0%   { transform: scale(1);}
      50%  { transform: scale(.5);}
      100% { transform: scale(1);}
    }
    </style>
    		<!--[if lt IE 9]>
    	    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    	<![endif]-->
    	</head>
    	<body>
    		<header>
                   <figure id='mylogo'> 
         			<img src="img/logo.jpg" alt="logo">
                   </figure>
                   <div id="titrePrincipal">			
         			<h1><span class="maj">mpopi</span>r&egrave;res</h1>
         	         	<span id="text">
            		          <span class="maj">n</span>um&eacute;ro de <span class="maj">t</span>&eacute;l&eacute;phone :
            		          +33 (0)1 2x xx xx  
            		          <br>
            		          <span class="maj">a</span>dresse <span class="maj">p</span>ostale :
            		          75014 PARIS
            		          <br>
            		          <span class="maj">a</span>dresse <span class="maj">e</span>-mail : 
            		          <a class="con" href="mailto:mapoil@wanadoo.fr">mapoil@wanadoo.fr</a></p>
       		          </span> 
         		</div>
    			<form class="formLang">
    				<label for="l"><span class="maj">c</span>hoisissez votre langue :</label>
    				<select class="selLang" name="l">
    					<option class="fr" value="fr" label="true" selected="selected"><span class="maj">f</span>ran&ccedil;ais</option>
    					<option class="en" value="en"><span class="maj">e</span>nglish</option>
    				</select>
    			</form>
    			<nav>
    			<span class="ent"><span class="maj">n</span>otre <span class="maj">e</span>ntreprise</span>
    				<span class="pro"><span class="maj">n</span>os <span class="maj">p</span>roduits</span>
    				<span class="cli"><span class="maj">n</span>otre <span class="maj">c</span>lient&egrave;le</span>
    				<span class="mar"><span class="maj">n</span>os <span class="maj">m</span>arch&eacute;s</span>
    				<span class="tem"><span class="maj">t</span>&eacute;moignages</span>
    			</nav>
    .		</header>
       	<section>
       	<div id="main">
      <div class="header">
      <div class="section">
        <div id="cadre_carte">
          <div id="carte">yann est intelligent </div>
          et capable 
         </div>
      </div>
    </div>
       		<article></article>
       	</section>
       	<footer>
       	      <q class="italic"><span class="maj">s</span>ite <span class="maj">w</span>eb r&eacute;alis&eacute; par <a href="mail to:site.super25@gmail.com "><span class="maj">y</span>poip <span class="maj">qpoiptr</span></a></q>
       	</footer>
       	<script type="text/javascript" src="js/2018 01 07 site v0.js"></script>
       <script>
    var oMap;
    var animEnCours = false;
    var destination = {
        "paris" : {
            "libelle" : "Paris",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "cameroun" : {
            "libelle" : "Cameroun",
            "point" : L.latLng(48.85342, 2.3488),
            "zoom" : 3.5,
        },
        "comores" : {
            "libelle" : "Comores",
            "point" : L.latLng(-11.72, 43.25),
            "zoom" : 3.5,
        },
        "ethiopie" : {
            "libelle" : "Ethiopie",
            "point" : L.latLng(8.9800, 38.7989),
            "zoom" : 3.5,
        },
        "guadeloupe" : {
            "libelle" : "Guadeloupe",
            "point" : L.latLng(6.265, -61.551),
            "zoom" : 3.5,
        },
        "guyane" : {
            "libelle" : "Guyane",
            "point" : L.latLng(4.144817,-52.8442),
            "zoom" : 3.5,
        },
        "reunion" : {
            "libelle" : "La Réunion",
            "point" : L.latLng(-21.1151, 55.5363),
            "zoom" : 8,
        },
        "madagascar" : {
            "libelle" : "Madagascar",
            "point" : L.latLng(-18.77, 46.9),
            "zoom" : 3.5,
        },
        "martinique" : {
            "libelle" : "Martinique",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "maurice" : {
            "libelle" : "Maurice",
            "point" : L.latLng(14.64, -61.01669),
            "zoom" : 3.5,
        },
        "mayotte" : {
            "libelle" : "Mayotte",
            "point" : L.latLng(-12.768,45.2286),
            "zoom" : 3.5,
        },
        "tahiti" : {
            "libelle" : "Tahiti",
            "point" : L.latLng(-17.6509, -149.426),
            "zoom" : 3.5,
        },
        //...
    };
    /*var destination = {
     
      'paris':    L.latLng(48.85342, 2.3488),
      'cameroun':      L.latLng(5.76463, 11.75537),
      'comores' :      L.latLng(-11.72, 43.25),
      'ethiopie' :  L.latLng(8.9800, 38.7989),
      'guadeloupe' :      L.latLng(16.265, -61.551),
      'guyane' :      L.latLng(4.144817,-52.8442),
      'reunion' :      L.latLng(-21.1151, 55.5363),
      'madagascar' :      L.latLng(-18.77, 46.9),
      'martinique' :      L.latLng(14.64, -61.01669),
      'maurice' :      L.latLng(-20.3484,57.5833),
      'mayotte' :      L.latLng(-12.768,45.2286),
      'tahiti' :      L.latLng(-17.6509, -149.426)
    };
    */
    // création des divIcon
    var oIconRed = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle circle-red"></div>'
    });
    var oIconGreen = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-green"></div>'
    });
    var oIconOrange = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-orange"></div>'
    });
    var oIconBleu = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-bleu"></div>'
    });
    var oIconViolet = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-violet"></div>'
    });
    var oIconNoir = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle2 circle-noir"></div>'
    });
    var oIconNoir1a = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle3 circle-noir"></div>'
    });
    var oIconNoir1b = L.divIcon({
      iconAnchor : [15, 15],
      className: 'circle-marker',
      html: '<div class="circle-animate circle4 circle-noir1"></div>'
    });
    // création des markers
    //paris
    var oMarkerRed   = L.marker( [48.85342, 2.3488], {icon: oIconRed});
    //cameroun
    var oMarkerNoir = L.marker( [5.76463, 11.75537], {icon: oIconNoir});
    //comores
    var oMarkerNoir1 = L.marker( [-11.72, 43.25], {icon: oIconNoir});
    //ethiopie
    var oMarkerNoir2 = L.marker( [8.9800, 38.7989], {icon: oIconNoir});
    //guadeloupe
    var oMarkerNoir3 = L.marker( [16.265, -61.551], {icon: oIconNoir1b});
    //guyane
    var oMarkerNoir4 = L.marker( [4.144817,-52.8442], {icon: oIconNoir});
    //la réunion
    var oMarkerNoir5 = L.marker( [-21.1151, 55.5363], {icon: oIconNoir1a});
    //madagascar
    var oMarkerNoir6 = L.marker( [-18.77, 46.9], {icon: oIconNoir});
    //martinique
    var oMarkerNoir7 = L.marker( [14.64, -61.01669], {icon: oIconNoir});
    //maurice
    var oMarkerNoir8 = L.marker( [-20.3484,57.5833], {icon: oIconNoir});
    //mayotte
    var oMarkerNoir9 = L.marker( [-12.768,45.2286], {icon: oIconNoir1a});
    //tahiti
    var oMarkerNoir10 = L.marker( [-17.6509, -149.426], {icon: oIconNoir});
    // création de la carte
    var zoomInitial = 9; // ce que l'on modifie versus test5 9 au leu de 7
    var zoomTravel  = 3; 
    oMap = L.map('carte', {
        zoomAnimationThreshold: 20, 
        zoomControl: false,          // voir <a href="http://leafletjs.com/reference-1.1.0.html#map-zoomcontrol" target="_blank">http://leafletjs.com/reference-1.1.0...ap-zoomcontrol</a>
        duration: 5,
        center: [ 0, 0 ],
        zoom: 1.1 
    });
    oMap.addLayer( L.tileLayer(
        'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
        {
          attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }
      ));
    // place les marker rouge et vert sur destination et départ
        oMarkerRed.addTo(oMap); 
        oMarkerNoir.addTo(oMap);   
        oMarkerNoir1.addTo(oMap);    
        oMarkerNoir2.addTo(oMap);    
        oMarkerNoir3.addTo(oMap);    
        oMarkerNoir4.addTo(oMap);    
        oMarkerNoir5.addTo(oMap);    
        oMarkerNoir6.addTo(oMap);    
        oMarkerNoir7.addTo(oMap);    
        oMarkerNoir8.addTo(oMap);    
        oMarkerNoir9.addTo(oMap);    
        oMarkerNoir10.addTo(oMap);   
    // fonction sur click oMap
    oMap.on('click', function (e) {
      // affiche marker vert au click
      oMarkerGreen.setLatLng([e.latlng.lat, e.latlng.lng]).addTo(this);
      oMarkerGreen.on('click', function (e) {
        this.remove(oMap);
      })
    });
     
    function swapMarker(where){
      // supprime marker rouge
      oMarkerRed.remove(oMap);
      // affiche marker vert
      oMarkerGreen.setLatLng(where).addTo(oMap);
      // autorise autre animation
      animEnCours = false;
    }
     
    function gotoDestination(where) {
      // si animation en cours on quitte
      if (animEnCours) {
        return;
      }
      animEnCours = true;
      var zoomCarte = oMap.getZoom();
      // récupération point de départ
      var pointDepart = oMap.hasLayer(oMarkerGreen) ? oMarkerGreen.getLatLng() : oMap.getCenter();
      // place les marker rouge et vert sur destination et départ
      oMarkerRed.setLatLng(where).addTo(oMap);
      oMarkerGreen.setLatLng(pointDepart).addTo(oMap);
      // calcul distance déplacement
      var distance = oMap.distance(pointDepart, where)/1000;
      // calcul durée déplacement
      var delay = distance / 2000;
      // accés direct si distance < 1000 km
      if (distance < 1000) {
      
        // réajuste position et zoom
       console.log(where); 
       switch(where) {
         default :  oMap.setView(L.latLng(0, 0), zoomInitial);
         break;
         case L.latLng(48.85342, 2.3488):
         oMap.setView(where,zoom);
         break;
         case L.latLng(16.265, -61.551):
         oMap.setView(where,8);
         break;}
        // change markers
        swapMarker(where);
      } 
      else {
         // défini action en fin de zoom
        oMap.once('zoomend', function () {
          // déplacement vers destination
          setTimeout(function () {
            // défini action en fin de déplacement
            oMap.once('moveend', function () {
              // on zooom sur destination
              setTimeout(function () {
          // réajuste position et zoom
         switch(where) {
         default :  oMap.setView(where, zoomInitial);
         break;
         case 'paris':
         oMap.setView(where,3);
         break;
         case 'guadeloupe':
         oMap.setView(where,9);
         break;
      }
            // change markers
                swapMarker(where);
              }, 500);  
            });
            // déplacement
            oMap.panTo(where, {
              animate: true,
              duration: delay
            });
          }, 500);
        });
        // ajuste le zoom minimum
        if (zoomCarte === zoomTravel) {
          oMap.fireEvent('zoomend');
        } 
        else {
          oMap.setZoom(zoomTravel);
        }
      }
    }
    </script>	
    	</body>
    </html>

    pouvez-vous encore m'aider ?

  10. #10
    Modérateur
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 077
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 077
    Points : 17 182
    Points
    17 182
    Par défaut
    Salut
    Citation Envoyé par aertys Voir le message
    .... par contre je ne vois pas ce qu'il manque dans mon "style" .....
    Dans le code posté N°6 il manque le }
    Code CSS : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    	  <style>
    #main {
      margin: 0 auto;
      max-width: 60em;
    #cadre_carte {
    Alors qu'il est bien la dans le code rectifié.
    Soyez sympa, pensez -y
    Balises[CODE]...[/CODE]
    Balises[CODE=NomDuLangage]...[/CODE] quand vous mettez du code d'un autre langage que celui du forum ou vous postez.
    Balises[C]...[/C] code intégré dans une phrase.
    Balises[C=NomDuLangage]...[/C] code intégré dans une phrase quand vous mettez du code d'un autre langage que celui du forum ou vous postez.
    Le bouton en fin de discussion, quand vous avez obtenu l'aide attendue.
    ......... et pourquoi pas, pour remercier, un pour celui/ceux qui vous ont dépannés.
    👉 → → Ma page perso sur DVP ← ← 👈

  11. #11
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    335
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 335
    Points : 70
    Points
    70
    Par défaut
    merci pour la réponse et l'aide continue que vous m'apportez.

    Mais je ne comprends pas très bien ce que je dois faire . J'ai essayé plein de choses mais je ne trouve pas l'erreur.

    Je dois écrire le code ainsi :
    Solution 1 :

    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    	  <style>
    #main {
      margin: 0 auto;
      max-width: 60em;
      }
    #cadre_carte {
      max-width: 75em;
      border: 5px   font-size: 1em;
      box-shadow: 0 2px 4px 2px #CCC;
    }
    #carte {
      height: 50%;
      width: 30%;
    }

    OU

    SOLUTION 2 :

    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    	  <style>
    #main {
      margin: 0 auto;
      max-width: 60em;
    #cadre_carte 
      max-width: 75em;
      border: 5px   font-size: 1em;
      box-shadow: 0 2px 4px 2px #CCC;
    }
    #carte {
      height: 50%;
      width: 30%;
    }

    J'ai une autre question : pourquoi le </style> ne s'affiche pas en "rouge" comme le <style> ?

    Encore autre chose :
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    @keyframes show-hide {
      0%   { transform: scale(1);}
      50%  { transform: scale(.5);}
      100% { transform: scale(1);}
    }
    L'accolade de show-hide est associée à 0% transform/scale(1); je n'arrive pas à savoir à quelle accolade est donc associée la 2ème après 100% transform: scale(1);

    Je vous joins tout le style ; à quelle ligne se trouvent les erreurs et est-ce qu'il faut rajouter ou enlever une accolade ?
    Code html : 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
    	  <style>
    #main {
      margin: 0 auto;
      max-width: 60em;
      }
    #cadre_carte {
      max-width: 75em;
      border: 5px   font-size: 1em;
      box-shadow: 0 2px 4px 2px #CCC;
    }
    #carte {
      height: 50%;
      width: 30%;
    }
     
    /* déclaration pour les markers */
    .circle {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle2 {
      box-sizing: border-box;
      width: 15px;
      height: 15px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle3 {
      box-sizing: border-box;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle4 {
      box-sizing: border-box;
      width: 25px;
      height: 25px;
      border-radius: 50%;
      background-color: rgba(255,255,255,0.3);
      box-shadow: 0 0 10px #888;
    }
    .circle-marker {
      box-sizing: border-box;
      width: 30px;
      height: 30px;
    }
    .circle-red {
      border: 5px solid #F00;
    }
    .circle-green {
      border: 5px solid #0A0;
    }
    .circle-orange {
      border: 5px solid #F63;
    }
    .circle-bleu {
      border: 5px solid #00F;
    }
    .circle-violet {
      border: 5px solid #909;
    }
    .circle-noir {
      border: 4px solid #000;
    }
    .circle-noir1 {
      border: 2px solid #000;
    }
    .circle-animate {
      animation-name: show-hide;
      animation-duration: 1s;
      animation-iteration-count: infinite;
      transform: scale(1);
    }
    @keyframes show-hide {
      0%   { transform: scale(1);}
      50%  { transform: scale(.5);}
      100% { transform: scale(1);}
    }
    </style>

  12. #12
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 232
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 232
    Points : 15 525
    Points
    15 525
    Par défaut
    Ce soucis n'est pas lié à Leaftlet mais au code CSS donc votre question serait peut-être mieux placée si vous créez une nouvelle discussion dans ce forum :
    https://www.developpez.net/forums/f4...mise-page-css/

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

Discussions similaires

  1. Attribuer de différente couleur
    Par BrunetteCP dans le forum Langage
    Réponses: 3
    Dernier message: 28/05/2009, 12h54
  2. Réponses: 6
    Dernier message: 18/05/2008, 10h13
  3. ComboBox aux différentes couleurs
    Par KiKiTiTi dans le forum GTK+ avec C & C++
    Réponses: 10
    Dernier message: 02/05/2008, 11h35
  4. Réponses: 2
    Dernier message: 25/03/2008, 15h30
  5. Réponses: 12
    Dernier message: 24/01/2006, 12h38

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