Skip to content

Commit ad3c8e0

Browse files
committed
Update Search for points of interest.html
Fixed bug reported in PR #142 Cleaned up code a bit and fixed another small bug.
1 parent 9d47d58 commit ad3c8e0

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

Samples/Tutorials/Search/Search for points of interest.html

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<script src="https://samples.azuremaps.com/lib/azure-maps/azure-maps-helper.min.js"></script>
2323

2424
<script>
25-
var map;
25+
var map, popup;
2626

2727
// Your Azure Maps client id for accessing your Azure Maps account.
2828
var azureMapsClientId = 'e6b6ab59-eb5d-4d25-aa57-581135b927f0';
@@ -88,19 +88,19 @@
8888
var url = `https://{azMapsDomain}/search/poi/json?api-version=1.0&query=${query}&lat=${lat}&lon=${lon}&radius=${radius}`;
8989

9090
processRequest(url).then((response) => {
91-
var bounds = [];
91+
var positions = [];
9292

9393
//Extract GeoJSON feature collection from the response and add it to the datasource
9494
var data = response.results.map((result) => {
9595
var position = [result.position.lon, result.position.lat];
96-
bounds.push(position);
96+
positions.push(position);
9797
return new atlas.data.Feature(new atlas.data.Point(position), { ...result });
9898
});
9999
datasource.add(data);
100100

101101
//Set camera to bounds to show the results
102102
map.setCamera({
103-
bounds: new atlas.data.BoundingBox.fromLatLngs(bounds),
103+
bounds: atlas.data.BoundingBox.fromPositions(positions),
104104
zoom: 10,
105105
padding: 15
106106
});
@@ -111,28 +111,28 @@
111111

112112
//Add a mouse over event to the result layer and display a popup when this event fires.
113113
map.events.add('mouseover', resultLayer, showPopup);
114+
});
115+
}
114116

115-
function showPopup(e) {
116-
//Get the properties and coordinates of the first shape that the event occurred on.
117-
118-
var p = e.shapes[0].getProperties();
119-
var position = e.shapes[0].getCoordinates();
117+
function showPopup(e) {
118+
//Get the properties and coordinates of the first shape that the event occurred on.
120119

121-
//Create HTML from properties of the selected result.
122-
var html = ['<div style="padding:5px"><div><b>', p.poi.name,
123-
'</b></div><div>', p.address.freeformAddress,
124-
'</div><div>', position[1], ', ', position[0], '</div></div>'];
120+
var p = e.shapes[0].getProperties();
121+
var position = e.shapes[0].getCoordinates();
125122

126-
//Update the content and position of the popup.
127-
popup.setPopupOptions({
128-
content: html.join(''),
129-
position: position
130-
});
123+
//Create HTML from properties of the selected result.
124+
var html = ['<div style="padding:5px"><div><b>', p.poi.name,
125+
'</b></div><div>', p.address.freeformAddress,
126+
'</div><div>', position[1], ', ', position[0], '</div></div>'];
131127

132-
//Open the popup.
133-
popup.open(map);
134-
}
128+
//Update the content and position of the popup.
129+
popup.setPopupOptions({
130+
content: html.join(''),
131+
position: position
135132
});
133+
134+
//Open the popup.
135+
popup.open(map);
136136
}
137137
</script>
138138

0 commit comments

Comments
 (0)