通过javascript,MapBox中的URL加载样式GeoJSON多边形

时间:2016-01-21 06:19:51

标签: javascript css leaflet mapbox

下面是一些代码,它产生两个多边形图层,默认情况下显示为灰色,半透明阴影多边形:

// Create the Storage service object
Storage storage = new Storage(httpTransport, jsonFactory, credential);

// Create a new batch request
BatchRequest batch = storage.batch();

// Add some requests to the batch request
storage.objectAccessControls().insert("bucket-name", "object-key1",
    new ObjectAccessControl().setEntity("user-123423423").setRole("READER"))
    .queue(batch, callback);
storage.objectAccessControls().insert("bucket-name", "object-key2",
    new ObjectAccessControl().setEntity("user-guy@example.com").setRole("READER"))
    .queue(batch, callback);
storage.objectAccessControls().insert("bucket-name", "object-key3",
    new ObjectAccessControl().setEntity("group-foo@googlegroups.com").setRole("OWNER"))
    .queue(batch, callback);

// Execute the batch request. The individual callbacks will be called when requests finish.
batch.execute();

是否可以指定填充颜色,不透明度等?已经尝试了几乎所有的东西,我只是无法到达那里。提前谢谢。

1 个答案:

答案 0 :(得分:0)

L.mapbox.featureLayer的签名如下:

  

L.mapbox.featureLayer(id | url | geojson,options)

https://www.mapbox.com/mapbox.js/api/v2.2.4/l-mapbox-featurelayer/#section-l-mapbox-featurelayer

这意味着您可以将URL作为第一个参数直接传递给它,因此您无需使用loadURL。如果以后想要重新加载或加载其他URL,则可以使用它。要在图层功能上设置样式,您可以使用setStyle方法中所述的L.FeatureGroup文档中所述L.mapbox.featureLayer扩展自L.mapbox.featureLayer('data/SeniorsAge65+.geojson').setStyle({fillColor: 'red'}) 的方法:

  

为具有setStyle方法的组的每个图层设置给定的路径选项。

http://leafletjs.com/reference.html#featuregroup-setstyle

归结为这样的事情:

import

样式对象支持此链接中描述的所有路径选项:

http://leafletjs.com/reference.html#path-options