javascript – Maps API v3:新的InfoWindow,带有pixelOffset,带有来自KML的数据.
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – Maps API v3:新的InfoWindow,带有pixelOffset,带有来自KML的数据.,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3687字,纯文字阅读大概需要6分钟。
内容图文
![javascript – Maps API v3:新的InfoWindow,带有pixelOffset,带有来自KML的数据.](/upload/InfoBanner/zyjiaocheng/764/30fb17770a244879828acac6871c78ec.jpg)
您好:我在Google地图上取得了进展(请参阅我上一篇文章:KML markers missing on Google Maps API v3: What’s wrong?),但我现在卡住了,并希望得到帮助.
我的自定义样式地图来自一个包含大约20个地标的KML文件.
出于设计原因,我希望我的地标在锚点的右侧打开,而不是默认的顶部/中心.我试着用一种简单的方法来寻找这个;离我最近的是:Issue with infowindows remaining active when another KML layer is selected – Google Maps API V3,我不能为我工作.
这是我正在寻找的一个例子:http://nationaltreasures.aircanada.com/(它的InfoWindows向右开).
我想我需要压缩默认的InfoWindow,创建我自己的拉取KML数据,然后为我的自定义InfoWindow指定pixelOffset,但我无法弄清楚如何做到这一点.
先感谢您!
function initialize() {
var styles = [ ]; // Styles removed to simplify code
var styledMap = new google.maps.StyledMapType(styles,
{name: "HEPAC"});
var mapOptions = {
zoom: 7,
center: new google.maps.LatLng(46.69504, -67.69751),
panControl: false,
mapTypeControl: false,
streetViewControl: false,
noClear: true,
zoomControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
},
mapTypeControlOptions: {
mapTypeIds: ['map_style', google.maps.MapTypeId.ROADMAP]
}
};
google.maps.visualRefresh = true;
var map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);
map.mapTypes.set('map_style', styledMap);
map.setMapTypeId('map_style');
var opt = { minZoom: 7, maxZoom: 9 }; // Sets minimum & maximum zoom level
map.setOptions(opt);
var ctaLayer = new google.maps.KmlLayer({
url: 'http://hepac.ca/wp-content/mapping/wellnessnetworksl.kml?f=3',
preserveViewport: true,
});
ctaLayer.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
解决方法:
antyrat在这里用标记右侧的infoWindow发布了这个:
请参阅接受的答案中的链接.
编辑:这是一个例子.显然,您需要在页面上包含InfoBox.js才能访问该插件.我希望这有效,我没有测试它,但它可能会指向正确的方向:
function initialize() {
var styles = [ ]; // Styles removed to simplify code
var styledMap = new google.maps.StyledMapType(styles,
{name: "HEPAC"});
var mapOptions = {
zoom: 7,
center: new google.maps.LatLng(46.69504, -67.69751),
panControl: false,
mapTypeControl: false,
streetViewControl: false,
noClear: true,
zoomControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
},
mapTypeControlOptions: {
mapTypeIds: ['map_style', google.maps.MapTypeId.ROADMAP]
}
};
google.maps.visualRefresh = true;
var map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);
map.mapTypes.set('map_style', styledMap);
map.setMapTypeId('map_style');
var opt = { minZoom: 7, maxZoom: 9 }; // Sets minimum & maximum zoom level
map.setOptions(opt);
var ctaLayer = new google.maps.KmlLayer({
url: 'http://hepac.ca/wp-content/mapping/wellnessnetworksl.kml?f=3',
preserveViewport: true,
});
ctaLayer.setMap(map);
google.maps.event.addListener(ctaLayer, 'click', function(kmlEvent) {
var text = kmlEvent.featureData.description; // ALTER THIS TO POINT TO THE DATA YOU WANT IN THE INFOBOX
var infoBox = new InfoBox({content: text, latlng: kmlEvent.position, map: map});
});
}
Google Maps API说:
Additionally, a click on a KML feature generates a KmlMouseEvent,
which passes the following information:
position indicates the latitude/longitude coordinates at which to anchor the InfoWindow for this KML feature. This position is generally
the clicked location for polygons, polylines, and GroundOverlays, but
the true origin for markers.
pixelOffset indicates the offset from the above position to anchor the InfoWindow “tail.” For polygonal objects, this offset is typically
0,0 but for markers includes the height of the marker.
featureData contains a JSON structure of KmlFeatureData.
有关详细信息,请参阅此页面:KML Feature Details
内容总结
以上是互联网集市为您收集整理的javascript – Maps API v3:新的InfoWindow,带有pixelOffset,带有来自KML的数据.全部内容,希望文章能够帮你解决javascript – Maps API v3:新的InfoWindow,带有pixelOffset,带有来自KML的数据.所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。