gpt4 book ai didi

javascript - kml 文件中来自多边形的 LatLngBounds?

转载 作者:行者123 更新时间:2023-11-29 22:24:27 27 4
gpt4 key购买 nike

我是 google map 和 API 的新手,试图通过点击将 map 平移到某个区域。我没有时间在 API 引用中找到我需要的东西,也不确定如何去做,所以我没有太多东西,但这是我目前所拥有的。

我想让它点击任何区域都会平移并放大以显示该区域的大部分,我相信这就是 panToBounds是为了做。

大部分功能将来自点击文本名称并让 map 加载显示正确的位置,而不是点击 map 本身

function initialize_neighbourhoodmap(neighbourhood_name) {
var latlng = new google.maps.LatLng(42.949442,-81.228125);

var zoom = 11;
var neighbourhood_center = get_neighbourhood_center();

var myOptions = {
zoom: zoom,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

map = new google.maps.Map(document.getElementById("neighbourhood_map"),
myOptions);

var neighbourhoods = new google.maps.KmlLayer('http://maps.google.com/maps/ms?authuser=0&ie=UTF8&hl=en&oe=UTF8&vps=3&msa=0&output=kml&msid=217366496682144933685.0004bf3be50d3cd7ad1c2', {suppressInfoWindows: true, preserveViewport:true});
neighbourhoods.setMap(map);

google.maps.event.addListener(neighbourhoods, 'click', function(KmlFeatureData) {
var neighbourhood_name = KmlFeatureData.featureData.name;
load_neighbourhood(neighbourhood_name, neighbourhoods);
window.location = "#neighbourhood-neighbourhood "+neighbourhood_name;
});

if(typeof neighbourhood_name !== 'undefined'){
load_neighbourhood(neighbourhood_name, neighbourhood_center);
}
}

function load_neighbourhood (neighbourhood_name, neighbourhoods) {
var neighbourhoodbounds = nonexistentgetboundsfunction(neighbourhood_name);
map.panToBounds(neighbourhood_center[neighbourhood_name][0]);
$('#neighbourhood h2').html('neighbourhood '+neighbourhood_name);
}

最佳答案

您确定需要其他功能吗?在我看来,用户界面变得很尴尬。嗯,这里是:http://jsfiddle.net/g343k/3/

我遇到了一个奇怪的“错误”,或者有些人可能称之为“特征”,它与 KML 多边形相关联。单击某个区域时, map 会平移到该区域的中心;但是,当单击外部 planning_district 区域时, map 会平移到框的中心,而不是单击所在的位置(Sean Mickey 在 FireFox 12 中进行了测试,它平移到单击)。除了将规划区分割为几十个更小的盒子之外,我想不出解决这个问题的办法:(现在我已经编写了代码来忽略对规划区的点击。

google.maps.event.addListener(neighbourhoods, 'click', function(KmlFeatureData) {
var neighbourhood_name = KmlFeatureData.featureData.name;
load_neighbourhood(neighbourhood_name, neighbourhoods);
window.location = "#neighbourhood-neighbourhood "+neighbourhood_name;
// ADDED
// Consider what to do when this outer area is clicked
if(KmlFeatureData.featureData.name!="planning_districts_2008") {
map.panTo(KmlFeatureData.latLng);
}

});

// LEFT OUT
//if(typeof neighbourhood_name !== 'undefined'){
// load_neighbourhood(neighbourhood_name, neighbourhood_center);
//}

// ADDED
google.maps.event.addListener(map, 'click', function(event) {
map.panTo(event.latLng);
});

关于javascript - kml 文件中来自多边形的 LatLngBounds?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10456290/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com