Skip to content

Commit c7351e8

Browse files
authored
Merge pull request #111016 from stevemunk/spatial-io-add-simple-data-layer
Removed CodePen samples from article: Add a simple data layer
2 parents fd51466 + 4a227e7 commit c7351e8

File tree

3 files changed

+88
-19
lines changed

3 files changed

+88
-19
lines changed
352 KB
Loading
13.9 KB
Loading

articles/azure-maps/spatial-io-add-simple-data-layer.md

Lines changed: 88 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: Add a simple data layer | Microsoft Azure Maps
2+
title: Add a simple data layer
3+
titleSuffix: Microsoft Azure Maps
34
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
89
ms.service: azure-maps
9-
ms.custom:
1010
#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.
1111
---
1212

@@ -32,7 +32,60 @@ var layer = new atlas.layer.SimpleDataLayer(datasource);
3232
map.layers.add(layer);
3333
```
3434

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+
function InitMap()
39+
{
40+
var map = new atlas.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/.
48+
authType: 'subscriptionKey',
49+
subscriptionKey: '{Your-Azure-Maps-Subscription-key}'
50+
},
51+
});
52+
53+
//Wait until the map resources are ready.
54+
map.events.add('ready', function () {
55+
56+
//Create a data source and add it to the map.
57+
var datasource = new atlas.source.DataSource();
58+
map.sources.add(datasource);
59+
60+
//Add a simple data layer for rendering data.
61+
var layer = new atlas.layer.SimpleDataLayer(datasource);
62+
map.layers.add(layer);
63+
64+
//Load an initial data set.
65+
loadDataSet('https://s3-us-west-2.amazonaws.com/s.cdpn.io/1717245/use-simple-data-layer.json');
66+
67+
function loadDataSet(url) {
68+
//Read the spatial data and add it to the map.
69+
atlas.io.read(url).then(r => {
70+
if (r) {
71+
//Update the features in the data source.
72+
datasource.setShapes(r);
73+
74+
//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:
3689

3790
```json
3891
{
@@ -47,34 +100,48 @@ Add features to the data source. Then, the simple data layer will figure out how
47100
}
48101
```
49102

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`.
51106

52-
<br/>
107+
This sample code renders the point feature using the simple data layer, and appears as follows:
53108

54-
<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>.
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+
> &emsp; center: [-73.967605, 40.780452]
115+
>
116+
> Are overwritten by the value from the datasource:
117+
>
118+
> &emsp; "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+
------------------------------------>
56123

57124
The real power of the simple data layer comes when:
58125

59126
- There are several different types of features in a data source; or
60127
- Features in the data set have several style properties individually set on them; or
61128
- You're not sure what the data set exactly contains.
62129

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.
66131

67-
<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>.
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.":::
69133

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+
------------------------------------>
70137

71138
> [!NOTE]
72139
> 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:
73140
>
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.
75142
> - 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.
78145
79146
## Default supported style properties
80147

@@ -191,3 +258,5 @@ See the following articles for more code samples to add to your maps:
191258
192259
> [!div class="nextstepaction"]
193260
> [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

Comments
 (0)