Add vector layer or vector layer view
To add a vector layer or vector layer view to the map, first copy the uuid of the vector layer from the geobox portal and get the vector layer from the server: (examples are explained for vector layer, but the same is true for vector layer view.)
getVectorLayer(layer_uuid)
Example:
const vectorLayer = await Server.getVectorLayer('4f9f3e4b-4dc1-469b-83ab-00ae00f02581');
After getting the vector layer, it is necessary to create a feature layer from the vector layer. For this, use the featureLayer creation guide.
newFeatureLayer(options)
Example:
var fLayer = map.newFeatureLayer({ source: vectorLayer });
After the new object is created from the newFeatureLayer class, you need to load the features of the layer.
loadFeatures(options)
Parameters:
options (Object)
Name | Description |
---|---|
options.f
String
Default: ‘topojson’
|
Output format. Choices are: ‘topojson’ | ‘json’ |
options.skip
Number?
Default: 0
|
Number of skipped features. |
options.limit
Number?
Default:1000
|
Maximum number for result features. |
options.order_by
String?
|
Comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D NOTE: “A” denotes ascending order and “D” denotes descending order. |
Returns:
GeoJSON: Returns GeoJSON of features.
Example:
await fLayer.loadFeatures({ f: 'topojson', skip:0, limit:1000, order_by: 'id A' });
Finally, add the layer to the map using the addToMap method.
addToMap()
Example:
fLayer.addToMap();
After adding the layer to the map, it is better to change the view of the map to the layer extent. For this purpose, use the zoomToAll method.
zoomToAll()
Example:
fLayer.zoomToAll();
See the Pen Contact Form – Pen a Day 20 by Geobox (@geobox-gl-demo) on CodePen.1