问题描述
在infowindow.setContent
中,我有一个按钮,我想更改单击该代码时的标记颜色按钮
google.maps.event.addListener(marker,'click',(function(marker,i) {
return function() {
infowindow.setContent(locations[i][0] + locations[i][3] + " <button class='btn btn-primary btn-sm map-checked-Box mr-1' onclick='myFunction();' data-id='"+ locations[i][3] +"'>Print</button> ");
infowindow.open(map,marker);
}
})(marker,i ));
}
function myFunction() {
infowindow.setContent('<div style="background-color: green">' + locations[i][0] + locations[i][3] + "</div>");
}
我正在调用myfunction(),但在此行中不起作用。我认为我正在混淆函数中的位置
infowindow.setContent(locations[i][0] + locations[i][3] + " <button class='btn btn-primary btn-sm map-checked-Box mr-1' onclick='myFunction();' data-id='"+ locations[i][3] +"'>Print</button> ");
解决方法
由于标记是图像,因此无法通过CSS更改标记的颜色。 您必须为现有标记设置一个新图像才能获得更改后的标记颜色的效果。
一般步骤为:
- 将标记存储在稍后在
Expected: rec.get("recId") = first record rec.get("recId") = second record rec.get("recId") = third record* Actual: rec.get("recId") = third record rec.get("recId") = third record rec.get("recId") = third record
中可用的变量中。 - 使用
myFunction
更新标记图像
Here is an example fiddle。单击更改按钮以查看效果。
Refer to this link获取在线可用图标的列表。
,由
解决function state(marker){
marker.setIcon('http://maps.google.com/mapfiles/ms/micons/orange.png');
}