【问题标题】:Leaflet - Convert lat/lng to standard projectionLeaflet - 将 lat/lng 转换为标准投影
【发布时间】:2015-09-02 11:15:39
【问题描述】:

如果数据在外部文件(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 库,但我找不到这种情况的类似示例(带有外部文件)。

【问题讨论】:

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


    【解决方案1】:

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

    我使用谷歌地图获取某个点的 GPS 纬度/经度,并在 Leaflet 中使用它们而无需转换。

    // 编辑 对我来说,传单和谷歌地图使用相同的投影。

    //编辑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);
    

    【讨论】:

    • 如果我理解得很好,你使用谷歌地图和传单的组合?有没有使用这种组合的例子?
    • 不,我使用带有 lat/lng 的传单,我从谷歌地图获得而无需转换。检查下面上传的图片
    • 嗯,在我的情况下它不起作用:(你能告诉我你使用哪个版本的传单吗?谢谢。
    • 我找到了。传单指令与纬度/经度相反,我不知道为什么。试试这个“坐标”:[2.294694,48.858093]“坐标”:[15.966568,45.815399]
    猜你喜欢
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    • 2017-03-01
    • 2023-04-07
    • 2018-11-12
    • 2018-10-31
    • 1970-01-01
    相关资源
    最近更新 更多