2017-12-31 30 views

答えて

1

それは(機能グループを拡張)リーフレットにGeoJSON層群を構築するように、あなたにGeoJSONオブジェクトはL.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>

関連する問題