【问题标题】:relevant hexids inside a hexagon六边形内的相关六边形
【发布时间】:2019-08-20 10:57:31
【问题描述】:

我正在通过“h3.geoToH3(lng, lat, res)”生成一组十六进制 ID。 之后我通过“让多边形= geojson2h3.h3SetToFeatureCollection(hexIds)”创建一个FeatureCollection 当我单击地图上的六边形时,我只想要启动的六边形内相关六边形的 ID。 我怎样才能以高效的方式做到这一点?

getHexIds = (res) => {
        let hexIds = this.props.stations.features.map(element => {
            const [lng, lat] = element.geometry.coordinates;
            const hexId = h3.geoToH3(lng, lat, res);
            return hexId;
        })

        let polygons = geojson2h3.h3SetToFeatureCollection(hexIds);

        this.setState({
            polygons: polygons
        }, () => {
            this.geoJsonLayer.current.leafletElement.clearLayers().addData(this.state.polygons);
        })

        // console.info(this.state.polygons, res);
    }
onEachFeature = (feature, layer) => {
        layer.on('click', (e) => {
          // show the relevant hexids
        }) 
    }

【问题讨论】:

    标签: h3


    【解决方案1】:

    如果我正确理解了这个问题,这可能与您的地图库(可能是 Leaflet)有关,而不是 H3,但这里有一些通用方法:

      1234563这非常快,并且重新计算比存储和查找要容易得多。
    • 如果您想获得与点击点相关联的 H3 索引的(即您有多个功能,每个功能由多个 H3 索引组成),那么您通常想要构建像{[h3Index]: h3Set} 这样的反向索引。然后您可以使用h3.geoToH3 查找点击点处的索引,并在您的反向索引中查找该集合。

    • 如果您的地图在点击时没有提供纬度/经度,您可以使用 viewport-mercator-project 之类的库从点击的 x/y 屏幕坐标中找到纬度/经度(在 DOM 上可用事件)。

    【讨论】:

      猜你喜欢
      • 2015-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      相关资源
      最近更新 更多