|
| 1 | +--- |
| 2 | +title: Create a feature stateset |
| 3 | +titleSuffix: Microsoft Azure Maps Creator |
| 4 | +description: How to create a feature stateset using the Creator REST API. |
| 5 | +author: brendansco |
| 6 | +ms.author: Brendanc |
| 7 | +ms.date: 03/03/2023 |
| 8 | +ms.topic: how-to |
| 9 | +ms.service: azure-maps |
| 10 | +services: azure-maps |
| 11 | +--- |
| 12 | + |
| 13 | +# Create a feature stateset |
| 14 | + |
| 15 | +[Feature statesets] define dynamic properties and values on specific features that support them. This article explains how to create a stateset that defines values and corresponding styles for a property and changing a property's state. |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +* Successful completion of [Query datasets with WFS API]. |
| 20 | +* The `datasetId` obtained in the [Check the dataset creation status] section of the *Use Creator to create indoor maps* tutorial. |
| 21 | + |
| 22 | +>[!IMPORTANT] |
| 23 | +> |
| 24 | +> * This article uses the `us.atlas.microsoft.com` geographical URL. If your Creator service wasn't created in the United States, you must use a different geographical URL. For more information, see [Access to Creator Services]. |
| 25 | +> * In the URL examples in this article you will need to replace: |
| 26 | +> * `{Azure-Maps-Subscription-key}` with your Azure Maps subscription key. |
| 27 | +> * `{datasetId}` with the `datasetId` obtained in the [Check the dataset creation status] section of the *Use Creator to create indoor maps* tutorial |
| 28 | +
|
| 29 | +## Create the feature stateset |
| 30 | + |
| 31 | +To create a stateset: |
| 32 | + |
| 33 | +Create a new **HTTP POST Request** that uses the [Stateset API]. The request should look like the following URL: |
| 34 | + |
| 35 | +```http |
| 36 | +https://us.atlas.microsoft.com/featurestatesets?api-version=2.0&datasetId={datasetId}&subscription-key={Your-Azure-Maps-Subscription-key} |
| 37 | +``` |
| 38 | + |
| 39 | +Next, set the `Content-Type` to `application/json` in the **Header** of the request. |
| 40 | + |
| 41 | +If using a tool like [Postman], it should look like this: |
| 42 | + |
| 43 | +:::image type="content" source="./media/tutorial-creator-indoor-maps/stateset-header.png"alt-text="A screenshot of Postman showing the Header tab of the POST request that shows the Content Type Key with a value of application forward slash json."::: |
| 44 | + |
| 45 | +Finally, in the **Body** of the HTTP request, include the style information in raw JSON format, this applies different colors to the `occupied` property depending on its value: |
| 46 | + |
| 47 | +```json |
| 48 | +{ |
| 49 | + "styles":[ |
| 50 | + { |
| 51 | + "keyname":"occupied", |
| 52 | + "type":"boolean", |
| 53 | + "rules":[ |
| 54 | + { |
| 55 | + "true":"#FF0000", |
| 56 | + "false":"#00FF00" |
| 57 | + } |
| 58 | + ] |
| 59 | + } |
| 60 | + ] |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +After the response returns successfully, copy the `statesetId` from the response body. In the next section, you'll use the `statesetId` to change the `occupancy` property state of the unit with feature `id` "UNIT26". If using Postman, it will appear as follows: |
| 65 | + |
| 66 | +:::image type="content" source="./media/tutorial-creator-indoor-maps/response-stateset-id.png"alt-text="A screenshot of Postman showing the resource Stateset ID value in the responses body."::: |
| 67 | + |
| 68 | +## Update a feature state |
| 69 | + |
| 70 | +In this section you will learn how to update the `occupied` state of the unit with feature `id` "UNIT26". To do this, create a new **HTTP PUT Request** calling the [Feature Statesets API]. The request should look like the following URL (replace `{statesetId}` with the `statesetId` obtained in [Create a feature stateset](#create-a-feature-stateset)): |
| 71 | + |
| 72 | +```http |
| 73 | +https://us.atlas.microsoft.com/featurestatesets/{statesetId}/featureStates/UNIT26?api-version=2.0&subscription-key={Your-Azure-Maps-Subscription-key} |
| 74 | +``` |
| 75 | + |
| 76 | +Next, set the `Content-Type` to `application/json` in the **Header** of the request. |
| 77 | + |
| 78 | +If using a tool like [Postman], it should look like this: |
| 79 | + |
| 80 | +:::image type="content" source="./media/tutorial-creator-indoor-maps/stateset-header.png"alt-text="A screenshot of the header tab information for stateset creation."::: |
| 81 | + |
| 82 | +Finally, in the **Body** of the HTTP request, include the style information in raw JSON format, this applies different colors to the `occupied` property depending on its value: |
| 83 | + |
| 84 | +```json |
| 85 | +{ |
| 86 | + "states": [ |
| 87 | + { |
| 88 | + "keyName": "occupied", |
| 89 | + "value": true, |
| 90 | + "eventTimestamp": "2020-11-14T17:10:20" |
| 91 | + } |
| 92 | + ] |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +>[!NOTE] |
| 97 | +> The update will be saved only if the time posted stamp is after the time stamp of the previous request. |
| 98 | +
|
| 99 | +Once the HTTP request is sent and the update completes, you'll receive a `200 OK` HTTP status code. If you implemented [dynamic styling] for an indoor map, the update displays at the specified time stamp in your rendered map. |
| 100 | + |
| 101 | +## Additional information |
| 102 | + |
| 103 | +* For information on how to retrieve the state of a feature using its feature id, see [Feature State - List States]. |
| 104 | +* For information on how to delete the stateset and its resources, see [Feature State - Delete Stateset]. |
| 105 | +* For information on using the Azure Maps Creator [Feature State service] to apply styles that are based on the dynamic properties of indoor map data features, see how to article [Implement dynamic styling for Creator indoor maps]. |
| 106 | + |
| 107 | +* For more information on the different Azure Maps Creator services discussed in this article, see [Creator Indoor Maps]. |
| 108 | + |
| 109 | +## Next steps |
| 110 | + |
| 111 | +Learn how to implement dynamic styling for indoor maps. |
| 112 | + |
| 113 | +> [!div class="nextstepaction"] |
| 114 | +> [dynamic styling] |
| 115 | +
|
| 116 | +[Access to Creator Services]: how-to-manage-creator.md#access-to-creator-services |
| 117 | +[Query datasets with WFS API]: how-to-creator-wfs.md |
| 118 | +[Stateset API]: /rest/api/maps/v2/feature-state/create-stateset |
| 119 | +[Feature Statesets API]: /rest/api/maps/v2/feature-state/create-stateset |
| 120 | +[Feature statesets]: /rest/api/maps/v2/feature-state |
| 121 | +[Check the dataset creation status]: tutorial-creator-indoor-maps.md#check-the-dataset-creation-status |
| 122 | +[dynamic styling]: indoor-map-dynamic-styling.md |
| 123 | +[Feature State - List States]: /rest/api/maps/v2/feature-state/list-states |
| 124 | +[Feature State - Delete Stateset]: /rest/api/maps/v2/feature-state/delete-stateset |
| 125 | +[Feature State service]: /rest/api/maps/v2/feature-state |
| 126 | +[Implement dynamic styling for Creator indoor maps]: indoor-map-dynamic-styling.md |
| 127 | +[Creator Indoor Maps]: creator-indoor-maps.md |
| 128 | +[Postman]: https://www.postman.com/ |
0 commit comments