【问题标题】:Openlayers Angularjs always shows GeoJSON Point at [0,0]Openlayers Angularjs 总是在 [0,0] 处显示 GeoJSON 点
【发布时间】:2016-04-28 06:56:22
【问题描述】:

这个问题最接近这个post。但似乎还没有解决(我无法对此发表评论),我想提供更多信息。

首先,我使用Inline GeoJSON,尝试分配一些随机点,例如:

{
        "type": "Feature",
        "properties": {},
        "geometry": {
           "type": "Point",
           "coordinates": [
                        99.140625,
                        9.44906182688142
                      ]
         }
};

结果始终为 [0,0]。它与经度和纬度无关。

顺便说一下,作者的例子是一个边界,经过测试,也没有显示出来。但在这里我想先测试一个点。

我错过了什么?

【问题讨论】:

    标签: angularjs openlayers-3 geojson


    【解决方案1】:

    我不知道您的其余代码是什么,但您提供的 geojson 工作正常。

    检查这个片段

    var format = new ol.format.GeoJSON();
    var myGeoJsonFeatures = format.readFeatures(
    myGeoJson, 
    {featureProjection: 'EPSG:3857'}
    );
    vector.getSource().addFeatures(myGeoJsonFeatures);  
    

    还有一个工作小提琴fiddle

    可能与您指定给地图的投影有关

    【讨论】:

    • 嗨,正常的 OpenLayers 正在工作。我的问题是关于 AngularJS 中的 Openlayers。
    • 嗨 pavlos,谢谢你的代码。我发布答案。投影信息将被包括在内!
    【解决方案2】:
    "source": {
    "type": "GeoJSON",
    "geojson": {
      "object": {
        "type": "FeatureCollection",
        "features": [
          {
            "type": "Feature",
            "id": "op",
            "properties": {
              "name": "aaa"
            },
            "geometry": {
              "type": "Point",
              "coordinates": [
                -9.520376,
                38.231155
              ]
            }
          }
        ]
      },
      "projection": "EPSG:4326"
    }
    

    显然,需要指定投影信息! 感谢 pavlos 作为他的代码提示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      相关资源
      最近更新 更多