OpenLayers中每层多张图像

chr*_*chu 5 image layer openlayers

是否可以在OpenLayers的一个图层中放置多个图像?

理想情况下,我想将我的图片分为几类(每一层是一个类别),这样我可以整体显示和隐藏每个类别,而不是显示/隐藏每张图片。

这可能吗?我发现了几个使用OpenLayers的Image层(似乎仅支持一个图像)或使用带有StyleMap的Vector层(似乎也仅允许一个外部图像)的示例。

我是否忽略了某些内容,还是会花费更多的精力(例如,创建自定义图层类型)?

提前致谢!

Max*_*aez 2

要将多个图像放在同一层中,您可以创建这样的 styleMap

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

其中“${icon}”是功能的属性。

在下一个示例中,我使用 2 个图像“star”和“home”

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]);
Run Code Online (Sandbox Code Playgroud)