2010-02-23 8 views
1

현재지도 위에 많은 맞춤 마커를 플롯 한 다음 클릭하면 팝업 페이지가 생성되는 프로젝트를 진행 중입니다. 이 문제는 자바 스크립트에서 초보자가되어지도에 두 번째 마커 이미지가 표시되는 중입니다. 당신이 볼 수있는 '카메라'아이콘이 작동 ...하지만 '칼텍스'을 필요로하는 것도 작업으로 지금까지 내가 ..., 다음과 같은 코드를 가지고 : 당신이에 마커 로직을 캡슐화 같은Google Maps APIv3 - 다른 png 이미지로 여러 마커를 오버레이하는 방법

<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script> 
<script type="text/javascript"> 
    function initialize() { 
    var latlng = new google.maps.LatLng(-43.54654110763488, 172.6156002235225); 
    var myOptions = { 
     zoom: 11, 
     center: latlng, 
     navigationControl: false, 
     scaleable: false, 
     draggable:false, 


     navigationControlOptions: {style: google.maps.NavigationControlStyle.ANDROID,position: google.maps.ControlPosition.TOP_LEFT}, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 


    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 


    setMarkers(map, webcams, caltex); 
    } 


    /** 
* Data for the markers consisting of a name, a LatLng and a zIndex for 
* the order in which these markers should display on top of each 
* other. 
*/ 
var webcams = [ 
    ['Anzac Dr ', -43.51129867148775, 172.7162349879427, 9], 
    ['QEII', -43.48499827165804, 172.6179431987025, 8], 
    ['Yaldhurst Russley', -43.52069820902269, 172.5344992587786, 7], 
    ['Waimakariri Bridge', -43.47192540674842, 172.5693997383076, 6], 
    ['Dyers Linwood', -43.54654110763488, 172.6956002235225, 4], 
    ['Main North W', -43.4513336384715, 172.6278547889116, 5], 
    ['Main North N', -43.4509480091774, 172.6386309983553, 3], 
    ['Memorial Ave', -43.49318192393784, 172.5499633557023, 2], 
    ['The Hub', -43.54341394837794, 172.5256827185488, 1] 

]; 


/** Markers for caltex stations **/ 

var caltex = [ 
    ['Caltex VIC', -41.01785817829983, 174.91504669189453, 11], //Corner High & Brunswick Streets 
    ['Caltex Porirua', -41.01785817829983, 174.91504669189453, 10], //Parumoana Street 
    ['Caltex Railway Avenue', -41.01785817829983, 174.91504669189453, 9], //20 Railway Avenue 
    ['Olympic Service Station', -41.23076651060946, 174.8100757598877, 8], //Corner Holland Crescent & Vogel Street 
    ['Caltex Rimutaka', -41.2346071181492, 174.80685710906982, 7], //1193 Fergusson Drive North 
    ['Caltex Wellington Airport', -41.243384802383986, 174.81380939483643, 6], //Corner Calabar Road & Broadway 
    ['Caltex Wainuiomata', -41.29338219297847, 174.78076457977295, 4], //14-16 The Strand 
    ['Caltex Upper Hutt', -41.301958541159564, 174.7844123840332, 5], //749-755 Fergusson Drive 
    ['Caltex Stokes Valley', -41.286771831897774, 174.77312564849854, 3], //7 Stokes Valley Road, Stokes Valley 
    ['Caltex Newtown', -41.285127199004215, 174.7728681564331, 2], //224 Riddiford Street 
    ['Caltex Basin Reserve', -41.30211973991373, 174.7792625427246, 1] //28 Adelaide Road 

]; 


function setMarkers(map, locations) { 
    // 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('camera.png', 
     // This marker is 32 pixels wide by 32 pixels tall. 
     new google.maps.Size(32, 32), 
     // The origin for this image is 0,0. 
     new google.maps.Point(0,0), 
     // The anchor for this image is the base of the flagpole at 0,32. 
     new google.maps.Point(0, 0)); 


    var shadow = new google.maps.MarkerImage('camera_shadow.png', 
     // The shadow image is larger in the horizontal dimension 
     // while the position and offset are the same as for the main image. 
     new google.maps.Size(37, 32), 
     new google.maps.Point(0,0), 
     new google.maps.Point(0, 32)); 
     // Shapes define the clickable region of the icon. 
     // The type defines an HTML <area> element 'poly' which 
     // traces out a polygon as a series of X,Y points. The final 
     // coordinate closes the poly by connecting to the first 
     // coordinate. 
    var shape = { 
     coord: [1, 1, 1, 20, 18, 20, 18 , 1], 
     type: 'poly' 
    }; 



    for (var i = 0; i < locations.length; i++) { 
    var cameras = locations[i]; 
    var myLatLng = new google.maps.LatLng(cameras[1], cameras[2]); 
    var marker = new google.maps.Marker({ 
     position: myLatLng, 
     map: map, 
     shadow: shadow, 
     icon: image, 
     shape: shape, 
     title: cameras[0], 
     zIndex: cameras[3] 
    }); 
    } 



    for (var i = 0; i < locations.length; i++) { 
    var caltex = locations[i]; 
    var myLatLng = new google.maps.LatLng(caltex[1], caltex[2]); 
    var marker = new google.maps.Marker({ 
     position: myLatLng, 
     map: map, 
     shadow: shadow, 
     icon: image, 
     shape: shape, 
     title: caltex[0], 
     zIndex: caltex[3] 
    }); 
    } 
} 

     var marker = newGMarker(LatLng,cameras) 

</script> 
</head> 
<body onload="initialize()"> 
    <div id="map_canvas" style="width:450px; height:500px"></div> 
</body> 
</html> 

답변

0

가 보이는 setMarkers()를 호출하여 각 마커 유형에 대해 한 번 호출 할 수 있습니다. 그러나 한 번만 호출합니다. 필요한 항목 :

setMarkers(map, webcams); 
setMarkers(map, caltex); 
관련 문제