0

現在、ユーザーが注目しているベクターレイヤーの特定の機能のアイコンを変更しようとしています。次のように、各機能をマップに追加します。

var point = new OpenLayers.Geometry.Point(pt.lon, pt.lat);
var markerStyle = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'],  {
    externalGraphic: iconURL
});
var marker = new OpenLayers.Feature.Vector(point, attributes, markerStyle);

後で、機能のアイコンを更新するために次のことを行います。

var marker = this.findSelectedMarker();
if (marker) {
    marker.style.externalGraphic = newIconUrl;
    this.layer.redraw();             
}

しかし、レイヤーが再描画されると、レイヤー内のすべての機能は、newIconUrl更新しようとしている選択されたマーカーだけでなく、を使用します。

レイヤーで選択した1つの機能のアイコンを変更するにはどうすればよいですか?ありがとう。

4

1 に答える 1

1

There were two issues I needed to fix in order to solve this. The first was related to using multiple OpenLayers styles, both at the layer level as well as the individual feature level. I removed the styling for each individual feature, so that only the following layer style was being implemented:

this.layerStyle = new OpenLayers.StyleMap({ 
    'default': {
        externalGraphic: media_url + '${iconURL}',
        graphicHeight: 32,
        graphicWidth: 32,
        graphicXOffset: -16,
        graphicYOffset: -32,
        fillOpacity: 0.75
    }
});

The second change I made was to use attribute replacement syntax to designate the icon URL with a feature attribute called '${iconURL}'. This allowed me to change the icon url by simply changing an attribute of the selected feature and redraw the layer:

focusedMarker.attributes.iconURL = this.focusedURL;
this.layer.redraw();
于 2012-09-10T17:03:18.460 に答える