как получить доступ к элементу массива GeoJSON - PullRequest
0 голосов
/ 30 апреля 2018

Я ищу доступ ко всем свойствам моего geoJson.

Например, как мне получить доступ к geoJson.features.properties.messagePerso?

Я хочу иметь возможность с помощью что-то вроде innerHTML отображать messagePerso в div и переходить от одного к другому с помощью кнопки.

var geojson = {

"features": [
    {
        "type": "Feature",
        "properties": {
            "message": " url(img/1.jpg) 50% 50%",
            "messagePerso": " croisement des canaux sambre/bxl-charleroi",
            "iconSize": [20,20]
        },
        "geometry": {
            "type": "Point",
            "coordinates": [
              4.427333,50.413140
            ]
        }
    },
    {
        "type": "Feature",
        "properties": {
            "message":" url(img/13.jpg) 50% 50%",
             "messagePerso": "Saint théodore Est/ Vue sur carsid désafecté",
            "iconSize": [20,20]
        },
        "geometry": {
            "type": "Point",
            "coordinates": [
        4.418988,50.417823
            ]
        }
    }

На данный момент я использовал файлы json, чтобы создать несколько точек на карте и использовать их в качестве кнопок для отображения некоторых элементов файлов json с чем-то вроде

id.innerHTML = marker.properties.message;

Но как сделать одну кнопку, которая отображает следующую marker.properties.message?

geojson.features.forEach(function(marker) {

var el = document.createElement('div');
el.className = 'marker';
var yoo = $('.marker').length;

 $('.marker').each( function(i){
 $(this).attr('id','marker'+(i))
 });
el.style.width ='15px';
el.style.height = '15px';

el.style.opacity =0;

el.addEventListener('click', function() {
 numlegende2.innerHTML = marker.properties.message;
 map.flyTo({center:marker.geometry.coordinates});   
});
  });
...