Skip to content

Commit 1a8ee6e

Browse files
author
caoxinke
committed
fix OpenLayers下地址匹配服务弹框不显示的问题。
1 parent cd3d6eb commit 1a8ee6e

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

examples/openlayers/addressMatchService.html

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,6 @@
195195
control.setMap(map);
196196
map.addControl(control);
197197
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-
});
217198

218199
var layer = new ol.layer.Tile({
219200
source: new ol.source.TileSuperMapRest({
@@ -275,6 +256,28 @@
275256
});
276257

277258
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);
278281
overlay.setPosition(undefined);
279282
vectorSource.clear();
280283
var features = [];

0 commit comments

Comments
 (0)