0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【OpenLayers4】ol.Objectの派生クラスで任意のプロパティの変更を検知する

Posted at

OpenLayers v4.6.5 で確認。

例えばol.geom.LineStringに線幅を持たせるため、widthというプロパティを独自にもたせるとする。
ol.geom.LineStringol.Objectの派生クラスなので、widthの設定、取得には以下のようにget/setメソッドを利用できる。

var ls = new ol.geom.LineString([[0, 0], [1, 1]]);
var width = 5;
ls.set('width', width);

ls.get('width');		// 5

また、setのタイミングでchange:widthイベントを発火するので、リスナーを設定することで変更を検知できる。


ls.on('change:width', function(evt) {
		console.log('new width: ' + this.get('width'));
	},
	ls
);
ls.set('width', 8);		// new width: 8
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?