为了把多张图片在同一层,你可以创建一个StyleMap设定这样
var style = new OpenLayers.StyleMap({
default :new OpenLayers.Style({
'pointRadius': 10,
'externalGraphic': '/images/${icon}.png'
})
})
其中“$ {}图标”是要素的属性。
在下面的例子中,我用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]);