Openlayers 如何将样式添加到要素(矢量线字符串)?
我不知道如何为我的特征添加样式,它由向量中的一个线字符串组成。我是将样式添加到线字符串还是向量?我想改变线条的颜色和大小,如果可能的话,尽量使线条不透明Openlayers 如何将样式添加到要素(矢量线字符串)?,openlayers,gis,Openlayers,Gis,我不知道如何为我的特征添加样式,它由向量中的一个线字符串组成。我是将样式添加到线字符串还是向量?我想改变线条的颜色和大小,如果可能的话,尽量使线条不透明 mapObject=newOpenLayers.Layer.Vector(“Vector”); var p1=新的OpenLayers.Geometry.Point(mapObjectTopLeftLon,mapObjectTopLeftLat); var p2=新的OpenLayers.Geometry.Point(mapObjectTopR
mapObject=newOpenLayers.Layer.Vector(“Vector”);
var p1=新的OpenLayers.Geometry.Point(mapObjectTopLeftLon,mapObjectTopLeftLat);
var p2=新的OpenLayers.Geometry.Point(mapObjectTopRightLon,mapObjectTopRightLat);
var p3=新的OpenLayers.Geometry.Point(mapObjectBottomRightLon,mapObjectBottomRightLat);
var p4=新的OpenLayers.Geometry.Point(mapObjectBottomLeftLon,mapObjectBottomLeftLat);
var p5=新的OpenLayers.Geometry.Point(mapObjectTopLeftLon,mapObjectTopLeftLat);
var pnt=[];
推力(p1,p2,p3,p4,p5);
mapObject.addFeatures([new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(pnt)));
map.addLayer(mapObject);
事实上,您将样式添加到存储要素的向量层,在您的示例中,它被命名为mapObject(但应该是featureLayer或myVectorLayer之类的东西)。
你可以找到一个关于矢量层和OpenLayers样式的博客。在这种情况下,StyleMap肯定会很有用
如果您需要更多样式(您有许多不同的功能需要区分),您还可以根据“规则”(OpenLayers.Rule)更改各个功能的样式,并在OpenLayers.Filter.Comparison的帮助下,为您的功能指定不同的符号。样式的一个简单示例:
myOpenLayersStyles.commentLayer = new OpenLayers.StyleMap({ //creates style for the vectorLayer features
"default": new OpenLayers.Style({
pointRadius: 20,
fillColor: "#0000ff",
fillOpacity: 1,
strokeColor: "#0000ff",
strokeWidth: 3,
strokeOpacity: .7,
cursor: "pointer",
cursor: "hand"
},{
rules: [
new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "completed",
value: 1
}),
symbolizer: {
graphicHeight: 25,
externalGraphic: "Img/comment_completed.png"
}
}),
new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "completed",
value: 0
}),
symbolizer: {
externalGraphic: "Img/comment.png",
graphicHeight: 25
}
})
]
}
)
});