[OpenLayers-Users] need a clarification re styleMaps
Puneet Kishor
punk.kish at gmail.com
Tue Oct 4 11:42:36 EDT 2011
The following code works
// Add styleMap to layer
var style_map = new OpenLayers.StyleMap({
externalGraphic: uri + "/img/arrow.png",
graphicWidth: 15,
graphicHeight: res[0].height,
rotation: res[0].angle
});
var lyr = new OpenLayers.Layer.Vector("name", {styleMap: style_map});
// Points without styleMap
var points = [];
points.push(
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(res[0].lng, res[0].lat)
)
);
lyr.addFeatures(points);
map.addLayer(lyr);
everything works. Different points get drawn with symbols of correct height and rotation. But, if I don't add the styleMap definition to the lyr when creating it, and instead, add it to the point, like so
// Layer with styleMap
var lyr = new OpenLayers.Layer.Vector("name");
// Add styleMap to each point
var style_map = new OpenLayers.StyleMap({
externalGraphic: uri + "/img/arrow.png",
graphicWidth: 15,
graphicHeight: res[0].height,
rotation: res[0].angle
});
var points = [];
points.push(
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(res[0].lng, res[0].lat),
{styleMap: style_map}
)
);
lyr.addFeatures(points);
map.addLayer(lyr);
then nothing gets drawn. At best, this is counter-intuitive to me… the style is per point, not per layer. At worst, this creates a problem for me that I don't know how to solve. I am creating a layer that I want to reuse. If I follow the first approach above, the first time around everything works well. But, on subsequent iterations the points get drawn with the previously set style (rotation and height).
Suggestions?
--
Puneet Kishor
More information about the Users
mailing list