Data layers 从与数据层API一起添加的geoJSON功能获取标记引用
我正在使用数据层API向地图添加geojson数据 但问题是addGeoJson方法返回一个特性列表,我找不到一个接口方法来检索与该特性关联的marker obj引用 我不想动态创建google标记对象,将它们添加到地图中并删除该功能。这太过分了 在我离开数据层并管理自己的标记之前,我只想使用正确的方法 谢谢Data layers 从与数据层API一起添加的geoJSON功能获取标记引用,data-layers,Data Layers,我正在使用数据层API向地图添加geojson数据 但问题是addGeoJson方法返回一个特性列表,我找不到一个接口方法来检索与该特性关联的marker obj引用 我不想动态创建google标记对象,将它们添加到地图中并删除该功能。这太过分了 在我离开数据层并管理自己的标记之前,我只想使用正确的方法 谢谢 Seb.我也有这个问题。我在API文档中找不到太多。您需要一个标记对象,但您没有标记对象,因为您已将其上载到数据层,所以您拥有了功能 但是,在中,它表示可以使用位置集创建MVCObject
Seb.我也有这个问题。我在API文档中找不到太多。您需要一个标记对象,但您没有标记对象,因为您已将其上载到数据层,所以您拥有了功能 但是,在中,它表示可以使用位置集创建MVCObject。我在下面的事件处理程序中这样做了。您不必将它放在地图上,只需通过创建MVCObject并将其提交给infoWindow构造函数来处理click事件 例子:
函数初始化(mapID){
var mylatng=new google.maps.LatLng(38.951644,-92.334127);
变量映射选项={
缩放:12,
中心:myLatlng
}
var map=new google.maps.map(document.getElementById(mapID),mapOptions);
map.data.addGeoJson(realstate_js.geojson_results);
map.data.setStyle(函数(特性){
//setStyle在每个功能上执行此函数。。。
//然后,每个功能都会收到“google.maps.Data.StyleOptions”对象
//它定义了它的图标和东西。
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Data.StyleOptions
返回{
“可点击”:true,
“图标”:feature.A.icon,
“标题”:功能A.address1,
}
});
var fakeMarker=new google.maps.MVCObject();
var infoWindow=new google.maps.infoWindow({
“内容”:“,
});
map.data.addListener('click',函数(事件){
fakeMarker.set('position',{'lat':event.latLng.A,'lng':event.latLng.F});
var infoWindow=new google.maps.infoWindow({
'内容':“信息窗口内容在此omg此so文本”+,
});
信息窗口。打开(地图,伪造者);
});
}
我相信A
和F
是缩小的内部名称,它们对我来说是不同的。相反,我做了fakeMarker.set('position',event.latLng)
。
function initialize(mapID) {
var myLatlng = new google.maps.LatLng(38.951644, -92.334127);
var mapOptions = {
zoom: 12,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById(mapID), mapOptions);
map.data.addGeoJson(realestate_js.geojson_results);
map.data.setStyle(function(feature){
// setStyle executes this function on each feature...
// each feature then receives the "google.maps.Data.StyleOptions" object
// which defines its icons and stuff.
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Data.StyleOptions
return {
'clickable':true,
'icon':feature.A.icon,
'title':feature.A.address1,
}
});
var fakeMarker = new google.maps.MVCObject();
var infoWindow = new google.maps.InfoWindow({
'content':"",
});
map.data.addListener('click', function(event){
fakeMarker.set('position', {'lat':event.latLng.A, 'lng':event.latLng.F});
var infoWindow = new google.maps.InfoWindow({
'content':"<h1>Info Window Content here</h1><p>omg this so text</p>" + ,
});
infoWindow.open(map, fakeMarker);
});
}