【问题标题】:Displaying Antarctica using GeoJSON in heremaps在此处地图中使用 GeoJSON 显示南极洲
【发布时间】:2014-10-13 08:13:30
【问题描述】:

我正在尝试使用 HERE maps api 在地图上渲染 Antarctica geojson 形状。
geojson 在这里找到:https://github.com/johan/world.geo.json/blob/master/countries/ATA.geo.json
你可以看到 github 渲染得很好。
在 geojson.io 上使用相同的 geojson 也可以很好地呈现它。

但在 HERE 地图中使用它时,它似乎以某种方式呈现了南极洲的“反面”。
它为除南极洲以外的一切着色。 见:http://imagebin.ca/v/1dZIn5vsEuFx
(我尝试使用 jsfiddle 制作示例,但无法加载外部 json。HERE maps api 不允许您从字符串加载 geoJSON)

geoJSON 有问题吗? HERE 地图 api 有问题吗?

【问题讨论】:

    标签: javascript geojson here-api


    【解决方案1】:

    API 不太了解如何处理开放多边形。因为多边形基本上只是环绕地球的一条线,所以 API 不知道你的形状是靠近北极还是南极。默认情况下,它假定开放的多边形靠近北极。您可以通过使用此标志 (setNorthPoleCovering) 来更改它:

    http://developer.here.com/javascript-apis/documentation/v3/maps/topics_api_nlp/h-map-polygon.html#h-map-polygon__setnorthpolecovering

    然而,实际上要在代码中实现这一点有点复杂:

    // When you instantiate the geojson.Reader you can specify a function that 
    // receives all objects the reader parsed. It is called when objects are 
    // being rendered on the map. At that point we can look into the object and
    // check whether it is Antarctica
    var reader = new H.data.geojson.Reader('...ATA.geo.json', {
      style: function(obj) {
        if (obj.getData().properties.name === "Antarctica") {
          //AHA! We found Antarctica!
          // Since this is a multi-polygon we have a group here which contains
          // all polygons. We apply the north-pole-covering flag to each of the
          // polygons
          obj.forEach(function(polygon) {
            polygon.setNorthPoleCovering(false);
          });
        }
      }
    });
    reader.parse();
    map.addLayer(reader.getLayer());

    【讨论】:

      【解决方案2】:

      根据您希望在动态行为方面实现的目标,如果您只是希望显示或共享带有卡片和其他元数据的地图,其中包含一些基本样式的国家/地区 -- HERE XYZ 可用于呈现 GeoJSON在 HERE 地图上。

      如果您想使用 JavaScript 而不是嵌入式 iframe,那么您可能正在寻找另一个答案。

      【讨论】:

        【解决方案3】:

        GeoJSON 存在问题,其他映射 API 也会有同样的问题。它需要在180度子午线关闭,所以

        [178.277212,-84.472518],[180,-84.71338],[-179.942499,-84.721443]
        

        变成

        [178.277212,-84.472518],[180,-84.71338],[180,-90],[-180,-90],[-180,-84.71338],[-179.942499,-84.721443]
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-10-16
          • 2022-11-11
          • 2014-12-22
          • 1970-01-01
          • 1970-01-01
          • 2022-10-19
          • 2019-05-29
          相关资源
          最近更新 更多