2017-10-03 25 views
1

Google Maps APIでloadGeoJson()メソッドを使用すると、すべての機能の描画が完了したときに発生するイベントはありますか?Google Maps APIでGeojsonの描画が完了したときを決定する

マップの "アイドル"状態を聞くことができますが、読み込みが完了した時点で地図がアイドルと見なされているように見えますが、機能が描画される前の状態です。私はまた、任意の機能をマップに追加しましたが、私はすべての機能がマップに追加された後に実行するalert()を必要とされるときに発生ますaddFeature()リスナーについて知っ https://jsfiddle.net/z3tu0epb/

var map; 

function initMap() { 
    map = new google.maps.Map(document.getElementById('map'), { 
    zoom: 12, 
    center: new google.maps.LatLng(40.755690, -73.975938) 
    }); 

    // Load GeoJSON. 
    map.data.loadGeoJson(
    'https://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/nybb/FeatureServer/0/query?where=1=1&outFields=*&geometryPrecision=8&outSR=4326&f=geojson'); 

    google.maps.event.addListenerOnce(map, 'idle', function() { 
    alert("map is idle"); 
    }); 

} 

: は、以下のフィドルを参照してください。

おかげで、

答えて

1

私は、データ層のためのイベント「すべての機能を描画した後、」キャプチャする実現可能な方法はありません怖いです。データレイヤーが内部で使用されている描画マネージャーのインスタンスを公開している可能性があります。この場合、あなたは

https://developers.google.com/maps/documentation/javascript/reference#OverlayCompleteEvent

overlaycompleteイベントに耳を傾けることができしかし、あなたはリスナーを追加することはできませんので、データ層は、公にその描画マネージャインスタンスを公開しません。あなたが行うことができます

https://developers.google.com/maps/documentation/javascript/reference#Data

ユニークなことは、すべての機能がロードされたとき(コレクションに追加)を把握することです。この場合、あなたはGoogle issue tracker

にこのようなイベントのための機能要求を提出するためにも、お気軽に loadGeoJson(url:string, options?:Data.GeoJsonOptions, callback?:function(Array<Data.Feature>))

var map; 
 

 
function initMap() { 
 
    map = new google.maps.Map(document.getElementById('map'), { 
 
    zoom: 12, 
 
    center: new google.maps.LatLng(40.755690, -73.975938) 
 
    }); 
 

 
    // Load GeoJSON. 
 
    map.data.loadGeoJson(
 
    'https://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/nybb/FeatureServer/0/query?where=1=1&outFields=*&geometryPrecision=8&outSR=4326&f=geojson', 
 
    {}, 
 
    function(features) { 
 
     alert("Loaded " + features.length + " features"); 
 
    }); 
 

 
    google.maps.event.addListenerOnce(map, 'idle', function() { 
 
    alert("map is idle"); 
 
    }); 
 
    
 
    
 

 
}
#map { 
 
    height: 100%; 
 
} 
 

 

 
/* Optional: Makes the sample page fill the window. */ 
 

 
html, 
 
body { 
 
    height: 100%; 
 
    margin: 0; 
 
    padding: 0; 
 
}
<div id="map"></div> 
 
<!-- Replace the value of the key parameter with your own API key. --> 
 
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDztlrk_3CnzGHo7CFvLFqE_2bUKEq1JEU&callback=initMap"> 
 

 

 
</script>

のコールバック関数を使用することができます

関連する問題