5

OpenLayers のレイヤーに複数の画像を配置することは可能ですか?

理想的には、写真をカテゴリ (各レイヤーは 1 つのカテゴリ) にグループ化して、すべての写真を表示/非表示にするのではなく、各カテゴリ全体を表示および非表示にできるようにしたいと考えています。

これは可能ですか?OpenLayers の Image レイヤー (1 つの画像のみをサポートしているようです) または StyleMap を使用した Vector レイヤー (これも 1 つの外部画像のみを許可しているようです) を使用した例をいくつか見つけました。

何か見落としがありますか、それとももっと手間がかかりますか (つまり、カスタム レイヤー タイプを作成するなど)?

前もって感謝します!

4

1 に答える 1

2

同じレイヤーに複数の画像を配置するには、次のようなスタイルマップを作成できます

var style = new OpenLayers.StyleMap({
    default :new OpenLayers.Style({
          'pointRadius': 10,
          'externalGraphic': '/images/${icon}.png'
    })
})

ここで、「${icon}」は機能の属性です。

次の例では、「スター」と「ホーム」の2つの画像を使用します

var path = new OpenLayers.Layer.Vector( "images" );
//set the styleMap
path.styleMap = style;
map.addLayers([path]);

//create a new feature
var pointHome = new OpenLayers.Geometry.Point(-57.533832,-25.33963);
var featureHome = new OpenLayers.Feature.Vector(pointHome);
//set the icon of the feature
featureHome.attributes["icon"] ="home";

var pointStar = new OpenLayers.Geometry.Point(-57.533371,-25.338946);
var featureStar = new OpenLayers.Feature.Vector(pointStar);
//set the icon of the feature
featureStar.attributes["icon"] ="star";

path.addFeatures([featureHome, featureStar]);
于 2012-11-09T18:00:31.347 に答える