我一直在尝试创建一个情节,其中我有一些点我希望与hover-info等交互,但我想要包含两个多边形区域而没有任何交互式内容。
对于MWE:
library(plotly)
data("iris")
xsq <- function(x) sqrt(x)
x <- c( c(seq(0,10,0.001),0,0), c(0.5,10,10,0.5))
y <- c( c(xsq(x[1:length(seq(0,10,0.001))]),xsq(max(x)),0), c(0,2,0,0))
## produce the plotly plot
plot_ly(x = x, y = y, alpha = 0.1, opacity=0.1) %>%
add_polygons(hoverinfo = "none", color = I("red"),showlegend=F) %>%
add_polygons(x = c(0.5,10,10,0.5), y=c(0,2,0,0), hoverinfo = "none",
color = I("blue"), showlegend=F) %>%
add_markers(x=iris$Sepal.Length,y=iris$Sepal.Width-2, opacity=1, alpha=1,
color=iris$Species, hoverinfo="text", text=iris$Species)
这有点像我想要的但我有几个问题:
我也试图使用ggplot,但那里没有运气。
基本上我认为我想要的是一种向绘图图添加两个静态多边形的方法。有没有人有任何其他建议/想法?
感谢。
答案 0 :(得分:1)
经过一番广泛的搜索和实验,我找到了解决问题的方法1.需要为多边形图层添加markersArray[];
function addMarkers () {
var bounds = map.getBounds();
for (var i = 0; i < spaces.length; i++) {
var markerLatLng = {lat: parseFloat(spaces[i].lat), lng: parseFloat(spaces[i].log)};
if (bounds.contains(markerLatLng)){
var spaceMarker = {
path: 'M43.8,0H6.2C2.8,0,0,3.2,0,7.1v25c0,3.9,2.8,7.1,6.2,7.1h12.5L31.2,50V39.3h12.5c3.4,0,6.2-3.2,6.2-7.1v-25C50,3.2,47.2,0,43.8,0z',
fillColor: 'Black',
fillOpacity: 0.7,
strokeColor: 'Dodgerblue',
strokeWeight: 0,
labelOrigin: new google.maps.Point(24,19)
};
var markerLabel = "$" + spaces[i].hourlyrate ;
marker = new google.maps.Marker({
position: new google.maps.LatLng(spaces[i].lat, spaces[i].log),
map: map,
icon: spaceMarker,
id: spaces[i].id,
zIndex: 100,
label:{
text: markerLabel,
color: "#FFFFFF",
fontSize: "23px",
fontWeight: "bold",
fontFamily: "Lato"
}
});
google.maps.event.addListener(marker, 'click', addClickToMarker);
markersArray.push(marker);
}
}
}
function addClickToMarker() {
console.log("test");
}
。如,
hoveron="points"