javascript - 超集群返回意外的经度值
问题描述
我正在使用 supercluster 包来计算要使用 React 版本的传单在地图上显示的集群。我尝试聚类的各个位置的纬度在 -34 到 -42 左右,经度值在 172 到 174 左右,但是计算出的集群虽然它们的纬度值似乎正确,但经度值在 5 到 7 左右。
集群与单个位置黑色图钉是集群,绿色图钉是其正确位置的剩余单个站点。
用于计算站点的代码:
const clusterer = new Supercluster<GeoJSONSiteProperties, {}>({ radius: 30 })
const geoJSONSites = sites.map(site => representSiteAsGeoJSON(site))
clusterer.load(geoJSONSites)
//The clusterer will determine which sites are far enough from others to display individually,
//and which should be put in a cluster represented by a pin on the map. Once it has done that
//sort the indidual sites and clusters and update the state to display them on the map. const newClusters: ClusterFeature<{}>[] = []
const newIndividualSites: ISite[] = []
clusterer.getClusters([-180, -85, 180, 85 ], mapZoomLevel).forEach((c: GeoJSONSite | ClusterFeature<{}>) =>{
if(c.properties.cluster){
newClusters.push(c as ClusterFeature<{}>)
}
else{
newIndividualSites.push(createSiteFromGeoJSONRepresentation(c as GeoJSONSite))
}
})
将站点与 geoJSON 相互转换的代码:
import { Feature, Point } from 'geojson';
import { ISite } from '../model/definitions/data_providers/ISitesProvider';
export type GeoJSONSiteProperties = Omit<ISite, "lat" | "lon"> & { cluster: false }
export type GeoJSONSite = Feature<Point, GeoJSONSiteProperties>
/**
* Create a representation of a site in the GeoJSON format.
* @param site
* @returns
*/
export function representSiteAsGeoJSON(site: ISite): GeoJSONSite {
return {
type: "Feature",
geometry: {
type: "Point",
coordinates: [ site.lat, site.lon ]
},
properties: {
cluster: false,
roadPositionString: site.roadPositionString,
postedSpeedLimit: site.postedSpeedLimit,
hasSampleImages: site.hasSampleImages,
stations: site.stations,
address: site.address
}
}
}
export function createSiteFromGeoJSONRepresentation(geojsonSite: GeoJSONSite): ISite{
return {
lat: geojsonSite.geometry.coordinates[0],
lon: geojsonSite.geometry.coordinates[1],
...geojsonSite.properties
}
}
有谁知道为什么会发生这种情况?
解决方案
推荐阅读
- nearprotocol - 交易/操作的气体限制是多少?
- c++ - 从 CMake 在 Eigen 中设置最大静态对齐
- excel - 如何使循环检查,总结单元格值并停在正确的位置
- c - c中的变量随机改变值
- racket - 如何在 Racket 中制作 HTML 表格边框
- vb.net - 如何计算已在 VB.NET 中的 datagridview 中检查的复选框
- microservices - jhipster 注册中心/控制中心向网关应用程序发送管理请求导致 401 未授权
- html - 为什么不使用填充作为显示?
- python - 我可以将 python 服务器与 kotlin 客户端连接起来吗?
- java - 我如何检测是否有人输入了错误的 otp