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.

OpenlayersでResolutionを使ってスケールフィルタする際にハマったこと

Posted at

Mapに設定したResolutionとは異なる範囲の地図画像がMapServerから返ってくる

OpenlayersとMapserverの組み合わせており、ImageWMSレイヤを使って複数レイヤの地図画像を1リクエストで取得しようとした場合、Mapserver側でスケールフィルタを設定する必要がある。Openlayers側でのスケールフィルタはレイヤ単位であるため、複数レイヤを表示する目的のImageWMSに対してスケールフィルタを設定すると、すべてのレイヤを同時にON⇔OFFと切り替えることしかできないからだ。

ImageWMSはMapserverへリクエストを送信する際に、現在のResolutionからBBOXを計算し、地図のピクセルサイズと共にリクエストパラメータに設定してくれる。MapserverはこのBBOXと地図のピクセルサイズからスケールを計算するわけだが、これがOpenlayersとMapserverで一致しない場合があり、スケールフィルタの表示範囲外のResolutionをOpenlayers側に指定しているのにも関わらず、Mapserverから返ってくる地図画像には出力されてしまっている場合や、その逆の現象が発生する現象に遭遇した。

解決方法

ol.Map生成時のoptionsにpixelRatioという項目があり、これに1を明示的に設定することで解決した。特に理由がなければ地図を生成する際はこの項目には1を指定することを忘れずに。

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?