2011-07-19 11 views
0

OpenLayersでは、私はLineFeatureオブジェクトを持っています。Vector Feature Rerender

オブジェクトのスタイルを変更します(例:my_line.style.strokeColor="Black")。

しかし、ズームイン/アウト(つまりレンダー)するまで、画面上の色は変わりません。

再レンダリングする必要があるベクター機能をどのように教えてください。

答えて

2

スタイルを変更した後に、その機能を含むベクターレイヤーでredraw()メソッドを呼び出してみてください。

更新:レイヤ全体を再描画したくない場合は、drawFeature()メソッドを試すことができます。

/** 
    * APIMethod: drawFeature 
    * Draw (or redraw) a feature on the layer. If the optional style argument 
    * is included, this style will be used. If no style is included, the 
    * feature's style will be used. If the feature doesn't have a style, 
    * the layer's style will be used. 
    * 
    * This function is not designed to be used when adding features to 
    * the layer (use addFeatures instead). It is meant to be used when 
    * the style of a feature has changed, or in some other way needs to 
    * visually updated *after* it has already been added to a layer. You 
    * must add the feature to the layer for most layer-related events to 
    * happen. 
    * 
    * Parameters: 
    * feature - {<OpenLayers.Feature.Vector>} 
    * style - {String | Object} Named render intent or full symbolizer object. 
    */ 
    drawFeature: function(feature, style) { 
     // don't try to draw the feature with the renderer if the layer is not 
     // drawn itself 
     if (!this.drawn) { 
      return; 
     } 
     if (typeof style != "object") { 
      if(!style && feature.state === OpenLayers.State.DELETE) { 
       style = "delete"; 
      } 
      var renderIntent = style || feature.renderIntent; 
      style = feature.style || this.style; 
      if (!style) { 
       style = this.styleMap.createSymbolizer(feature, renderIntent); 
      } 
     } 

     var drawn = this.renderer.drawFeature(feature, style); 
     //TODO remove the check for null when we get rid of Renderer.SVG 
     if (drawn === false || drawn === null) { 
      this.unrenderedFeatures[feature.id] = feature; 
     } else { 
      delete this.unrenderedFeatures[feature.id]; 
     }; 
    } 
+0

を一つだけを再描画する方法はありますその層の特徴?そうでない場合は、理由を知っていますか? – Richard

+0

更新された答えを参照 – igorti

+0

@igortiは、上記のコードで再レンダリングを見ることはできませんでしたが、そのコメントはその最終的な機能の正確な記述であると確信しています。コードがドキュメンテーションそのものよりも優れたドキュメンテーションを提供することは興味深いことであり、おそらく驚くべきことではありません。 – Richard

0

こんにちはあなたは以下のようにこれを行うことができます:あなたは、おそらくそれがコードだ時に、あなたが見てみる場合はどのように動作するか、より良いアイデアを持っているでしょう

.... 
map.vectorlayer.addFeatures(line); 
var mystyle = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); 
mystyle.strokeColor = '#7200FF'; 
... 
map.vectorlayer.styleMap.styles['default'].defaultStyle = mystyle; 
map.vectorlayer.redraw(true);