2017-12-31 236 views

답변

1

은 (피쳐 그룹을 확장) 전단지 GeoJSON 층 그룹을 구축 있도록 L.geoJSON 공장을 통해 GeoJSON 개체를 구문 분석하면, 당신이 리플릿은 그룹의 getBound() 방법을 사용하여 자식 레이어의 경계 (기능)을 계산할 수 있습니다, 그룹을지도에 추가하지 않아도됩니다.

var map = L.map('map').setView([48.86, 2.35], 11); 
 

 
var geojsondata = {"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [2.34, 48.86]}}, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [2.36, 48.86]}}]}; 
 

 
var geojsongroup = L.geoJSON(geojsondata); 
 
//geojsongroup.addTo(map); 
 

 
alert(geojsongroup.getBounds().toBBoxString()); 
 

 
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { 
 
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' 
 
}).addTo(map);
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"> 
 
<script src="https://unpkg.com/[email protected]/dist/leaflet-src.js"></script> 
 

 
<div id="map" style="height: 200px"></div>