How to get data from an interactive map layer
This example shows how to read data from and write it to an interactive map layer on Node.js using HERE Data SDK for TypeScript.
Build and run an app on Node.js
Before you build an app, make sure that you installed all of the dependencies.
To build and run an app on Node.js:
- Create an npm project.
mkdir example-app && cd example-app && npm init- Initialize a TypeScript project.
tsc --init- Install node types.
npm install --save-dev @types/node- Install the SDK modules.
npm install --save @here/olp-sdk-authentication @here/olp-sdk-dataservice-read @here/olp-sdk-dataservice-apiNow, everything is set to create the app.
5. Create the index.ts file and app skeleton.
/**
* An example of the Node.js app used for reading data from and writing it to an interactive map layer in the datastore.
*/
class App {
run() {
console.log("App works!");
}
}
const app = new App();
app.run();- Compile and run the app.
tsc && node .After a successful run, the console displays the following message:
App works!
Create RequestBuilder
RequestBuilderYou need RequestBuilder to use the InteractiveApi functions from @here/olp-sdk-dataservice-api. You can use the InteractiveApi functions to request any data from an interactive map layer.
To create the RequestBuilder instance:
- Create the
OlpClientSettingsobject. For instructions, see Create platform client settings. - Create the
RequestBuilderinstance withRequestFactorythat contains the catalog HRN, platform client settings from step 1, API name, and API version.
const requestBuilder = await RequestFactory.create(
"interactive",
"v1",
settings,
HRN.fromString("your-catalog-HRN")
);Get data from an interactive map layer
Each interactive map layer has a different set of features that you can request and use to work with map data.
You can request one or several features of the interactive map layer using their IDs, tiles that contain them, a bounding box, spatial search, search, iteration, and statistics.
Note
When you request features from the interactive map layer, you get
FeatureCollectioneven if the request returns only one feature or there are no features found.
The interactive API supports the following tile types:
web– for the Mercator projection (used by OpenStreetMap, Google Maps, and Bing Maps). Format:level_x_y. For example,10_100_100means level 10, x-coordinate 100, and y-coordinate 100.tms– for the Tile Map Service specification developed by the Open Source Geospatial Foundation. Format:level_x_y. For example,10_100_100means level 10, x-coordinate 100, y-coordinate 100.quadkey– for quadtree keys used by Bing Maps (formerly Virtual Earth). For example,0123031233is a quadkey for the level 10 tile.here– for the HERE tiling schema.
To get features from the interactive layer:
- Create the
RequestBuilderobject. - Depending on what you want to use to get features, do one of the following:
- To get one feature using its ID, call the
getFeaturefunction with the request builder, feature ID, and layer ID.
const result = await InteractiveApi.getFeature(requestBuilder, {
featureId: "your-feature-id",
layerId: "your-layer-id",
});- To get more than one feature using their IDs, call the
getFeaturesfunction with the request builder, IDs of these features, and layer ID.
const result = await InteractiveApi.getFeatures(requestBuilder, {
id: "your-feature1-id,your-feature2-id",
layerId: "your-layer-id",
});- To get features using a bounding box, call the
getFeaturesByBBoxfunction with the request builder, bounding box, and layer ID.
const result = await InteractiveApi.getFeaturesByBBox(requestBuilder, {
bbox: "13.082,52.416,13.628,52.626", // Bounding box of Berlin
layerId: "your-layer-id",
});- To get features using a tile, call the
getFeaturesByTilefunction with the request builder, tile type, tile ID, layer ID, and parameters, which are additional feature properties.
const result = await InteractiveApi.getFeaturesByTile(requestBuilder, {
tileType: "your tile type",
tileId: "your-tileId",
layerId: "your-layer-id",
params: "your-params-string",
});- To get features using the spatial search, call one of the following functions:
- The
getFeaturesBySpatialfunction with the request builder, latitude and longitude in the WGS84 decimal degrees, and layer ID.
const result = await InteractiveApi.getFeaturesBySpatial(requestBuilder, { lat: "latitude-in-WGS84-decimal-degrees", lng: "longitude-in-WGS84-decimal-degrees", layerId: "your-layer-id", });- The
getFeaturesBySpatialPostfunction with the request builder, layer ID, and search radius in meters.
const result = await InteractiveApi.getFeaturesBySpatial(requestBuilder, { layerId: "your-layer-id", radius: "radius-in-meters", }); - The
With the spatial search, you can find all features around a given position or in a given region. For more information, see Spatial search for features in the Data API Guide.
-
To get features using the search, call the
searchFeaturesfunction.For more information, see Searching for features in the Data API Guide.
-
To get features using iteration, call the iterateFeatures function.
You get an ordered set of features, and none of them is returned twice. For more information, see Iterating features in the Data API Guide.
-
To get features using statistics, call the
getStatisticsfunction with the ID of the layer.const result = await InteractiveApi.getStatistics(requestBuilder, { layerId: "your-layer-id", });
Update data and publish it to an interactive map layer
For information on how to publish data, see How to update data and publish it to an interactive map layer.
Delete data from an interactive map layer
For information on how to delete data, see How to delete data from an interactive map layer.
Updated 9 days ago