Leaflet - 将lat / lng转换为标准投影

时间:2015-09-02 11:15:40

标签: angularjs leaflet geojson markerclusterer angular-leaflet-directive

如果数据在外部文件(geojson)中,如何将坐标从Leaflet坐标系转换为Google使用的坐标系(WGS-84?)? 在example with external geojson file中,我为巴黎和萨格勒布定义了坐标,我正在寻找将这些坐标转换为准确位置的解决方案:)

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": "par",
            "properties": {
                "name": "Paris"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    48.858093,
                    2.294694
                ]
            }
        },
        {
            "type": "Feature",
            "id": "zg",
            "properties": {
                "name": "Zagreb"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    45.815399, 
                    15.966568
                ]
            }
        }
    ]
}

有Proj4js JavaScript库,但我找不到类似的例子(使用外部文件)。

1 个答案:

答案 0 :(得分:0)

Leaflet可直接使用您的GeoJSon,而无需转换lat / lng。

我使用谷歌地图获取某些点的GPS lat / lng并在Leaflet中使用它们而不进行转换。

//编辑 对我来说,Leaflet和Google地图使用相同的投影。

enter image description here

//编辑2

Html:

   <div id="map" class="leaflet-container leaflet-fade-anim"></div>

JS:

  var map=L.map( "map" ,{
     center:[0,0],
     zoom:1, minZoom: 1 , maxZoom:18
  });
  var base_maps = [];
  var layer_OSM = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    noWrap: true,
    // continuousWorld: true,
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
    unloadInvisibleTiles: true
  });
  base_maps['OpenStreetMap'] = layer_OSM;
  map.addLayer(layer_OSM);



  var markersLayer = new L.FeatureGroup();

  var marker = L.marker([p_lat, p_lon]);

  markersLayer.addLayer(marker);
  map.addLayer(markersLayer);