Amazon Location에서 MapLibre 도구 및 라이브러리 사용 - Amazon Location Service

Amazon Location에서 MapLibre 도구 및 라이브러리 사용

Amazon Location을 사용하여 대화형 애플리케이션을 만드는 데 사용되는 중요한 도구 중 하나는 MapLibre입니다. MapLibre는 주로 웹 또는 모바일 애플리케이션에서 지도를 표시하기 위한 렌더링 엔진입니다. 하지만 플러그인에 대한 지원도 포함하며 Amazon Location의 다른 측면과 함께 작업할 수 있는 기능도 제공합니다. 다음은 작업하려는 위치 지역을 기반으로 사용할 수 있는 도구를 설명합니다.

참고

Amazon Location의 모든 측면을 사용하려면 사용하려는 언어의 AWSSDK를 설치하세요.

  • 애플리케이션에 지도를 표시하려면 Amazon Location에서 제공하는 데이터를 사용하고 화면에 그릴 맵 렌더링 엔진이 필요합니다. 맵 렌더링 엔진은 맵을 이동 및 확대하거나 마커, 푸시핀 및 기타 주석을 맵에 추가하는 기능도 제공합니다.

    Amazon Location Service에서는 MapLibre 렌더링 엔진을 사용하여 맵을 렌더링할 것을 권장합니다. MapLibre GL JS는 자바스크립트로 지도를 표시하는 엔진이며, MapLibre Native는 iOS 또는 안드로이드용 지도를 제공합니다.

    또한 MapLibre는 핵심 기능을 확장하기 위한 플러그인 에코시스템을 갖추고 있습니다. 자세한 내용은 https://maplibre.org/maplibre-gl-js-docs/plugins/을 참조하세요.

  • 장소 검색

    검색 사용자 인터페이스를 더 간단하게 만들려면 웹용 MapLibre 지오코더를 사용할 수 있습니다(Android 애플리케이션은 Android Places 플러그인을 사용할 수 있음).

    Amazon Location for Maplibre 지오코더 라이브러리를 사용하여 JavaScript 애플리케이션에서 amazon-location-for-maplibre-gl-geocoder와 함께 Amazon Location을 사용하는 프로세스를 간소화합니다.

  • 경로

    맵에 경로를 표시하려면 MapLibre 길찾기를 사용하세요.

  • 지오펜스 및 트래커

    MapLibre에는 지오펜스 및 추적을 위한 특정 렌더링 또는 도구가 없지만 렌더링 기능과 플러그인을 사용하여 지오펜스와 추적된 장치를 맵에 표시할 수 있습니다.

    추적 대상 디바이스는 MQTT를 사용하거나 Amazon Location Service에 업데이트를 수동으로 전송할 수 있습니다. AWS Lambda을 사용하여 지오펜스 이벤트에 응답할 수 있습니다.

Amazon Location Service에 추가 기능을 제공하는 데 사용할 수 있는 많은 오픈 소스 라이브러리(예: 공간 분석 기능을 제공하는 Turf)가 있습니다.

많은 라이브러리는 개방형 표준 GeoJSON 형식의 데이터를 사용합니다. Amazon Location Service는 자바스크립트 애플리케이션에서 GeoJSON을 사용할 수 있도록 지원하는 라이브러리를 제공합니다. 자세한 정보는 다음 섹션(Amazon Location SDK 및 라이브러리 사용 방법)을 참조하세요.

Amazon Location MapLibre 지오코더 플러그인

Amazon Location MapLibre 지오코더 플러그인은 maplibre-gl-geocoder 라이브러리를 사용하여 맵 렌더링 및 지오코딩 작업을 수행할 때 Amazon Location 기능을 JavaScript 애플리케이션에 더 쉽게 통합할 수 있도록 설계되었습니다.

설치

다음 명령을 사용하여 모듈에서 사용할 수 있도록 NPM에서 Amazon Location MapLibre 지오코더 플러그인을 설치할 수 있습니다.

npm install @aws/amazon-location-for-maplibre-gl-geocoder

스크립트를 사용하여 브라우저에서 직접 사용할 HTML 파일로 가져올 수 있습니다.

<script src="https://www.unpkg.com/@aws/amazon-location-for-maplibre-gl-geocoder@1">/script<
모듈 사용

이 코드는 Amazon Location 지오코딩 기능을 사용하여 Maplibre GL JavaScript 맵을 설정합니다. Amazon Cognito Identity Pool을 통한 인증을 사용하여 Amazon Location 리소스에 액세스합니다. 맵은 지정된 스타일 및 중앙 좌표로 렌더링되며 맵에서 위치를 검색할 수 있습니다.

// Import MapLibre GL JS import maplibregl from "maplibre-gl"; // Import from the AWS JavaScript SDK V3 import { LocationClient } from "@aws-sdk/client-location"; // Import the utility functions import { withIdentityPoolId } from "@aws/amazon-location-utilities-auth-helper"; // Import the AmazonLocationWithMaplibreGeocoder import { buildAmazonLocationMaplibreGeocoder, AmazonLocationMaplibreGeocoder } from "@aws/amazon-location-for-maplibre-gl-geocoder" const identityPoolId = "Identity Pool ID"; const mapName = "Map Name"; const region = "Region"; // region containing the Amazon Location resource const placeIndex = "PlaceIndexName" // Name of your places resource in your AWS Account. // Create an authentication helper instance using credentials from Amazon Cognito const authHelper = await withIdentityPoolId("Identity Pool ID"); const client = new LocationClient({ region: "Region", // Region containing Amazon Location resources ...authHelper.getLocationClientConfig(), // Configures the client to use credentials obtained via Amazon Cognito }); // Render the map const map = new maplibregl.Map({ container: "map", center: [-123.115898, 49.295868], zoom: 10, style: `https://maps.geo.${region}.amazonaws.com/maps/v0/maps/${mapName}/style-descriptor`, ...authHelper.getMapAuthenticationOptions(), }); // Gets an instance of the AmazonLocationMaplibreGeocoder Object. const amazonLocationMaplibreGeocoder = buildAmazonLocationMaplibreGeocoder(client, placeIndex, {enableAll: true}); // Now we can add the Geocoder to the map. map.addControl(amazonLocationMaplibreGeocoder.getPlacesGeocoder());
브라우저에서 사용

이 예제에서는 Amazon Location Client를 사용하여 Amazon Cognito를 사용하여 인증하는 요청을 작성합니다.

참고

이러한 예제 중 일부는 Amazon Location Client를 사용합니다. Amazon Location Client는 AWS SDK for JavaScript V3를 기반으로 하며 HTML 파일에 참조된 스크립트를 통해 Amazon Location에 직접적으로 호출할 수 있습니다.

HTML 파일에 다음 코드를 포함합니다.

< Import the Amazon Location With Maplibre Geocoder> <script src="https://www.unpkg.com/@aws/amazon-location-with-maplibre-geocoder@1"></script> <Import the Amazon Location Client> <script src="https://www.unpkg.com/@aws/amazon-location-client@1"></script> <!Import the utility library> <script src="https://www.unpkg.com/@aws/amazon-location-utilities-auth-helper@1"></script>

JavaScript 파일에 다음을 포함합니다.

const identityPoolId = "Identity Pool ID"; const mapName = "Map Name"; const region = "Region"; // region containing Amazon Location resource // Create an authentication helper instance using credentials from Amazon Cognito const authHelper = await amazonLocationAuthHelper.withIdentityPoolId(identityPoolId); // Render the map const map = new maplibregl.Map({ container: "map", center: [-123.115898, 49.295868], zoom: 10, style: `https://maps.geo.${region}.amazonaws.com/maps/v0/maps/${mapName}/style-descriptor`, ...authHelper.getMapAuthenticationOptions(), }); // Initialize the AmazonLocationMaplibreGeocoder object const amazonLocationMaplibreGeocoderObject = amazonLocationMaplibreGeocoder.buildAmazonLocationMaplibreGeocoder(client, placesName, {enableAll: true}); // Use the AmazonLocationWithMaplibreGeocoder object to add a geocoder to the map. map.addControl(amazonLocationMaplibreGeocoderObject.getPlacesGeocoder());

다음은 Amazon Location MapLibre 지오코더 플러그인에 사용되는 함수 및 명령입니다.

  • buildAmazonLocationMaplibreGeocoder

    이 클래스는 다른 모든 직접 호출의 진입점인 AmazonLocationMaplibreGeocder의 인스턴스를 생성합니다.

    const amazonLocationMaplibreGeocoder = buildAmazonLocationMaplibreGeocoder(client, placesIndex, {enableAll: true});
  • getPlacesGeocoder

    맵에 직접 추가할 수 있는 즉시 사용 가능한 IControl 객체를 반환합니다.

    const geocoder = getPlacesGeocoder(); // Initialize map let map = await initializeMap(); // Add the geocoder to the map. map.addControl(geocoder);