Google地图 - 将InfoWindows附加到阵列中的多边形 [英] Google Maps - Attaching InfoWindows to polygons in array
问题描述
干杯!
C ...
tmppoly = new google.maps.Polygon({
map:map,
paths:polypath,
strokeColor:scolor ,
strokeOpacity:0.5,
strokeWeight:2,
fillColor:fcolor,
fillOpacity:0.5
});
addPolygonClick(tmppoly,mdata);
plot_polygons.push(tmppoly);
函数addPolygonClick(poly,html){
infowindow = new google.maps.InfoWindow(
{
content:html
});
google.maps.event.addListener(poly,'click',function(event){
this.setOptions({fillColor:#000000});
infowindow .open(map);
});
首先,你应该知道关于方法'infowindow.open(map,anchor?:MVCObject)'的表达式''。正如google api v3所说:在核心API中,唯一的锚是Marker类。 Polygon类不符合条件,但是,我们可以通过其他方式实现。
var polygon = new google.maps.Polygon ({
paths:PGpoints,// PGpoints是这个多边形周围的点集合
map:map $ b $ strokeColor colory $ b $ strokeOpacity 0.6
strokeWeight:1,
fillColor:colory,
fillOpacity:0.35
});
polygon.set(Info,idy); //设置一些用于向该多边形添加额外信息的属性。
google.maps.event.addListener(多边形,'click',function(){
var infoWindow = new google.maps.InfoWindow();
infoWindow.setContent( 信息:+ polygon.get(Info));
//'laty,lngy'是PGpoints中一个点的位置,可以根据需要选择
infoWindow.setPosition(new google.maps.LatLng(laty,lngy));
infoWindow.open(map);
});
上面的代码已通过测试,您可以直接使用它。然后,如果您单击一个多边形,infoWindow会出现在地图上方。
I've been banging my head against the wall all morning with this one. I an creating an array of polygons, and want to associate some data in each one that will show in an infoWindow. I can see all the polygons on the map. I add the listener, and it fires (the color change happens), but I don't get the infoWindow. Any help would be greatly appreaciated!
Cheers!
C...
tmppoly = new google.maps.Polygon({
map: map,
paths: polypath,
strokeColor: scolor,
strokeOpacity: 0.5,
strokeWeight: 2,
fillColor: fcolor,
fillOpacity: 0.5
});
addPolygonClick(tmppoly,mdata);
plot_polygons.push(tmppoly);
...
function addPolygonClick(poly,html) {
infowindow = new google.maps.InfoWindow(
{
content: html
});
google.maps.event.addListener(poly,'click', function(event) {
this.setOptions({fillColor: "#000000"});
infowindow.open(map);
});
}
I can provide some useful suggestions about your question.
Firstly, you should know the expression about the method 'infowindow.open(map, anchor?:MVCObject)'. As the google api v3 says: In the core API, the only anchor is the Marker class. Polygon class does not match the condition, however, we can achieve in another way.
var polygon = new google.maps.Polygon({
paths: PGpoints, //The PGpoints is the collection of points around this polygon.
map: map,
strokeColor: colory,
strokeOpacity: 0.6,
strokeWeight: 1,
fillColor: colory,
fillOpacity: 0.35
});
polygon.set("Info", idy); // Set some attributes for adding extra information into this polygon.
google.maps.event.addListener(polygon, 'click', function() {
var infoWindow = new google.maps.InfoWindow();
infoWindow.setContent("Information : " + polygon.get("Info"));
// 'laty,lngy' is the location of one point in PGpoints, which can be chosen as you wish
infoWindow.setPosition(new google.maps.LatLng(laty,lngy));
infoWindow.open(map);
});
The code above has passed test, you can use it directly. Then, if you click one polygon, infoWindow would appear above the map.
这篇关于Google地图 - 将InfoWindows附加到阵列中的多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!