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

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

IGN API Géoportail Discussion :

OpenLayers - Plan IGN vecteur tuilé


Sujet :

IGN API Géoportail

  1. #1
    Membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Mai 2014
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 73
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Mai 2014
    Messages : 71
    Points : 66
    Points
    66
    Par défaut OpenLayers - Plan IGN vecteur tuilé
    Bonjour,

    Quelqu'un aurait-il un exemple simple de code pour afficher la nouvelle ressource "Plan IGN -Vecteur tuilé" AVEC un style de base ?

    Voici mon point de départ qui affiche (ca fonctionne !) PLAN IGN VT mais SANS styles ( ... tout est en linéaire bleu) :

    Code JavaScript : 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
    // The map
    var map = new ol.Map({
    	layers: [ 
    		new ol.layer.Tile({
    			title: 'OpenStreetMap',
    			source: new ol.source.OSM(),
    			visible: false,	
    		}),
    	],
     
    	target: 'map',
     
    	view: new ol.View ({
    		zoom: 15,
    		center: [261204.43490751847, 6250258.191535994]
    	}),
     
    });
     
     
    // Vector layer
    var vlayer = new ol.layer.VectorTile({
    	title: "Plan IGN vecteur",
    	renderMode: 'hybrid',
    	source: new ol.source.VectorTile({
    		tilePixelRatio: 1,
    		tileGrid: ol.tilegrid.createXYZ({
    			maxZoom: 19,
    		}),
    		format: new ol.format.MVT(),
    		projection: new ol.proj.Projection({code:"EPSG:3857"}),
    		url : "https://wxs.ign.fr/[clé de géoservice]/geoportail/tms/1.0.0/PLAN.IGN/{z}/{x}/{y}.pbf",
    		attributions: '<a href="https://geoservices.ign.fr/blog/2018/07/08/nouveautes_vecteur.html">&copy; IGN-Géoportail</a>',
    	}),
    	declutter: true
    });
    map.addLayer(vlayer);

    J'ai essayé de simplifier l'exemple de ol-ext: Geoportail vector tile, mais c'est (beaucoup) trop complexe pour moi !

    Merci d'avance !

    YD

  2. #2
    Membre averti Avatar de lowzonenose
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2014
    Messages
    196
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2014
    Messages : 196
    Points : 407
    Points
    407
    Par défaut
    Bonjour,

    je vous renvoie vers l'utilisation d'un exemple OpenLayers avec la librairie ol-mapbox-style :
    https://openlayers.org/en/latest/exa...box-style.html et
    https://openlayers.org/en/latest/exa...iles-4326.html

    Cette librairie vous permet de lire / appliquer un fichier de style (json) sur une carte ou sur une couche.
    Vous pouvez aussi vous appuyer sur notre démonstrateur : https://vectortiles.ign.fr/demonstrateur/

    Pour info, OpenLayers intègre la librairie ol-mapbox-style depuis la version v6.5.1.

  3. #3
    Membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Mai 2014
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 73
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Mai 2014
    Messages : 71
    Points : 66
    Points
    66
    Par défaut
    Merci lowzonenose,

    J'ai bien regardé vos exemples.
    J'ai choisi de repartir du démonstrateur (https://vectortiles.ign.fr/demonstrateur/), parce que la syntaxte m'était plus familière ...

    ... j'ai importé olms.js, mis à jour tous les liens en local, remplacé la clé Choisirgeoportail par ma propre clé (sur laquelle PLAN IGN VTvient d'être ajouté récemment)... Tout fonctionne bien SAUF LES STYLES. Pas seulement le style de PLAN IGN mais de toutes les couches vectorielles.

    J'imagine dès lors qu'il s'agit d'un problème de ol-mapbox-style qui "refuse de charger" les JSON, mais je ne vois pas comment régler le problème. S'agit-il de déclarer la clé Maptiler, et si oui comment ? Dans le code du démonstrateur il n'y a rien de tel ...

    Merci de m'aider encore un peu, SVP !

    Voiçi où j'en suis :

    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
    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8" />
    		<title>Pyramide écran avec ROK4</title>
     
    		<!-- Library OpenLayers 6.5.0 -->
    		<link rel="stylesheet" href="http://localhost/v6.5.0-dist/ol.css" />
    		<script src="http://localhost/v6.5.0-dist/ol.js"></script> 
     
    		<script src="http://localhost/ressources/ol-mapbox-style-6.3.2/ol-mapbox-style-master/src/olms.js"></script>
    		<script src="http://localhost/ressources/jquery-2.2.4.min.js"></script>
     
    		<!-- Library Extension Géoportail pour OpenLayers 3.0.14 -->		
    		<link rel="stylesheet" href="http://localhost/ressources/GpPluginOpenLayers-3.0.14/GpPluginOpenLayers.css" type="text/css">		
    		<script src="http://localhost/ressources/GpPluginOpenLayers-3.0.14/GpPluginOpenLayers.js"></script>
     
    		<style>
                            html, body {
                                    height: 100%;
                                    padding: 0;
                                    margin: 0;
                                    font-family: sans-serif;
                            }
     
                            /****** Page d'accueil *****/
                            h2 {
                                    margin-top: 50px;
                                    margin-bottom: 50px;
                                    text-align: center;
                                    font-size: 30px;
                            }
     
                            body.accueil {
                                    width: 100%;
                                    height: 100%;
                                    padding-top: 100px;
                                    background-image: url("../images/fond.png");
                                    background-position: center;
                                    background-repeat: no-repeat;
                                    background-attachment: fixed;
                                    background-size: cover;
                            }
     
                            a.accueil-lien {
                                    display: block;
                                    margin: 20px auto 20px auto;
                                    width: 40%;
                                    min-width: 500px;
                                    text-align: center;
                                    font-size: 20px;
                                    font-weight: bold;
                                    color: white;
                                    border-radius: 5px;
                                    display:block;
                                    line-height:50px;
                                    text-decoration: none;
                                    background-color: #70777a;
                            }
     
                            a.accueil-lien:link{
                                    color: white;
                            }
     
                            a.accueil-lien:visited{
                                    color: white;
                            }
     
                            a.accueil-lien:hover{
                                    color: white;
                                    font-weight: bold;
                                    font-size: 22px;
                                    background-color: #94c01a;
                            }
     
                            a.accueil-lien:active{
                                    color: white;
                                    font-weight: bold;
                                    font-size: 22px;
                                    background-color: #94c01a;
                            }
     
                            /****** Carte *****/
     
                            #map {
                                    width: 100%;
                                    height: 100%;
                            }
     
                            #infos {
                                    border-radius: 5px;
                                    position: fixed;
                                    padding: 10px;
                                    bottom: 10px;
                                    left: 10px;
                                    display: none;
                                    max-height: 50%;
                                    background-color: rgba(255, 255, 255, 0.7);
                                    z-index: 10000;
                                    overflow: auto;
                            }
     
                            #zoomlevel {
                                    position: fixed;
                                    text-align: center;
                                    top: 70px;
                                    left: 18px;
                                    height: 100%;
                                    font-size: 20;
                                    color: white;
                                    text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
                            }
     
                            /* Infos au clic */
                            #infos h5 {
                                    margin: 15px auto 2px auto;
                                    text-align: center;
                                    color: rgb(100, 150, 0);
                            }
     
                            #infos ul {
                                    margin: 0px;
                                    padding: 0px;
                                    list-style-type: none;
                            }
     
                            #infos li {
                                    margin: 0px;
                            }
     
                            #croix {
                                    color: rgb(100, 150, 0);
                                    font-weight: bold;
                                    position: absolute;
                                    font-size: larger;
                                    top: 0px;
                                    right: 5px;
                                    cursor: pointer;
                            }
     
                            /* Openlayers controls buttons */
                            .ol-rotate {
                                    top: 4.5em;
                                    left: .5em;
                                    right: auto;
                            }
     
                            .ol-zoom {
                                    top: .5em;
                                    left: .5em;
                            }               
                    </style>
     
    	</head>
    	<body>
    		<div id="map"></div>
    		<div id="infos"></div>
    		<div id="zoomlevel"></div>
    		<script>
                            
                            function go() {
     
                                    /************************* CARTE PRINCIPALE *************************/
     
                                    var layers = [];
     
                                    var stamenLayer = new ol.layer.Tile({
                                            title: "Fond de carte",
                                            description: "Stamen maps - Water color",
                                            visible: false,
                                            source: new ol.source.Stamen({
                                                    layer: 'watercolor'
                                            })
                                    });
                                    layers.push(stamenLayer);
     
                                    var planignLayer = new ol.layer.VectorTile({
                                            title: "Plan IGN",
                                            description: "Plan IGN Vecteur tuilé",
                                            mapboxStyleUrl: "https://wxs.ign.fr/[ma clé géoservices]/static/vectorTiles/styles/PLAN.IGN/standard.json",
                                            mapboxStyleSource: "plan_ign",
                                            // gris.json
                                            // sans_toponymes.json
                                            // transparent.json
                                            // accentue.json
                                            // attenue.json
                                            // classique.json
                                            // epure.json
                                            visible: true,
                                            source: new ol.source.VectorTile({
                                                    format: new ol.format.MVT(),
                                                    url: "https://wxs.ign.fr/[ma clé géoservices]/geoportail/tms/1.0.0/PLAN.IGN/{z}/{x}/{y}.pbf"
                                            }),
                                            declutter: true,
                                            attributions: '<a href="https://geoservices.ign.fr/documentation/geoservices/vecteur-tuile.html">&copy; IGN</a>',
                                    });
                                    layers.push(planignLayer);
     
     
                                    var schapiLayer = new ol.layer.VectorTile({
                                            title: "SCHAPI",
                                            description: "SCHAPI Vecteur tuilé",
                                            mapboxStyleUrl: "https://vectortiles.ign.fr/styles/schapi.json",
                                            mapboxStyleSource: "schapi",
                                            visible: true,
                                            source: new ol.source.VectorTile({
                                                    format: new ol.format.MVT(),
                                                    url: "https://vectortiles.ign.fr/rok4server/1.0.0/SCHAPI_TERR_TR_STA/{z}/{x}/{y}.pbf"
                                            }),
                                            declutter: true,
                                            attributions: '<a href="https://fr.wikipedia.org/wiki/Service_central_d%27hydrom%C3%A9t%C3%A9orologie_et_d%27appui_%C3%A0_la_pr%C3%A9vision_des_inondations">SCHAPI</a>',
                                    });
                                    layers.push(schapiLayer);
     
                                    var pciAriegeLayer = new ol.layer.VectorTile({
                                            title: "PCI_RURAL",
                                            description: "PCI Vecteur tuilé test",
                                            mapboxStyleUrl: "https://vectortiles.ign.fr/styles/pci.json",
                                            mapboxStyleSource: "pci",
                                            visible: true,
                                            source: new ol.source.VectorTile({
                                                    format: new ol.format.MVT(),
                                                    url: "https://vectortiles.ign.fr/rok4server/1.0.0/PCI_RURAL/{z}/{x}/{y}.pbf"
                                            }),
                                            declutter: true,
                                            attributions: '<a href="https://geoservices.ign.fr/blog/2018/11/13/lancement_PCI.html">PCI</a>',
                                    });
                                    layers.push(pciAriegeLayer);
     
                                    var bdtopoAriegeBatiLayer = new ol.layer.VectorTile({
                                            title: "BDTOPO_ARIEGE_BATI",
                                            description: "BDTOPO Vecteur tuilé test",
                                            mapboxStyleUrl: "https://vectortiles.ign.fr/styles/bati.json",
                                            mapboxStyleSource: "bdtopo",
                                            visible: true,
                                            source: new ol.source.VectorTile({
                                                    format: new ol.format.MVT(),
                                                    url: "https://vectortiles.ign.fr/rok4server/1.0.0/BDTOPO_BATI_ARIEGE/{z}/{x}/{y}.pbf"
                                            }),
                                            declutter: true,
                                            attributions: '<a href="https://geoservices.ign.fr/blog/2020/10/26/Grand_angle_diffusion_BDTOPO.html">BDTOPO</a>',
                                    });
                                    layers.push(bdtopoAriegeBatiLayer);
     
                                    var bdtopoAriegeLayer = new ol.layer.VectorTile({
                                            title: "BDTOPO_ARIEGE",
                                            description: "BDTOPO Vecteur tuilé test",
                                            mapboxStyleUrl: "https://vectortiles.ign.fr/styles/",
                                            mapboxStyleSource: "bdtopo",
                                            visible: true,
                                            source: new ol.source.VectorTile({
                                                    format: new ol.format.MVT(),
                                                    url: "https://vectortiles.ign.fr/rok4server/1.0.0/BDTOPO_ARIEGE/{z}/{x}/{y}.pbf"
                                            }),
                                            declutter: true,
                                            attributions: '<a href="https://geoservices.ign.fr/blog/2020/10/26/Grand_angle_diffusion_BDTOPO.html">BDTOPO</a>',
                                    });
                                    layers.push(bdtopoAriegeLayer);
     
                                    var map = new ol.Map({
                                            layers: [
                                                    stamenLayer,
                                                    planignLayer,
                                                    schapiLayer,
                                                    pciAriegeLayer,
                                                    bdtopoAriegeLayer,
                                                    bdtopoAriegeBatiLayer
                                            ],
                                            controls: ol.control.defaults({
                                                    zoom: true,
                                                    attribution: true,
                                                    rotate: true
                                            }),
                                            target: 'map',
                                            view: new ol.View({
                                                    center: [287963, 5948655],
                                                    zoom: 6,
                                                    constrainResolution: true
                                            })
                                    });
     
                                    /************************* Application des styles mapbox *************************/
     
                                    layers.forEach(function (layer) {
                                            if (layer.get('mapboxStyleUrl')) {
                                                    fetch(layer.get('mapboxStyleUrl')).then(
                                                            function (response) {
                                                                    if (response.ok) {
                                                                            response.json().then(
                                                                                    function (style) {
                                                                                            olms.applyStyle(layer, style, layer.get('mapboxStyleSource'));
                                                                                    }
                                                                            ).catch(function (error) {
                                                                                    console.error(error);
                                                                            });
                                                                    }
                                                            }
                                                    );
                                            }
                                    });
     
                                    /************************* LAYER SWITCHER *************************/
     
                                    var lsControl = new ol.control.LayerSwitcher({
                                            layers: layers.map(function (layer) {
                                                    return {
                                                            layer: layer,
                                                            config: {
                                                                    title: layer.get('title'),
                                                                    description: layer.get('description')
                                                            }
                                                    }
                                            }),
                                            options: {
                                                    collapsed: true
                                            }
                                    });
     
                                    //Ajout du controle à  la carte
                                    map.addControl(lsControl);
     
                                    // Creation du controle
                                    var searchControl = new ol.control.SearchEngine({});
     
                                    // Ajout à  la carte
                                    map.addControl(searchControl);
     
                                    /************************* AFFICHAGE *************************/
     
                                    // Affichage du niveau en haut à  gauche
                                    map.on("moveend", function () {
                                            var zoom = map.getView().getZoom();
                                            document.getElementById('zoomlevel').innerHTML = zoom;
                                    });
     
                                    // Affichage des informations de la feature du dessus
                                    map.on('click', function (event) {
                                            var infos = '';
                                            var something = false;
                                            map.forEachFeatureAtPixel(event.pixel, function (feature, layer) {
                                                    if (feature.get('layer') !== 'fond_opaque') {
                                                            something = true;
                                                            infos += '<h5>' + layer.get('title') + ' - ' + feature.get('layer') + '</h5><ul>';
                                                            for (const [key, value] of Object.entries(feature.getProperties())) {
                                                                    if (key !== 'layer') {
                                                                            infos += "<li>" + key + ": " + value + "</li>";
                                                                    }
                                                            }
                                                            infos += '</ul>';
                                                    }
                                            }, {
                                                    hitTolerance: 2
                                            });
                                            if (something) {
                                                    infos = '<div onclick="close_infos()" id="croix">x</div>' + infos;
                                                    document.getElementById('infos').innerHTML = infos;
                                                    document.getElementById('infos').style.display = 'block';
                                            } else {
                                                    document.getElementById('infos').style.display = 'none';
                                            }
                                    });
     
                            }
     
                            //Connection au serveur du geoportail
                            Gp.Services.getConfig({
                                    serverUrl: "http://localhost/autoconf.js",
                                    callbackSuffix: "",
                                    onSuccess: go
                            });
     
                            function close_infos() {
                                    document.getElementById('infos').style.display = 'none';
                            }
                                            
                    </script>
     
    	</body>
    </html>

  4. #4
    Membre averti Avatar de lowzonenose
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2014
    Messages
    196
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2014
    Messages : 196
    Points : 407
    Points
    407
    Par défaut
    il n'y a pas de clef pour les fichiers de styles (json) :
    Code JavaScript : Sélectionner tout - Visualiser dans une fenêtre à part
    mapboxStyleUrl: "https://wxs.ign.fr/static/vectorTiles/styles/PLAN.IGN/standard.json"

    Les styles sont publiques.
    Ce n'est pas le cas pour les flux, une clef est nécessaire...

  5. #5
    Membre du Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Mai 2014
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 73
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Mai 2014
    Messages : 71
    Points : 66
    Points
    66
    Par défaut Résolu
    Problème résolu !

    J'avais téléchargé ol-mapbox-style-6.3.2 > olms.js, qui ne fonctionne pas.
    En récupérant olms6.js depuis le code source du démonstrateur, ca fonctionne nickel.

    Y a peut-être un problème, là, mais bon ... pas de mon ressort !

    Merci lowzonenose.

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

Discussions similaires

  1. MapLibre GL et ressource vecteur tuilé de l'IGN
    Par mga_geo dans le forum IGN API Géoportail
    Réponses: 30
    Dernier message: 10/06/2021, 14h44
  2. PLAN IGN V2 - Tuiles pour DOM/COM
    Par kintha dans le forum IGN API Géoportail
    Réponses: 2
    Dernier message: 14/09/2020, 08h40
  3. Openlayers / Carte IGN
    Par sans_deconner dans le forum IGN API Géoportail
    Réponses: 3
    Dernier message: 10/10/2018, 17h00
  4. Amélioration de la couche Plan IGN
    Par Léo Berthoud dans le forum IGN API Géoportail
    Réponses: 4
    Dernier message: 03/10/2014, 14h24
  5. Disparition du marqueur avec OpenLayers + Carte IGN
    Par dontkillkenny dans le forum IGN API Géoportail
    Réponses: 2
    Dernier message: 24/12/2011, 11h29

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