You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-maps/spatial-io-add-simple-data-layer.md
+88-19Lines changed: 88 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
---
2
-
title: Add a simple data layer | Microsoft Azure Maps
2
+
title: Add a simple data layer
3
+
titleSuffix: Microsoft Azure Maps
3
4
description: Learn how to add a simple data layer using the Spatial IO module, provided by Azure Maps Web SDK.
4
-
author: eriklindeman
5
-
ms.author: eriklind
6
-
ms.date: 02/29/2020
7
-
ms.topic: conceptual
5
+
author: dubiety
6
+
ms.author: yuchungchen
7
+
ms.date: 06/19/2023
8
+
ms.topic: how-to
8
9
ms.service: azure-maps
9
-
ms.custom:
10
10
#Customer intent: As an Azure Maps web sdk user, I want to add simple data layer so that I can render styled features on the map.
11
11
---
12
12
@@ -32,7 +32,60 @@ var layer = new atlas.layer.SimpleDataLayer(datasource);
32
32
map.layers.add(layer);
33
33
```
34
34
35
-
Add features to the data source. Then, the simple data layer will figure out how best to render the features. Styles for individual features can be set as properties on the feature. The following code shows a GeoJSON point feature with a `color` property set to `red`.
35
+
The following code snippet demonstrates using a simple data layer, referencing the data from an online source.
36
+
37
+
```javascript
38
+
functionInitMap()
39
+
{
40
+
var map =newatlas.Map('myMap', {
41
+
center: [-73.967605, 40.780452],
42
+
zoom:12,
43
+
view:"Auto",
44
+
45
+
//Add authentication details for connecting to Azure Maps.
46
+
authOptions: {
47
+
// Get an Azure Maps key at https://azuremaps.com/.
//If bounding box information is known for data, set the map view to it.
75
+
if (r.bbox) {
76
+
map.setCamera({
77
+
bounds:r.bbox,
78
+
padding:50
79
+
});
80
+
}
81
+
}
82
+
});
83
+
}
84
+
});
85
+
}
86
+
```
87
+
88
+
The url passed to the `loadDataSet` function points to the following json:
36
89
37
90
```json
38
91
{
@@ -47,34 +100,48 @@ Add features to the data source. Then, the simple data layer will figure out how
47
100
}
48
101
```
49
102
50
-
The following code renders the above point feature using the simple data layer.
103
+
Once you add features to the data source, the simple data layer figures out how best to render them. Styles for individual features can be set as properties on the feature.
104
+
105
+
The above sample code shows a GeoJSON point feature with a `color` property set to `red`.
51
106
52
-
<br/>
107
+
This sample code renders the point feature using the simple data layer, and appears as follows:
53
108
54
-
<iframeheight="500"scrolling="no"title="Use the Simple data layer"src="//codepen.io/azuremaps/embed/zYGzpQV/?height=500&theme-id=0&default-tab=js,result&editable=true"frameborder='no'loading="lazy"allowtransparency="true"allowfullscreen="true"> See the Pen <a href='https://codepen.io/azuremaps/pen/zYGzpQV/'>Use the simple data layer</a> by Azure Maps (<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.
55
-
</iframe>
109
+
:::image type="content" source="./media/spatial-io-add-simple-data-layer/simple-data-layer.png"alt-text="A screenshot of map with coordinates of 0, 0 that shows a red dot over blue water, the red dot was added using the symbol layer.":::
110
+
111
+
> [!NOTE]
112
+
> Notice that the coordinates set when the map was initialized:
113
+
>
114
+
>   center: [-73.967605, 40.780452]
115
+
>
116
+
> Are overwritten by the value from the datasource:
117
+
>
118
+
>   "coordinates": [0, 0]
119
+
120
+
<!------------------------------------
121
+
<iframe height="500" scrolling="no" title="Use the Simple data layer" src="//codepen.io/azuremaps/embed/zYGzpQV/?height=500&theme-id=0&default-tab=js,result&editable=true" frameborder='no' loading="lazy" allowtransparency="true" allowfullscreen="true"> See the Pen <a href='https://codepen.io/azuremaps/pen/zYGzpQV/'>Use the simple data layer</a> by Azure Maps (<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.</iframe>
122
+
------------------------------------>
56
123
57
124
The real power of the simple data layer comes when:
58
125
59
126
- There are several different types of features in a data source; or
60
127
- Features in the data set have several style properties individually set on them; or
61
128
- You're not sure what the data set exactly contains.
62
129
63
-
For example when parsing XML data feeds, you may not know the exact styles and geometry types of the features. The following sample shows the power of the simple data layer by rendering the features of a KML file. It also demonstrates various options that the simple data layer class provides.
64
-
65
-
<br/>
130
+
For example when parsing XML data feeds, you may not know the exact styles and geometry types of the features. The [Simple data layer options] sample shows the power of the simple data layer by rendering the features of a KML file. It also demonstrates various options that the simple data layer class provides.
66
131
67
-
<iframeheight="700"scrolling="no"title="Simple data layer options"src="//codepen.io/azuremaps/embed/gOpRXgy/?height=700&theme-id=0&default-tab=result"frameborder='no'loading="lazy"allowtransparency="true"allowfullscreen="true"> See the Pen <a href='https://codepen.io/azuremaps/pen/gOpRXgy/'>Simple data layer options</a> by Azure Maps (<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.
68
-
</iframe>
132
+
:::image type="content" source="./media/spatial-io-add-simple-data-layer/simple-data-layer-options.png"alt-text="A screenshot of map with a panel on the left showing the different simple data layer options.":::
69
133
134
+
<!------------------------------------
135
+
<iframe height="700" scrolling="no" title="Simple data layer options" src="//codepen.io/azuremaps/embed/gOpRXgy/?height=700&theme-id=0&default-tab=result" frameborder='no' loading="lazy" allowtransparency="true" allowfullscreen="true"> See the Pen <a href='https://codepen.io/azuremaps/pen/gOpRXgy/'>Simple data layer options</a> by Azure Maps (<a href='https://codepen.io/azuremaps'>@azuremaps</a>) on <a href='https://codepen.io'>CodePen</a>.</iframe>
136
+
------------------------------------>
70
137
71
138
> [!NOTE]
72
139
> This simple data layer uses the [popup template](map-add-popup.md#add-popup-templates-to-the-map) class to display KML balloons or feature properties as a table. By default, all content rendered in the popup will be sandboxed inside of an iframe as a security feature. However, there are limitations:
73
140
>
74
-
> - All scripts, forms, pointer lock and top navigation functionality is disabled. Links are allowed to open up in a new tab when clicked.
141
+
> - All scripts, forms, pointer lock and top navigation functionality is disabled. Links are allowed to open up in a new tab when clicked.
75
142
> - Older browsers that don't support the `srcdoc` parameter on iframes will be limited to rendering a small amount of content.
76
-
>
77
-
> If you trust the data being loaded into the popups and potentially want these scripts loaded into popups be able to access your application, you can disable this by setting the popup templates `sandboxContent` option to false.
143
+
>
144
+
> If you trust the data being loaded into the popups and potentially want these scripts loaded into popups be able to access your application, you can disable this by setting the popup templates `sandboxContent` option to false.
78
145
79
146
## Default supported style properties
80
147
@@ -191,3 +258,5 @@ See the following articles for more code samples to add to your maps:
191
258
192
259
> [!div class="nextstepaction"]
193
260
> [Supported data format details](spatial-io-supported-data-format-details.md)
261
+
262
+
[Simple data layer options]: https://samples.azuremaps.com/spatial-io-module/simple-data-layer-options
0 commit comments