使用鼠标事件更改多边形的颜色
我尝试通过鼠标悬停事件将颜色更改为一个多边形,
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(-39.875696,-72.624207), 9);
pLat = 0.2;
pLon = 0.2;
p1Lat = -40;
p1Lon = -73;
p1Coor = [
new GLatLng(p1Lat, p1Lon - pLon),
new GLatLng(p1Lat + pLat, p1Lon),
new GLatLng(p1Lat, p1Lon + pLon),
new GLatLng(p1Lat - pLat, p1Lon),
new GLatLng(p1Lat, p1Lon - pLon)
];
var p1 = new GPolygon(p1Coor, "#f33f00", 2, 1, "#ff0000", 0.2);
GEvent.addListener(p1,"mouseover",function(overlay,latlng){
p1.color = "#ffff00";
alert(p1.color);
});
map.addOverlay(p1);
属性会发生变化,但我没有看到变化。为什么 ?
I try change the color to one Gpolygon with a mouseover event
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(-39.875696,-72.624207), 9);
pLat = 0.2;
pLon = 0.2;
p1Lat = -40;
p1Lon = -73;
p1Coor = [
new GLatLng(p1Lat, p1Lon - pLon),
new GLatLng(p1Lat + pLat, p1Lon),
new GLatLng(p1Lat, p1Lon + pLon),
new GLatLng(p1Lat - pLat, p1Lon),
new GLatLng(p1Lat, p1Lon - pLon)
];
var p1 = new GPolygon(p1Coor, "#f33f00", 2, 1, "#ff0000", 0.2);
GEvent.addListener(p1,"mouseover",function(overlay,latlng){
p1.color = "#ffff00";
alert(p1.color);
});
map.addOverlay(p1);
the attribute change, but I don`t see the change. why ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案
p1.setFillStyle({color:"#0000ff"});
p1.setStrokeStyle({颜色:"#0000ff"});
I find the solution with
p1.setFillStyle({color:"#0000ff"});
p1.setStrokeStyle({color:"#0000ff"});