在 Openlayers 中跨日期线包装 Geojson 数据 [英] Wrapping Geojson data across date line in Openlayers

查看:101
本文介绍了在 Openlayers 中跨日期线包装 Geojson 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using OpenLayers to map earthquakes using the USGS dataset available at:

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

我正在添加图层并像这样配置视图:

I am adding layers and configuring the view like so:

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].我的问题是,如何将该范围更改为地图视图的范围,以便数据呈现在日期变更线的另一侧?

My view is set so that at zoom level 1, the date line is included in the extent. The USGS data does not render to the right of the date line. I understand that this is because the VectorSource's default extent is [-180, -90, 180, 90]. My question is, how can I change that extent to the extent of the map view so that data renders on the other side of the the date line?

似乎最好的方法是拦截 USGS 数据的坐标并对 lon 坐标添加转换,可能通过 ol/proj.transformol/proj.transformExtent,但我一直无法找到包含坐标的 openlayers 数据对象,也找不到对它们应用地图或变换的方法.

It seems like the best approach would be to intercept the coordinates of the USGS data and add a transformation to the lon coordinate, maybe through ol/proj.transform or ol/proj.transformExtent, but I haven't been able to find the openlayers data object that contains the coordinates nor the way to apply a map or transformation to them.

推荐答案

矢量层使用视图投影,除非指定是 EPSG:3857 以格林威治子午线为中心

Vectors layers use the view projection which unless specified is EPSG:3857 centered on the Greenwich meridian

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

You could try defining a spherical mercator centered on the dateline

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
  })

这篇关于在 Openlayers 中跨日期线包装 Geojson 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆