A data layer, also known as an operational layer, is a client-side layer that can access geographic data from a data source. The data source for the layer can be a data service or a file such as GeoJSON.
The data for a data layer is typically stored in ArcGIS as a data service using ArcGIS tools. You can use data layers to display feature or tile data from feature, vector tile, or map tile services in your application.
Feature layers
If you have features containing geometry and attributes, you can import the data to create an ArcGIS feature layer in a feature service. To access the data, you can use the URL of the service to query and return features. You can style and display the results in a map or scene. Feature layers can also contain styling information as part of the service response.
How to publish and display a feature layer
To access and display a hosted feature layer, you use the OpenLayers Vector
and Vector
classes.
- Import your data from a CSV, XLS, GeoJSON, or Shapefile file to create a hosted feature layer.
- Get the URL for the feature layer.
- In your code, reference the OpenLayers CSS, JS, and
ol-mapbox-style
libraries. - Define a
Vector
to access and query the feature service to return GeoJSON features.Source - Display the data in a
Vector
and add the layer to your map.Layer
Example
Display a feature layer (as GeoJSON)
This example demonstrates how to display a feature layer. To get GeoJSON features from a feature layer, you need to provide a URL that queries the feature service and returns the features in GeoJSON format.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.15.1/css/ol.css" type="text/css" />
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.15.1/build/ol.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ol-mapbox-style@6.1.4/dist/olms.js" type="text/javascript"></script>
<script>
olms.apply(map, basemapURL).then(function (map) {
const pointLayerName = "Trailheads";
const pointSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" +
pointLayerName +
"/FeatureServer/0/query?where=1%3D1&outFields=*&returnGeometry=true&f=geojson"
});
const pointLayer = new ol.layer.Vector({
source: pointSource
});
map.addLayer(pointLayer);
});
</script>
Vector tile layers
If you want to access and display your data as vector tile data, first import your tile data, or convert an existing feature layer into a vector tile layer, using ArcGIS Online to create a vector tile service.
Vector tile layers closely follow the Mapbox vector tile specification, but the URL endpoints end in /{z}/{y}/{x}.pbf
, rather than /{z}/{x}/{y}.pbf
.
How to publish and display a vector tile layer
To display the hosted layer in your application, you use the OpenLayers Vector
and Vector
classes.
- Import your data from a CSV, XLS, GeoJSON, or Shapefile file to create a hosted feature layer.
- Style and publish the feature layer as a vector tile layer using ArcGIS Online.
- Get the URL for the vector tile layer.
- In your code, reference the OpenLayers CSS, JS, and
ol-mapbox-style
libraries. - Define a
Vector
source to access and query the vector tile layer.Tile - Display the data in a
Vector
and add the layer to your map.Tile Layer - Define the style of the vector tile layer, found in the Style tab of the item page in your developer dashboard.
Example
Display a vector tile layer
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.15.1/css/ol.css" type="text/css" />
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.15.1/build/ol.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ol-mapbox-style@10.5.0/dist/olms.js"></script>
<script>
olms.apply(map, basemapURL).then((map) => {
const parcelsSource = new ol.source.VectorTile({
format: new ol.format.MVT(),
url: `https://vectortileservices3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_Mountains_Parcels_VTL/VectorTileServer/tile/{z}/{y}/{x}.pbf`
});
const parcelsLayer = new ol.layer.VectorTile({
source: parcelsSource
});
map.addLayer(parcelsLayer);
});
</script>
Map tile layers
If you want to access and display a map tile service containing raster data, you need to use ArcGIS Online to upload the tile data or publish it from an existing feature layer.
How to publish and display a map tile layer
To display the layer, you use the OpenLayers XYZ
and Tile
layer classes.
- In the developer dashboard, import your data from a CSV, XLS, GeoJSON, or Shapefile file to create a hosted feature layer.
- Create a tile layer in ArcGIS Online by navigating to the feature layer's item page > Publish > Tile layer.
- Get the URL for the new tile layer.
- In your code, reference the OpenLayers CSS, JS, and
ol-mapbox-style
libraries. - Define an
XYZ
source to access and query the vector tile layer. - Display the data in a
Tile
layer and add the layer to your map.
Example
Display a map tile layer
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.15.1/css/ol.css" type="text/css" />
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.15.1/build/ol.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ol-mapbox-style@10.5.0/dist/olms.js" type="text/javascript"></script>
<script>
olms.apply(map, basemapURL)
.then(function (map) {
const hillshadeURL = "https://server.arcgisonline.com/ArcGIS/rest/services/Elevation/World_Hillshade/MapServer/tile/{z}/{y}/{x}";
const hillshadeSource = new ol.source.XYZ({
url: hillshadeURL
});
const tileLayer = new ol.layer.Tile({
source: hillshadeSource,
opacity: 0.3
});
map.addLayer(tileLayer);
});
</script>