我一直在为客户创建这张地图,但我觉得有点头晕目眩。到目前为止,我已经成功地使用 modx 为地图动态创建了一个标记列表,创建了一个成功运行的自定义图标,并且我已经将它设置为我想要的样式。但是,我正在寻求有关以下方面的帮助:
自定义图标并没有准确指向我想要的位置。我假设 iconAnchor 变量是控制它的东西。那是对的吗?它的值是否只是图标的 x/y 协调?我也想知道我的信息窗口定位在哪里被控制。
当我单击列表中的某个位置时,地图以该位置为中心,但结果,我的信息窗口超出了地图的底部。有没有办法让标记图标出现在地图的左上象限?
我的信息窗口最终将有一个包含大约 10-15 个图像的列表,旁边有文本,我希望信息窗口可以滚动。我已经完成了这项工作,但是当我单击并向下移动滚动条时,一旦松开鼠标,它就会停止滚动,但随后会按住地图-结果,滚动后,地图会随着鼠。知道是什么原因造成的吗?
我最后关心的是加载后地图如何从一个点跳到另一个点。它只显示每个位置片刻,然后跳转到下一个位置。是否可以删除此功能并设置一个显示我所有标记的起始地图区域?
感谢您的任何建议。
我的代码改编自:http ://www.erikwhite.net/gmapjquery.html
这是我当前的代码:
$(document).ready(function(){
var defaultLat = 50.5;
var defaultLon = -1.4;
//code to enable a customer marker on the map
var icon = new GIcon();
icon.image = '/img/icon.png';
icon.iconSize = new GSize (45, 48);
icon.iconAnchor = new GPoint (8, 42);
icon.infoWindowAnchor = new GPoint (43, 6);
//var markers = new GMarker(getLatLng();, icon);
var markers = new Array();
markers[0] = new Array(new GMarker(new GLatLng(LAT, LNG), icon), "TITLE", "title, blurb and a set of images paired with a line of text");
var map = new google.maps.Map2($("#map").get(0));//Initialise google maps
map.setCenter(new GLatLng(defaultLat, defaultLon), 15);//Set location to the default and zoom level
map.disableDoubleClickZoom();//Disable zooming
$.each(markers,function(i,marker){
var delayTime = ((i * 300) / (0.5 * markers.length));//Delay time decreases as number of markers increases
setTimeout(function(){
map.addOverlay(marker[0]);
$("")
.html(markers[i][1])//Use list item label from array
.click(function(){
displayPoint(marker[0], i);
setActive(this);//Show active state
})
.appendTo("#list");
GEvent.addListener(marker[0], "click", function(){
displayPoint(marker[0], i);
setActive(i);//Show active location
});
displayPoint(marker[0], i);
setActive(i);//Show active location
if (i == (markers.length - 1)) {//If last item in array
setTimeout(function(){//Remove active class and fade marker after delay
$("#map_message").fadeOut();
//setActive();
}, 3500);
}
}, delayTime);
});
$("#list").css("opacity","0.2").animate({opacity: 1}, 1100);//Fade in menu
$("#map_message").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
function displayPoint(marker, index){
if ($('#map_message').is(':hidden')) {//Allow toggling of markers
$('#map_message').fadeIn();
}
else{//Remove all .active classes and hide markers
$('#map_message').hide();
$(".active").removeClass();
}
//$("#map_message").hide();//Default behaviour, doesn't allow toggling
var moveEnd = GEvent.addListener(map, "moveend", function(){
var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
$("#map_message")
.html(markers[index][2])//Use information from array
.fadeIn()
.css({ top:markerOffset.y, left:markerOffset.x });
GEvent.removeListener(moveEnd);
});
map.panTo(marker.getLatLng());
}
function setActive(el){
$(".active").removeClass();//Remove all .active classes
$("#list").find('li').eq(el).addClass('active');//Find list element equal to index number and set active
$(el).addClass('active');//Set active if list element clicked directly
}
}); //End onReady
<div id="map" style="width: 500px; height: 350px; border: 1px solid #777; ">map</div>
<div id="list"></div>
<div id="map_message"></div>
#map { float:left; margin-left: 180px; width:500px; height:350px; }
#map_message { position:absolute; padding:10px; background:#5dbb46; color:#fff; width:200px; height:180px; overflow:auto; }
#list { float:left; width:150px; background:#acacad; color:#fff; list-style:none; padding:0; }
#list li { padding:8px; }
#list li:hover { background:#bdbdbe; color:#fff; cursor:pointer; cursor:hand; }