3

google map api v3を使用して、円をマーカーに正常にバインドしました。マーカーをドラッグ可能にすると、円も移動するので、これを知っています。

マーカーがクリックされた場合、どうすれば円を参照できますか。表示されていない場合、またはその逆の場合は、円を表示する必要があります。

マーカーと円を作成するためのコードは次のとおりです

var markerOptions = {
title: title,
icon: markerImage,
shadow: markerShadow,
position: latlng,
map: map
}
var marker = new google.maps.Marker(markerOptions);   
// Add a Circle overlay to the map.
var circle = new google.maps.Circle({
map: map,
radius: 50*1609.34,// 50 MI
visible: false
});
//circle.bindTo('map', marker);
circle.bindTo('center', marker, 'position');

スタックオーバーフローに関する回答を見つけたので、中央のバインディングだけでなく、削除されたマップのバインディングも実行する必要があると思いましたが、それは機能しませんでした。

これがマーカーのクリックイベントです。

google.maps.event.addListener(marker, "click", function() {
var infowindowOptions = {
content: html
 }
var infowindow = new google.maps.InfoWindow(infowindowOptions);
cm_setInfowindow(infowindow);
infowindow.open(map, marker);
marker.setIcon(markerImageOut);
marker.circle({visible: true});

何か案は。クリックまたはマウスオーバーしたばかりのマーカーのバインドされた円を操作する必要があります。

4

2 に答える 2

5

1つのオプションは、円をマーカーのプロパティ(._myCircleなど)にし、クリックハンドラーでmarker._myCircleとして参照することです。

マーカーの_myCircleプロパティとして円を追加します。

var circle = new google.maps.Circle({
  map: map,
  radius: 50*1609.34,// 50 MI
  visible: false
});
circle.bindTo('center', marker, 'position');
marker._myCircle = circle;

切り替えるには、次のようなものを使用します(テストされていません):

if(marker._myCircle.getMap() != null) marker._myCircle.setMap(null);
else marker._myCircle.setMap(map);
于 2012-12-08T02:02:01.427 に答える
1
var rad =".$this->conf['radius'] * 1000 ."; //convert km to meter
var populationOptions = {
   strokeColor: '#FF0000',
   strokeOpacity: 0.8,
   strokeWeight: 1,
   fillColor: '#FF0000',
   fillOpacity: 0.35,
   map: map,//map object
   center: new google.maps.LatLng($corr_match[0], $corr_match[1]),//center of circle
   radius: rad
};
var cityCircle = new google.maps.Circle(populationOptions);
于 2014-10-01T10:49:06.513 に答える