Skip to content

Commit cca2927

Browse files
authored
Merge pull request #292849 from stevemunk/spatial-io-add-simple-data-layer-update-sample-code
Updated sample code and screenshot for 'simple data layer' example.
2 parents 47d27bf + 4a3ce97 commit cca2927

File tree

2 files changed

+61
-62
lines changed

2 files changed

+61
-62
lines changed
2.25 KB
Loading

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

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -36,65 +36,68 @@ map.layers.add(layer);
3636
The following code snippet demonstrates using a simple data layer, referencing the data from an online source.
3737

3838
```javascript
39-
function InitMap()
40-
{
41-
var map = new atlas.Map('myMap', {
42-
center: [-73.967605, 40.780452],
43-
zoom: 12,
44-
view: "Auto",
45-
46-
//Add authentication details for connecting to Azure Maps.
47-
authOptions: {
48-
// Get an Azure Maps key at https://azuremaps.com/.
49-
authType: 'subscriptionKey',
50-
subscriptionKey: '{Your-Azure-Maps-Subscription-key}'
51-
},
52-
});
53-
54-
//Wait until the map resources are ready.
55-
map.events.add('ready', function () {
56-
57-
//Create a data source and add it to the map.
58-
var datasource = new atlas.source.DataSource();
59-
map.sources.add(datasource);
60-
61-
//Add a simple data layer for rendering data.
62-
var layer = new atlas.layer.SimpleDataLayer(datasource);
63-
map.layers.add(layer);
64-
65-
//Load an initial data set.
66-
const dataSet = {
67-
"type": "Feature",
68-
"geometry": {
69-
"type": "Point",
70-
"coordinates": [0, 0]
71-
},
72-
"properties": {
73-
"color": "red"
74-
}
75-
};
76-
77-
loadDataSet(dataSet);
78-
79-
function loadDataSet(url) {
80-
//Read the spatial data and add it to the map.
81-
atlas.io.read(url).then(r => {
82-
if (r) {
83-
//Update the features in the data source.
84-
datasource.setShapes(r);
85-
86-
//If bounding box information is known for data, set the map view to it.
87-
if (r.bbox) {
88-
map.setCamera({
89-
bounds: r.bbox,
90-
padding: 50
91-
});
92-
}
93-
}
94-
});
39+
<script src="https://atlas.microsoft.com/sdk/javascript/spatial/0/atlas-spatial.min.js"></script>
40+
41+
<script>
42+
function InitMap() {
43+
var map = new atlas.Map("myMap", {
44+
center: [-73.967605, 40.780452],
45+
zoom: 12,
46+
view: "Auto",
47+
48+
//Add authentication details for connecting to Azure Maps.
49+
authOptions: {
50+
// Get an Azure Maps key at https://azuremaps.com/.
51+
authType: "subscriptionKey",
52+
subscriptionKey: '{Your-Azure-Maps-Subscription-key}'
53+
}
54+
});
55+
56+
//Wait until the map resources are ready.
57+
map.events.add("ready", function () {
58+
//Create a data source and add it to the map.
59+
var datasource = new atlas.source.DataSource();
60+
map.sources.add(datasource);
61+
62+
//Add a simple data layer for rendering data.
63+
var layer = new atlas.layer.SimpleDataLayer(datasource);
64+
map.layers.add(layer);
65+
66+
//Load an initial data set.
67+
const dataSet = {
68+
type: "FeatureCollection",
69+
bbox: [0, 0, 0, 0],
70+
features: [
71+
{
72+
type: "Feature",
73+
geometry: {
74+
type: "Point",
75+
coordinates: [0, 0]
76+
},
77+
properties: {
78+
color: "red"
79+
}
80+
}
81+
]
82+
};
83+
84+
loadDataSet(dataSet);
85+
86+
function loadDataSet(r) {
87+
//Update the features in the data source.
88+
datasource.setShapes(r);
89+
90+
//If bounding box information is known for data, set the map view to it.
91+
if (r.bbox) {
92+
map.setCamera({
93+
bounds: r.bbox,
94+
padding: 50
95+
});
96+
}
97+
}
98+
});
9599
}
96-
});
97-
}
100+
</script>
98101
```
99102

100103
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.
@@ -114,10 +117,6 @@ This sample code renders the point feature using the simple data layer, and appe
114117
>
115118
> &emsp; "coordinates": [0, 0]
116119
117-
<!------------------------------------
118-
> [!VIDEO //codepen.io/azuremaps/embed/zYGzpQV/?height=500&theme-id=0&default-tab=js,result&editable=true]
119-
------------------------------------>
120-
121120
The real power of the simple data layer comes when:
122121

123122
- There are several different types of features in a data source; or

0 commit comments

Comments
 (0)