can't implement L.mapbox.simplestyle with geoJson

∥☆過路亽.° 提交于 2020-01-06 12:56:39

问题


I'm trying to implement simplestyle's options for marker size and color , but can't get them to render. In this simple test case, I'm trying to follow Mapbox's own example quite closely:

var myData = [
      {
        "type": "Feature",
        "geometry": {
          "type": "Point",
          "coordinates": [4.509373,51.932994]
        },
        "properties": {
             "marker-size": "large",
             "marker-color": "#ffcc00"
        }
      }
    ];

var map = L.mapbox.map('map', 'examples.map-20v6611k')
    .setView([51.932994,4.509373], 8);

L.geoJson(myData, { style: L.mapbox.simplestyle.style }).addTo(map);

fiddle

But the marker renders in default style. What am I missing?


回答1:


OK, I've got it working using this extended function from this page of Mapbox's documentation:

L.geoJson(myData, {
    pointToLayer: L.mapbox.marker.style,
    style: function(feature) { return feature.properties; }
}).addTo(map);

The other Mapbox example didn't make it look like the pointToLayer argument was required, but whatever works:

fiddle




回答2:


Another alternative would be to create a featureLayer based on your myData:

var featureLayer = L.mapbox.featureLayer(myData).addTo(map);

Your data will have to be an object, however, and not an array:

var myData = {
    "type": "Feature",
    "geometry": {
      "type": "Point",
      "coordinates": [4.509373,51.932994]
    },
    "properties": {
         "marker-size": "large",
         "marker-color": "#ffcc00"
    }
  };


来源:https://stackoverflow.com/questions/23962684/cant-implement-l-mapbox-simplestyle-with-geojson

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