gpt4 book ai didi

javascript - 缩小谷歌地图的事件?

转载 作者:行者123 更新时间:2023-11-30 17:23:52 24 4
gpt4 key购买 nike

我试图在我的 map 上保持一组恒定的样本标记以便于查看。在平移和缩放期间,我使用从数据库中随机选择的标记填充我的 map ,直到一定数量。主要问题是用新的入界标记替换越界标记。

除了缩小之外,下面的代码工作得很好。当我缩小时,我想用一组新的随机标记重复刷新 map ,直到一定数量并均匀分布在 map 上。问题是有一个 zoom_changed 事件,但它似乎没有区分 in 和 out。

有什么建议吗?

      google.maps.event.addListener(map, 'idle', function() {
bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var north = northEast.lat();
var south = southWest.lat();
var west = southWest.lng();
var east = northEast.lat();
var marnum = 20;
$.post('pzparsers/pzparsers.php', {north:north, south:south, west:west, east:east, marnum:marnum}, function(response){
eval(response);
bounds = map.getBounds();
if(oldmarkers.length == 0 && newmarkers.length !== 0){
//b = $.extend( true, {}, a );
for (var i = 0; i < newmarkers.length; i++) {
oldmarkers[i] = newmarkers[i];
oldmarkers[i].setMap(map);
}
} else if (oldmarkers.length !== 0 && newmarkers.length !== 0){
for (var i = 0; i < oldmarkers.length; i++){
if(!bounds.contains(oldmarkers[i].getPosition())){
oldmarkers[i].setMap(null);
oldmarkers[i] = newmarkers[i];
oldmarkers[i].setMap(map);
}
}
}
});
});

PHP: -

  $output .= "newmarkers.length = 0;\n";
if($mrk_cnt > 0){
for ($lcnt = 0; $lcnt < $mrk_cnt; $lcnt++){
$output .= "var point = new google.maps.LatLng($lat[$lcnt], $lng[$lcnt]);\n";
$output .= "var mrktx = \"$inf[$lcnt]\";\n";
$output .= "var infowindow = new google.maps.InfoWindow({ content: mrktx });\n";
$output .= "var marker = new google.maps.Marker({position: point, icon: $icon[$lcnt], title: '$inf[$lcnt] $begin[$lcnt] - $end[$lcnt]'});\n";
$output .= "google.maps.event.addListener(marker,'click', function() {infowindow.open(map,marker);});\n";
//$output .= "marker.setMap(map);\n";
$output .= "newmarkers.push(marker);\n";
}
}

最佳答案

如果没有内置函数,就做一个。请尝试以下方法:

var mapzoom;

function initialize()
{

//first get the zoom value of the map in initialize function
mapzoom=map.getZoom();
}

google.maps.event.addListener(map, 'zoom_changed', function() {

var zoomLevel = map.getZoom();

if(mapzoom> zoomLevel)
{
//means zoom out do your code here

}

mapzoom=map.getZoom(); //to stored the current zoom level of the map

});

关于javascript - 缩小谷歌地图的事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24652763/

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