Openlayers 基于地图的要素样式库
解决方案:使用相同的源创建两个不同的层或使用Mike的解决方案。 有没有办法根据显示的地图设置要素的样式?我找不到在样式函数中获取贴图属性的方法:Openlayers 基于地图的要素样式库,openlayers,openlayers-6,Openlayers,Openlayers 6,解决方案:使用相同的源创建两个不同的层或使用Mike的解决方案。 有没有办法根据显示的地图设置要素的样式?我找不到在样式函数中获取贴图属性的方法: var styleBuilding = function(feature){ console.log(feature); return [ new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'blue', width: 3 }),
var styleBuilding = function(feature){
console.log(feature);
return [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue',
width: 3
}),
fill: new ol.style.Fill({
color: 'rgba(0, 0, 255, 0.1)'
})
}),
new ol.style.Style({
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: 'orange'
})
}),
geometry: function(feature) {
var coordinates = feature.getGeometry().getCoordinates()[0];
return new ol.geom.Point(coordinates[2]);
}
})
];
};
致意
Tim视图分辨率可用作样式函数的第二个参数。任何其他视图特性(例如,中心)都可以通过在“样式”功能中引用视图来获得,因此在本示例中,点颜色的设置取决于该点在视图的哪个象限中显示
简单地图
html,body,.map{
保证金:0;
填充:0;
宽度:100%;
身高:100%;
}
var map=新ol.map({
图层:[
新ol.layer.Tile({
来源:new ol.source.OSM()
}),
新ol.layer.Vector({
来源:新ol.source.Vector({
特点:[
新ol.特征(新ol.几何点([1e6,1e6]),
新ol.特征(新ol.几何点([1e6,-1e6]),
新ol.特征(新ol.几何点([-1e6,-1e6]),
新ol.特征(新ol.几何点([-1e6,1e6]),
]
}),
风格:功能(特征){
让颜色;
常量坐标=feature.getGeometry().getCoordinates();
const viewCenter=map.getView().getCenter();
if(坐标[0]<视图中心[0]){
if(坐标[1]<视图中心[1]){
颜色=红色;
}否则{
颜色=‘橙色’;
}
}否则{
if(坐标[1]<视图中心[1]){
颜色='绿色';
}否则{
颜色=‘蓝色’;
}
}
返回[
新ol风格({
图片:新ol.style.Circle({
半径:7,
填充:新的ol.style.fill({
颜色:颜色
})
})
})
];
}
})
],
目标:“地图”,
视图:新ol.view({
中间:[0,0],
缩放:2
})
});
很抱歉,这是我的一个大错误。我想根据地图更改样式。你给出的答案对于不同的观点都很有效!!!!我试着解释我想要什么。我有一个视图,但有两张地图。这些地图显示的是相同的视图和相同的源,但我想为矢量源使用不同的样式。