在 Openlayers 中跨日期行包装 Geojson 数据

Wrapping Geojson data across date line in Openlayers

我正在使用 OpenLayers 使用 USGS 数据集绘制地震图:

https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson

我正在添加图层并配置视图,如下所示:

var map = new Map({
  target: 'map',
  layers: [
    new TileLayer({
      source: new OSM()
    }),
    new ImageLayer({
      opacity: 0.3,
      source: raster
    }),
    new WebGLPointsLayer({
      source: new VectorSource({
        url: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson",
        format: new GeoJSON(),
        attributions: 'USGS'
      })
    })
  ],
  view: new View({
    center: fromLonLat([103.8198, 1.3521]),
    zoom: 1
  })
});

我的视图设置为在缩放级别 1 时,日期变更线包含在范围内。 USGS 数据不会呈现在日期变更线的右侧。我知道这是因为 VectorSource 的默认范围是 [-180, -90, 180, 90]。我的问题是,如何将该范围更改为地图视图的范围,以便数据呈现在日期变更线的另一侧?

似乎最好的方法是截取 USGS 数据的坐标并向 lon 坐标添加转换,也许可以通过 ol/proj.transform or ol/proj.transformExtent,但我一直无法找到 openlayers 数据包含坐标的对象,也没有对其应用地图或变换的方式。

向量层使用视图投影,除非指定,否则EPSG:3857以格林威治子午线

为中心

您可以尝试定义一个以日期变更线为中心的球形墨卡托

proj4.defs('sphmerc180', '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=180.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs');
register(proj4);

var sphmerc180 = getProjection('sphmerc180');
sphmerc180.setExtent(getProjection('EPSG:3857').getExtent());
sphmerc180.setGlobal(true);

然后将其用作视图投影

  view: new View({
    projection: sphmerc180,
    center: fromLonLat([103.8198, 1.3521], sphmerc180),
    zoom: 1
  })