我正在使用多边形形状文件,我想打开和关闭地图上某些功能的可见性。但是,我无法达到功能的属性。我尝试了下面的代码,但它没有通过循环。我该怎么办?
<html>
<head>
<meta charset=utf-8 />
<title>getMap</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v2.2.2/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v2.2.2/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<link href='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v0.0.4/leaflet.fullscreen.css' rel='stylesheet' />
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v0.0.4/Leaflet.fullscreen.min.js'></script>
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-hash/v0.2.1/leaflet-hash.js'></script>
<div id='map'>
</div>
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoibWVsYm91cm5ldW5pIiwiYSI6ImNpZzc4YmNvdTBrdzR0dWx6cW1tZG00d2UifQ.T4kFqEpykbTCepilYVeL_g';
var map = L.mapbox.map('map', 'mapbox.streets', {attributionControl: true});
var featureLayer = L.mapbox.featureLayer('melbourneuni.hetjfw29').addTo(map);
featureLayer.on('ready', function(){
// navigate the GeoJSON to get to the coordinates
var geojson = this.getGeoJSON();});
</script>
</body>
</html>
答案 0 :(得分:0)
只需使用var geojson = this.getGeoJSON()
,例如
featureLayer.on('ready', function(e){
var geojson = this.getGeoJSON()
// which returns featureCollection, iterate through `geojson.features` array next as you need
});