2
我想在OpenLayers中繪製國家位置,並且在更改默認圖標時遇到問題。在OpenLayers中更改默認標記圖標
我的基本代碼如下:
function addCountryMarker(ll, popupClass, popupContentHTML, closeBox, overflow) {
var feature = new OpenLayers.Feature(alumniCountries, ll);
feature.closeBox = closeBox;
feature.popupClass = popupClass;
feature.data.popupContentHTML = popupContentHTML;
feature.data.overflow = (overflow) ? "auto" : "hidden";
var marker = feature.createMarker();
var markerClick = function (evt) {
if (this.popup == null) {
this.popup = this.createPopup(this.closeBox);
map.addPopup(this.popup);
this.popup.show();
} else {
this.popup.toggle();
}
currentPopup = this.popup;
OpenLayers.Event.stop(evt);
};
marker.events.register("mousedown", feature, markerClick);
alumniCountries.addMarker(marker);
}
而這一切工作正常,但顯示默認的OpenLayers圖標。下面的代碼行更改圖標,但它打破了彈出式的markerClick功能:
feature.icon = new OpenLayers.Icon("marker-blue.png");
使用marker.icon也同樣行更改圖標,但也打破彈出。非常感謝任何關於如何更改圖標而不打破彈出窗口的指針。