绘制形状时样式化 OpenLayers 3 光标
Style OpenLayers 3 cursor when drawing shapes
我有一项功能允许用户在 OpenLayers 地图上绘制正方形或矩形。我想更改光标的样式。默认情况下,光标是一个蓝色圆圈。我想将其更改为正方形,以便符号与用户可能创建的形状相匹配。
解决方案涉及添加样式属性。我需要有关如何为非图像光标实现样式属性的细节,该光标类似于默认的蓝色圆圈,而是一个正方形。谢谢!
$scope.drawBoundingBox = () => {
const bbVector = new ol.source.Vector({ wrapX: false });
const vector = new ol.layer.Vector({
source: bbVector
});
bbVector.on("addfeature", evt => {
$scope.coords = evt.feature.getGeometry().getCoordinates();
});
const style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: "#FFF",
width: 3
}),
fill: new ol.style.Fill({
color: [255, 255, 255, 0]
})
});
const geometryFunction = ol.interaction.Draw.createRegularPolygon(4);
draw = new ol.interaction.Draw({
source: bbVector,
type: "Circle",
geometryFunction
});
vector.set("name", "boundingBox");
vector.setStyle(style);
map.addLayer(vector);
map.addInteraction(draw);
};
这是一个可行的解决方案,可以将默认的蓝色圆圈光标更改为正方形,并允许用户在地图上创建正方形或矩形。
$scope.drawBoundingBox = () => {
const bbVector = new ol.source.Vector({ wrapX: false });
const vector = new ol.layer.Vector({
source: bbVector
});
bbVector.on("addfeature", evt => {
$scope.coords = evt.feature.getGeometry().getCoordinates();
});
const geometryFunction = ol.interaction.Draw.createRegularPolygon(4);
draw = new ol.interaction.Draw({
source: bbVector,
type: "Circle",
geometryFunction: geometryFunction,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: "#FFF",
width: 3
}),
fill: new ol.style.Fill({
color: [255, 255, 255, 0]
}),
geometryFunction,
image: new ol.style.RegularShape({
fill: new ol.style.Fill({
color: '#FFF'
}),
stroke: new ol.style.Stroke({
color: "blue",
width: 3
}),
points: 4,
radius: 10,
angle: Math.PI / 4
}),
}),
});
vector.set("name", "boundingBox");
map.addLayer(vector);
map.addInteraction(draw);
};
我有一项功能允许用户在 OpenLayers 地图上绘制正方形或矩形。我想更改光标的样式。默认情况下,光标是一个蓝色圆圈。我想将其更改为正方形,以便符号与用户可能创建的形状相匹配。
解决方案涉及添加样式属性。我需要有关如何为非图像光标实现样式属性的细节,该光标类似于默认的蓝色圆圈,而是一个正方形。谢谢!
$scope.drawBoundingBox = () => {
const bbVector = new ol.source.Vector({ wrapX: false });
const vector = new ol.layer.Vector({
source: bbVector
});
bbVector.on("addfeature", evt => {
$scope.coords = evt.feature.getGeometry().getCoordinates();
});
const style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: "#FFF",
width: 3
}),
fill: new ol.style.Fill({
color: [255, 255, 255, 0]
})
});
const geometryFunction = ol.interaction.Draw.createRegularPolygon(4);
draw = new ol.interaction.Draw({
source: bbVector,
type: "Circle",
geometryFunction
});
vector.set("name", "boundingBox");
vector.setStyle(style);
map.addLayer(vector);
map.addInteraction(draw);
};
这是一个可行的解决方案,可以将默认的蓝色圆圈光标更改为正方形,并允许用户在地图上创建正方形或矩形。
$scope.drawBoundingBox = () => {
const bbVector = new ol.source.Vector({ wrapX: false });
const vector = new ol.layer.Vector({
source: bbVector
});
bbVector.on("addfeature", evt => {
$scope.coords = evt.feature.getGeometry().getCoordinates();
});
const geometryFunction = ol.interaction.Draw.createRegularPolygon(4);
draw = new ol.interaction.Draw({
source: bbVector,
type: "Circle",
geometryFunction: geometryFunction,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: "#FFF",
width: 3
}),
fill: new ol.style.Fill({
color: [255, 255, 255, 0]
}),
geometryFunction,
image: new ol.style.RegularShape({
fill: new ol.style.Fill({
color: '#FFF'
}),
stroke: new ol.style.Stroke({
color: "blue",
width: 3
}),
points: 4,
radius: 10,
angle: Math.PI / 4
}),
}),
});
vector.set("name", "boundingBox");
map.addLayer(vector);
map.addInteraction(draw);
};