Angular-google-maps: ํŠธ๋ž˜ํ”ฝ ๋ ˆ์ด์–ด ํ‘œ์‹œ

์— ๋งŒ๋“  2018๋…„ 05์›” 16์ผ  ยท  4์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: SebastianM/angular-google-maps

AGM MAP angular2์—์„œ ํŠธ๋ž˜ํ”ฝ ๋ ˆ์ด์–ด๋ฅผ ์–ด๋–ป๊ฒŒ ํ‘œ์‹œํ•ฉ๋‹ˆ๊นŒ?

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๊ธฐ๋ณธ google.maps.map ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์‹ค์ œ Google ์ง€๋„ ๊ฐœ์ฒด๋ฅผ ๊ฐ€์ ธ์˜ค๋ ค๋ฉด mapReady ์ด๋ฒคํŠธ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์ด๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์ฝ”๋“œ์—์„œ ํŠธ๋ž˜ํ”ฝ ๊ณ„์ธต์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. mapReady์˜ "์ด๋ฒคํŠธ"๋Š” ์‹ค์ œ Google ์ง€๋„ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค.

HTML
<agm-map (mapReady)="onMapReady($event)" ... plus any other attributes ...> ... </agm-map>

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ

onMapReady(mapInstance) {
    let trafficLayer = new google.maps.TrafficLayer();
    trafficLayer.setMap(mapInstance);
}

Typescript ์˜ค๋ฅ˜๋ฅผ ๋ฐฉ์ง€ํ•˜๋ ค๋ฉด Google ์ง€๋„ ์œ ํ˜• ์ •์˜๋ฅผ ๊ฐ€์ ธ์™€์•ผ ํ•ฉ๋‹ˆ๋‹ค.
import {} from '@types/googlemaps';
๋‹ค์Œ์„ ํ†ตํ•ด ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
npm install --save @types/googlemaps

๋ชจ๋“  4 ๋Œ“๊ธ€

๊ธฐ๋ณธ google.maps.map ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์‹ค์ œ Google ์ง€๋„ ๊ฐœ์ฒด๋ฅผ ๊ฐ€์ ธ์˜ค๋ ค๋ฉด mapReady ์ด๋ฒคํŠธ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์ด๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์ฝ”๋“œ์—์„œ ํŠธ๋ž˜ํ”ฝ ๊ณ„์ธต์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. mapReady์˜ "์ด๋ฒคํŠธ"๋Š” ์‹ค์ œ Google ์ง€๋„ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค.

HTML
<agm-map (mapReady)="onMapReady($event)" ... plus any other attributes ...> ... </agm-map>

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ

onMapReady(mapInstance) {
    let trafficLayer = new google.maps.TrafficLayer();
    trafficLayer.setMap(mapInstance);
}

Typescript ์˜ค๋ฅ˜๋ฅผ ๋ฐฉ์ง€ํ•˜๋ ค๋ฉด Google ์ง€๋„ ์œ ํ˜• ์ •์˜๋ฅผ ๊ฐ€์ ธ์™€์•ผ ํ•ฉ๋‹ˆ๋‹ค.
import {} from '@types/googlemaps';
๋‹ค์Œ์„ ํ†ตํ•ด ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
npm install --save @types/googlemaps

๊ฐ๋…์ž! ziftytodd๋‹˜, ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋‚˜์—๊ฒŒ google ๊ฐ์ฒด๋Š” angular-cli ๊ธฐ๋ฐ˜ ํ”„๋กœ์ ํŠธ์—์„œ ์ •์˜๋˜์ง€ ์•Š์•˜์œผ๋ฏ€๋กœ window.google.maps.TrafficLayer() ๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ฐธ์กฐํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค.

@ziftytodd ํ•ด๊ฒฐํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ €์—๊ฒŒ ์ •๋ง ๋„์›€์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค์—๊ฒŒ๋„ ๋„์›€์ด ๋  ์ˆ˜ ์žˆ๋Š” ๋ช‡ ๊ฐ€์ง€ ์กฐ์ •์„ ํ•ด์•ผ ํ–ˆ์ง€๋งŒ.

1 - npm install --save @types/googlemaps
2 - ๊ธฐ๋ณธ ๊ฒฝ๋กœ์— index.d.ts ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  declare module 'googlemaps'; ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
3 - ํƒ€์ดํ”„์Šคํฌ๋ฆฝํŠธ์—์„œ ๊ฐ€์ ธ์˜ค๊ธฐ: import {} from 'googlemaps';
4 - HTML ํŒŒ์ผ: <agm-map (mapReady)="onMapReady($event)" ... plus any other attributes ...> ... </agm-map>
5 - ํƒ€์ดํ”„์Šคํฌ๋ฆฝํŠธ์—์„œ:

onMapReady($event) {
let trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap($event);
}

๋„์›€์ด ๋˜๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค!

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰