2

Google Maps API V3 の複雑なアイコンの例https://developers.google.com/maps/documentation/javascript/examples/icon-complex を変更して、配列からデータを取得し、各マーカーの位置にカスタム情報ウィンドウのコンテンツとタイトルを表示するようにしました. また、'locations' 配列の個々のアイテムの説明に基づいて、特定のカスタム イメージ アイコンを、さまざまな「オープン」、「クローズド」、「パブリック」、または「フル」イメージ アイコンで表示したいと考えています。

新しいマーカーを作成するときに配列をループし、タイトルや情報ウィンドウのテキストと同じ方法で「場所」配列から特定のデータを取得する画像変数を適切に作成するにはどうすればよいですか?

完全な HTML と Javascript。

<script
src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=weather">  
</script>

<script type="text/javascript">



var locations =
[

  ['Coogee Beach', -33.923036, 151.259052, 5, 20, "Closed",],
  ['Cronulla Beach', -34.028249, 151.157507, 3, 50 ,"Full",],
  ['Manly Beach', -33.80010128657071, 151.28747820854187, 2, 10, "Public",],
  ['Maroubra Beach', -33.950198, 151.259302, 1, 30, "Open",]
  ];

  //json array

 function initialize() {

var myOptions = {
  center: new google.maps.LatLng(33.890542, 151.274856),
  zoom: 8,


panControl:false,
zoomControl:false,
mapTypeControl:true,
scaleControl:false,
streetViewControl:false,
overviewMapControl:false,
rotateControl:false,
mapTypeControlOptions: {
  style:google.maps.MapTypeControlStyle.DROPDOWN_MENU,
  position:google.maps.ControlPosition.BOTTOM_LEFT
},
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById("default"),
    myOptions);

setMarkers(map, locations)

}

function setMarkers(map,locations){

// 地図にマーカーを追加

// マーカーのサイズは X,Y のサイズとして表されます。 // ここで、画像の原点 (0,0) は画像の左上にあります。

// マーカーの原点、アンカー位置、および座標 // X 方向では右に増加し、 // Y 方向では下に増加します。

 var weatherLayer = new google.maps.weather.WeatherLayer({
  temperatureUnits: google.maps.weather.TemperatureUnit.FAHRENHEIT

  });
 weatherLayer.setMap(map);

 var cloudLayer = new google.maps.weather.CloudLayer();
 cloudLayer.setMap(map);





var image = new google.maps.MarkerImage('images/beachflag.png',
  // This marker is 32 pixels wide by 37 pixels tall.
  new google.maps.Size(32, 37),
  // 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,37.
  new google.maps.Point(0, 37));           

var shadow = new google.maps.MarkerImage('images/shadow-beachflag.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(51,37),
  new google.maps.Point(0,0),
  new google.maps.Point(0, 37));
  // 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
  //var icon = typeObject[markers1[i][3]]['icon'];
  // coordinate.
 var shape = {
      coord: [1, 1, 1, 20, 18, 20, 18 , 1],
      type: 'poly'//
  };




  var marker, i

for (i = 0; i < locations.length; i++)
 { 

 var project = locations[i][0]
 var lat = locations[i][1]
 var long = locations[i][2]
 var add =  locations[i][3]
 var complete = locations[i][4]
 var percentage = locations[i][4]


latlngset = new google.maps.LatLng(lat, long);

var marker = new google.maps.Marker({ 
      map: map,
title: project , position: latlngset, icon: image, shadow: shadow,

    });
    map.setCenter(marker.getPosition())


    var content =
    '<div id="content">'+
    '<h1 id="firstHeading" </h1>'+
    project + 

    '</h1>' +
    " # of Life Guards: " +
    add  +  
    '</h3>' +
    " | Percentage: "
    + complete;
    //infobox content

  var infowindow = new google.maps.InfoWindow()
            maxwidth:800,
google.maps.event.addListener(marker,'click',

(function(marker,content,infowindow){
    return function() {
       infowindow.setContent(content);
       infowindow.open(map,marker);

    };

  })(marker,content,infowindow));

  }
  }
4

1 に答える 1