1

我一直在为客户创建这张地图,但我觉得有点头晕目眩。到目前为止,我已经成功地使用 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; }
4

1 回答 1

1

1) 自定义图标并没有准确指向我想要的位置。

尝试使用 MarkerImage 类来设置图标的位置。

function setMarkers(map) {
  // Add markers to the map

  // Marker sizes are expressed as a Size of X,Y
  // where the origin of the image (0,0) is located
  // in the top left of the image.

  // Origins, anchor positions and coordinates of the marker
  // increase in the X direction to the right and in
  // the Y direction down.

  var image = new google.maps.MarkerImage('../images/myimage.png',
      // This marker is 25 pixels wide by 25 pixels tall.
      new google.maps.Size(25, 25),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is the center at 12, 13.
      new google.maps.Point(12, 13));

  latlng = new google.maps.LatLng(lat, lng);
  var marker = new google.maps.Marker({
    position: latlng,
    map: map,
    icon: image
  });
 }

2)当我点击列表上的一个位置时,地图以该位置为中心,但结果,我的信息窗口超出了地图的底部。有没有办法让标记图标出现在地图的左上象限?

我不完全确定您的意思,但地图中心不必与标记图标的纬度和经度相同。您也可以为多个地图/标记做。

或者我可能没有得到你的问题。

3)我对滚动信息窗口没有太多经验,所以也许其他人可以回答这个问题。

4)我最后关心的是加载后地图如何从一个点跳到另一个点。它只显示每个位置片刻,然后跳转到下一个位置。是否可以删除此功能并设置一个显示我所有标记的起始地图区域?

在开始时显示所有标记实际上更容易。我的建议是按照http://code.google.com/apis/maps/documentation/javascript/overlays.html#ComplexIcons重写您的代码,并从您遵循的示例应用程序中保留并调整“displayPoint”功能以进行滚动单击侧链接时的效果,这将设置不同的中心并打开该位置的信息窗口。

您的地图“跳跃”的原因是代码遍历每个标记并在加载时为每个标记调用“displayPoint”。

于 2010-09-19T06:30:34.243 回答