내가 여기에 넣은 코드는 다른 시스템에서 필사해야하는 것이므로 코드를 게시하는 쉬운 방법이 없습니다. 내가 있다면 전체 프로젝트를 게시 할 것입니다.
프로젝트에서 https://turfjs.org/docs/#nearestPoint 를 구현하려고 했지만 오류 메시지가 계속 나타납니다.
TS2345 : 'FeatureCollection <Geometry 유형의 인수 | GeometryCollection, {[이름 : 문자열] : 임의; }은 'FeatureCollection <Point, {[name : string] : any;}>'유형의 매개 변수에 할당 할 수 없습니다.
유형 Geometry는 Point 유형에 할당 할 수 없습니다. 속성 유형의 유형은 호환되지 않습니다. 유형 문자열은 Point 유형에 할당 할 수 없습니다.
나는이 게시물 turf.nearestPoint 가 게시물에서
map.on('click', function(e) {
var coord = e.latlng;
var lat = coord.lat;
var lng = coord.lng;
var targetPoint = turf.point([lng, lat]);
var nearest = turf.nearestPoint(targetPoint, points);
alert(JSON.stringify(nearest));
});
내 코드에서 나는
마우스 클릭 이벤트를 사용하여 turf.point ([lng, lat]}를 통해 selectPoint를 만듭니다.
동일한 turf.point ([lng, lat]) 접근 방식으로 생성 한 포인트 배열에서 포인트 생성
그러나 아무 소용이 없지만 항상 위에서 언급 한 TS 오류가 발생합니다.
또한 Turf 페이지의 문서에는 targetPoint가 Coord라고 나와 있지만 다른 포스터 코드에는 Feature 인 Turf.point가 있습니다.
인수
인수 ------ 유형 ------ 설명
targetPoint ---- Coord ----- 기준점
포인트 ------ FeatureCollection <Point> ------ 입력 포인트 세트에 대해
이것을 작동시키기 위해 8 시간 이상을 시도한 후에 나는 뽑을 머리카락이 남지 않았고 오늘 내가 한 모든 것을 의심하고 있습니다.
누군가가 실제로 작동하고 이미 기술에 익숙한 사람들만을위한 비밀스러운 의견이없는 무언가를 도와 주거나 저를 가리킬 수 있습니까?
이 문제로 어려움을 겪고있는 다른 사람들을 돕기 위해서입니다.
import * as Turf from '@turf/turf';
private handleClickEvent(e: Leaflet.LeafletEvent) {
const latLng: Leaflet.LatLng = e.latlng;
// Note in Turf it is backwards longitude, latitude where normally its lat, lng
let mapClickLocation: Feature<Point> = Turf.point( [latLng.lng, latLng.lat] );
let allYourGeoPoints: Array<Feature<Point>> = [];
// Values you'd set in the allYourGeoPoints e.g.
allYourGeoPoints.push(Turf.point([lng, lat], {'id': idOfYourRecord});
// Create a collection of points usable by Turf
let collectionOfPoints: FeatureCollection<Point> = Turf.featureCollection(allYourGeoPoints);
// Now find the nearest item
let nearestPointFound: NearestPoint = Turf.nearestPoint(mapClickLocation, collectionOfPoints);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다