在OpenLayers中更改默认标记图标

Chr*_*yne 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);
    }
Run Code Online (Sandbox Code Playgroud)

这一切都运行正常,但显示默认的openLayers图标.以下行更改图标但是它会破坏markerClick函数中的弹出窗口:

feature.icon = new OpenLayers.Icon("marker-blue.png");
Run Code Online (Sandbox Code Playgroud)

使用marker.icon的同一行也会更改图标,但也会中断弹出窗口.关于如何在不破坏弹出窗口的情况下更改图标的任何指示都将非常感激.

Chr*_*yne 5

花了一段时间,但最后却很简单:

feature.data.icon = new OpenLayers.Icon("marker-blue.png");
Run Code Online (Sandbox Code Playgroud)