单击单选按钮时更改特定地标的颜色
Change color of particular placemark when onClick radiobutton
我有一个使用 OpenLayers 的包含 10 多个地标的 KML 文件。我想做的是,当我点击单选按钮时,特定的地标会改变它的颜色。
有人知道如何做到这一点吗?
谢谢。
编辑:
所以这是我到目前为止所拥有的:
function init(){
///////////////////////////////////////////////
CONTROLS AND MAP STUFF
//////////////////////////////////////////////
var myvector = new OpenLayers.Layer.Vector("myvector", {
projection: map.displayProjection,
styleMap: new OpenLayers.StyleMap(
{ 'default':
{
strokeColor: "#777777",
strokeOpacity: 1,
strokeWidth: "2",
fillColor: "#FFF900",
fillOpacity: 1,
pointRadius: 8,
pointerEvents: "visiblePainted",
graphicName: "circle",
}
}),
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: url_time,
format: new OpenLayers.Format.KML({
extractStyles: false,
extractAttributes: true
})
})
});
map.addLayers([wms, wms2, myvector]);
select = new OpenLayers.Control.SelectFeature(myvector);
myvector.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
map.addControl(select);
select.activate();
map.zoomToExtent(new OpenLayers.Bounds(-53,-21,13,22));
}
function switchLabels() {
/////// PROBABLY HERE IS THE PLACE TO DO THE TRICK ////////
myvector.redraw();
}
///////////////////////////////////////////////
SOME OTHER THINGS
//////////////////////////////////////////////
和辐射按钮:
<input name="button1" type="radio" value="button1" onClick="switchLabels()">
这是一篇显示此 switchLabel 的帖子,但我不知道如何更改由一个地标创建的点。
谢谢。
好的。我放弃了使用 KML 来做我想做的事。对于那些需要在 OpenLayer 中更改矢量的某些属性的人,这里有一个可能的解决方案:
var features = [];
features[0] = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(10,10),
{
name : "Hello",
body : "world",
}, {strokeColor: "#777777",strokeOpacity: 1,strokeWidth: "2",fillColor: "#FFF900",fillOpacity: 1,pointRadius: 8,pointerEvents: "visiblePainted",graphicName: "circle"});
features[1] = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(15,10),
{
name : "Hello",
body : "Mars",
}, {strokeColor: "#777777",strokeOpacity: 1,strokeWidth: "2",fillColor: "#FFF900",fillOpacity: 1,pointRadius: 8,pointerEvents: "visiblePainted",graphicName: "circle"});
///////////// POPUPS //////////////
vector = new OpenLayers.Layer.Vector("LAYER",{
eventListeners:{
'featureselected':function(evt){
var feature = evt.feature;
var popup = new OpenLayers.Popup.FramedCloud("popup",
OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
new OpenLayers.Size(350,350),
feature.attributes.name + feature.attributes.body,
null, false, onPopupClose
);
popup.maxSize = new OpenLayers.Size(350, 350);
popup.minSize = new OpenLayers.Size(350, 350);
feature.popup = popup;
map.addPopup(popup);
},
'featureunselected':function(evt){
var feature = evt.feature;
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
});
function onPopupClose(evt) {
select.unselectAll();
}
vector.addFeatures(features);
// create the select feature control
var selector = new OpenLayers.Control.SelectFeature(vector,{
click:true,
autoActivate:true
});
map.addLayers([vector]);
map.addControl(selector);
map.zoomToExtent(new OpenLayers.Bounds(-53,-21,13,22));
}
///////////////////// FUNCTION TO CHANGE THE VECTOR STYLE ///////////
function switchColors(p_ind,p_id) {
if (eval('document.form.' + p_id).checked == 1){
vector.features[p_ind].style = {
strokeColor: "#777777",
strokeOpacity: 1,
strokeWidth: "2",
fillColor: "#FF0000",
fillOpacity: 1,
pointRadius: 8,
pointerEvents: "visiblePainted",
graphicName: "circle"
};
}
else {
vector.features[p_ind].style = {
strokeColor: "#777777",
strokeOpacity: 1,
strokeWidth: "2",
fillColor: "#FFF900",
fillOpacity: 1,
pointRadius: 8,
pointerEvents: "visiblePainted",
graphicName: "circle"
};
}
vector.redraw();
}
然后是收音机:
<form name="form" method="post" action="action.php">
<input name="p1" type="checkbox" value="p1" onClick="switchColors(0,'p1');">
<input name="p2" type="checkbox" value="p2" onClick="switchColors(1,'p2');">
</form>
相关文章:
- 多个单选按钮组相互干扰
- 是否可以禁用jquery中的单个单选按钮
- Javascript:无法获取变量中的单选按钮值
- 通过ajax到php文件获取单选按钮值
- 互斥单选按钮和相应的输入字段
- 用于选择MVC3中单选按钮值的JavaScript
- 如何更改已从单选按钮列表中选择的单选按钮的颜色
- 使用单选按钮更改 HTML 元素的颜色
- 单击单选按钮时如何更改背景颜色
- 单击单选按钮时更改特定地标的颜色
- 单击输入字段将背景颜色应用于父项,并取消选择初始选择的单选按钮
- 未选中时更改单选按钮的颜色
- 单选按钮颜色选择器
- 如果选中单选按钮,则更改父背景颜色
- 单选按钮不改变背景颜色HTML/CSS
- JavaScript -如果选中单选按钮,更改背景颜色
- 当我从列表或单选按钮中选择模板颜色时,如何使其更新?
- 在表格行中选择单选按钮时,行的颜色应该更改
- 如果未选中,请更改单选按钮的背景颜色
- 单选按钮所在的颜色单元格被选中,但没有点击