Я создал карту openlayers и использовал контрольный контроль загрузки. После нажатия кнопки поиска на карте будет отображаться масштаб, но опять же вся карта освежает. Ниже приведен исходный код, который я написал...
<div class="input-group add-on">
<input class="form-control" placeholder="Search" name="srch-term" id="srch-term" type="text" onkeypress="autoFill()"/>
<div class="input-group-btn">
<button class="btn btn-default" type="submit" onclick="searchStateName();"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
function searchStateName() {
input = document.getElementById("srch-term").value.toUpperCase();
if (input) {
for (var i = 0; i < countryData.length; i++) {
//alert(countryData[0]);
if (countryData[i].P.name_1.toUpperCase() == input) {
alert(countryData[i].P.name_1);
var extent = countryData[i].P.geom.getExtent();
map.getView().fit(extent, map.getSize());
if (countryData[i] !== highlight) {
if (highlight) {
featureOverlay.getSource().removeFeature(highlight);
}
if (countryData[i]) {
featureOverlay.getSource().addFeature(countryData[i]);
}
highlight = countryData[i];
}
}
}
}
}
Может кто-нибудь помочь мне найти, где проблема?
Проверьте код в цикле:
if (countryData[i] !== highlight) {
if (highlight) {
featureOverlay.getSource().removeFeature(highlight);
}
if (countryData[i]) {
featureOverlay.getSource().addFeature(countryData[i]);
}
highlight = countryData[i];
}
hightlight
- общая переменная, не так ли? Он всегда сохраняет последнюю созданную функцию. Но вы удаляете предыдущую созданную функцию каждый раз в цикле, что на карте будет только одна функция в конце.