Получить URL-адрес значка из geo json в mapbox gl - PullRequest
1 голос
/ 08 мая 2020

У меня есть гео json

{
   "type":"FeatureCollection",
   "features":[
      {
         "type":"Feature",
         "geometry":{
            "type":"Point",
            "coordinates":[
               -75.70439994335175,
               4.72285137053331
            ]
         },
         "properties":{
            "category":"pajaros",
            "icon":{
               "iconUrl":"http:\/\/tupale.co\/milfs\/images\/secure\/?file=150\/b93a3b673df42a1eb5ca85ffcfa21389.jpg\u002674",
               "iconSize":[
                  60
               ]
            },

            "563":"",
            "564":"b93a3b673df42a1eb5ca85ffcfa21389.jpg",
            "567":"-75.70439994335175 4.72285137053331 18",
            "title":"Semillero andino ( hembra )",
            "566":"Semillero andino ( hembra )",
            "localizacion":"-75.70439994335175 4.72285137053331 18 ",
            "description":"Contenido del json",
            "control":"024a69ad3b495e5c323402211bc7aa97",
            "latLng":[
               -75.70439994335175,
               4.72285137053331
            ],
            "time":1467590201,
            "name":1480263964
         }
      }
   ]
} 

И эта функция

        /**
         * This is where your '.addLayer()' used to be, instead
         * add only the source without styling a layer
         */
        map.addSource('places', {
          'type': 'geojson',
        //  'data': stores
          'data': 'http://localhost/tupali/cache/45.json'
        });
        map.addLayer({
        'id': 'points',
        'type': 'symbol',
        'source': 'places',
        'layout': {
        // get the icon name from the source's "icon" property
        // concatenate the name to get an icon from the style's sprite sheet
        'icon-image': ['concat', ['get', 'iconUrl'], '-15'],
        // get the title name from the source's "title" property
        'text-field': ['get', 'title'],
        'text-font': ['Open Sans Semibold', 'Arial Unicode MS Bold'],
        'text-offset': [0, 0.6],
        'text-anchor': 'top'
        }
        });

      });

Как я могу получить iconUrl и размер значка из geo json? Я пробую "'icon-image': ['concat', ['get', 'icon'], '-15']," но получаю любой массив, и я не знаю, как его взорвать. "Image" {"iconUrl": "http://localhost//tupali/milfs/images/secure/?file=150 / e1b0013409d0ed4a67c292999928c295.jpg & 74 ", "iconSize": [60]} "не может быть загружено."

1 Ответ

2 голосов
/ 10 мая 2020

Mapbox-GL- JS не может загружать изображения по URL таким способом. Сначала вам нужно добавить нужные изображения, используя map.loadImage() и map.addImage().

https://docs.mapbox.com/mapbox-gl-js/api/#map # loadimage

...