Do embedded GeoJSON styles work with Mapbox GL?

旧城冷巷雨未停 提交于 2019-12-08 02:35:59

问题


Is it possible to utilize the built-in properties attribute of a GeoJSON data source to automatically style a Mapbox GL map without having to pre-specify a style?

I have a use case where I dynamically load in GeoJSON LineString data that needs to be a particular color and it already has style data built in:

{"properties": {"color": "#ffff33"...

Right now, I have a rather inelegant setup where the relevant color is parsed out, translated into a style, and added to the map upon every load:

    $scope.patternPropToStyle = function(props) {
      var id = 'pattern' + props.pid;
      var style = {
        "id": id,
        "type": "line",
        "source": id,
        "render": {
          "$type": "LineString",
          "line-join": "round",
          "line-cap": "round"
        },
        "paint": {
          "line-color": props.color,
          "line-width": 8
        }
      }
      $scope._mapStyle.layers.push(style);
      $scope._map.setStyle($scope._mapStyle);
    }

I feel like there has to be a better way to do this.


回答1:


Currently, no - simplestyle-spec isn't supported in Mapbox GL. Currently the GeoJSON support is still very primitive, given that the focus was initially on vector tiles. simplestyle-spec support is certainly in the plans.



来源:https://stackoverflow.com/questions/28470476/do-embedded-geojson-styles-work-with-mapbox-gl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!