|
22 | 22 | <script src="https://samples.azuremaps.com/lib/azure-maps/azure-maps-helper.min.js"></script> |
23 | 23 |
|
24 | 24 | <script> |
25 | | - var map; |
| 25 | + var map, popup; |
26 | 26 |
|
27 | 27 | // Your Azure Maps client id for accessing your Azure Maps account. |
28 | 28 | var azureMapsClientId = 'e6b6ab59-eb5d-4d25-aa57-581135b927f0'; |
|
88 | 88 | var url = `https://{azMapsDomain}/search/poi/json?api-version=1.0&query=${query}&lat=${lat}&lon=${lon}&radius=${radius}`; |
89 | 89 |
|
90 | 90 | processRequest(url).then((response) => { |
91 | | - var bounds = []; |
| 91 | + var positions = []; |
92 | 92 |
|
93 | 93 | //Extract GeoJSON feature collection from the response and add it to the datasource |
94 | 94 | var data = response.results.map((result) => { |
95 | 95 | var position = [result.position.lon, result.position.lat]; |
96 | | - bounds.push(position); |
| 96 | + positions.push(position); |
97 | 97 | return new atlas.data.Feature(new atlas.data.Point(position), { ...result }); |
98 | 98 | }); |
99 | 99 | datasource.add(data); |
100 | 100 |
|
101 | 101 | //Set camera to bounds to show the results |
102 | 102 | map.setCamera({ |
103 | | - bounds: new atlas.data.BoundingBox.fromLatLngs(bounds), |
| 103 | + bounds: atlas.data.BoundingBox.fromPositions(positions), |
104 | 104 | zoom: 10, |
105 | 105 | padding: 15 |
106 | 106 | }); |
|
111 | 111 |
|
112 | 112 | //Add a mouse over event to the result layer and display a popup when this event fires. |
113 | 113 | map.events.add('mouseover', resultLayer, showPopup); |
| 114 | + }); |
| 115 | + } |
114 | 116 |
|
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. |
120 | 119 |
|
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(); |
125 | 122 |
|
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>']; |
131 | 127 |
|
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 |
135 | 132 | }); |
| 133 | + |
| 134 | + //Open the popup. |
| 135 | + popup.open(map); |
136 | 136 | } |
137 | 137 | </script> |
138 | 138 |
|
|
0 commit comments