|
195 | 195 | control.setMap(map); |
196 | 196 | map.addControl(control); |
197 | 197 | var select = new ol.interaction.Select(); |
198 | | - map.addInteraction(select); |
199 | | - select.on('select', function (e) { |
200 | | - if (e.selected.length > 0) { |
201 | | - var feature = e.selected[0]; |
202 | | - var innerHTML = ""; |
203 | | - innerHTML += "地址:" + feature.getProperties().address + "<br>"; |
204 | | - var x = Number(feature.getProperties().location.x.toString().match(/^\d+(?:\.\d{0,2})?/)); |
205 | | - var y = Number(feature.getProperties().location.y.toString().match(/^\d+(?:\.\d{0,2})?/)); |
206 | | - innerHTML += "坐标:[" + x + "," + y + "]<br>"; |
207 | | - if (feature.getProperties().score > 0) { |
208 | | - innerHTML += "匹配度:" + feature.getProperties().score + "<br>"; |
209 | | - } |
210 | | - innerHTML += "过滤字段:" + feature.getProperties().filters + "<br>"; |
211 | | - content.innerHTML = innerHTML; |
212 | | - overlay.setPosition(feature.getGeometry().flatCoordinates); |
213 | | - } else if (overlay) { |
214 | | - overlay.setPosition(undefined); |
215 | | - } |
216 | | - }); |
217 | 198 |
|
218 | 199 | var layer = new ol.layer.Tile({ |
219 | 200 | source: new ol.source.TileSuperMapRest({ |
|
275 | 256 | }); |
276 | 257 |
|
277 | 258 | function match(obj) { |
| 259 | + map.removeInteraction(select); |
| 260 | + select = new ol.interaction.Select(); |
| 261 | + map.addInteraction(select); |
| 262 | + select.on('select', function (e) { |
| 263 | + if (e.selected.length > 0) { |
| 264 | + var feature = e.selected[0]; |
| 265 | + var innerHTML = ""; |
| 266 | + innerHTML += "地址:" + feature.getProperties().address + "<br>"; |
| 267 | + var x = Number(feature.getProperties().location.x.toString().match(/^\d+(?:\.\d{0,2})?/)); |
| 268 | + var y = Number(feature.getProperties().location.y.toString().match(/^\d+(?:\.\d{0,2})?/)); |
| 269 | + innerHTML += "坐标:[" + x + "," + y + "]<br>"; |
| 270 | + if (feature.getProperties().score > 0) { |
| 271 | + innerHTML += "匹配度:" + feature.getProperties().score + "<br>"; |
| 272 | + } |
| 273 | + innerHTML += "过滤字段:" + feature.getProperties().filters + "<br>"; |
| 274 | + content.innerHTML = innerHTML; |
| 275 | + overlay.setPosition(feature.getGeometry().getCoordinates()); |
| 276 | + } else if (overlay) { |
| 277 | + overlay.setPosition(undefined); |
| 278 | + } |
| 279 | + }); |
| 280 | + map.addInteraction(select); |
278 | 281 | overlay.setPosition(undefined); |
279 | 282 | vectorSource.clear(); |
280 | 283 | var features = []; |
|
0 commit comments