GUIDE4YOU - 如何添加动态图层


来自

guide4you的家伙在使这个lib开源方面做得很好!!

我已经成功地拥有一个有效的演示指南4you示例。

库的可调节程度如何?例如,如何使用GeoJSON而不是KML添加图层。是否可以动态添加层(使用自己的javascript(而不是预定义?

以这个为例:https://openlayers.org/en/latest/examples/geojson.html

更具体地说:该示例如何与 guide4you 一起使用?

亲切问候

山 姆

要在 guide4 中使用 GeoJSON 层,您只需在 layerconfig 中指定类型"GeoJSON"。

{ "id": "3", "type": "GeoJSON", "source": { "url": "path/to/geojson" } }

有关一些示例,另请参阅 https://github.com/KlausBenndorf/guide4you/blob/master/conf/full/layers.commented.json

如果你想用javascript动态添加一个层,你可以使用这个api函数:

map.get('api').addFeatureLayer({ "id": "3", "type": "GeoJSON", "source": { "url": "path/to/geojson" }, "visible": true })

可能的选项与层配置中的选项相同。

如果您只想添加新功能,则可以创建类型为"Intern"的图层,并添加具有开放图层功能的功能。要素图层的源是 ol.source.Vector 的子类。在下面的示例中,我假设 geojsonObject 与 openlayers 的 geojson 示例中的类型相同。 var layer = map.get('api').addFeatureLayer({ "id": "3", "type": "Intern", "source": { "features": [] }, "visible": true }); layer.getSource().addFeatures((new ol.format.GeoJSON()).readFeatures(geojsonObject));

最后但并非最不重要的一点是,您可以使用简化的 API 来定义 layerConfig 对象中的功能,如下所示:

{ "id": "3", "type": "Intern", "source": { "features": [{ "id": 6, "name": "Some feature", "description: "Some description", "style": "#defaultStyle", "geometryWKT": "... any wkt string here ..." },{ "geometryWKT": "... any wkt string here ..." }] } }

这可以在 layerConfig 文件或 addFeatureLayer api 方法中使用。

最新更新