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
๊ฐ๋ ์! 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);
}
๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค!
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๊ธฐ๋ณธ google.maps.map ๊ฐ์ฒด๋ฅผ ํตํด ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค. ์ค์ Google ์ง๋ ๊ฐ์ฒด๋ฅผ ๊ฐ์ ธ์ค๋ ค๋ฉด
mapReady
์ด๋ฒคํธ๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ ์ด๋ฅผ ์ฒ๋ฆฌํ๋ ์ฝ๋์์ ํธ๋ํฝ ๊ณ์ธต์ ์ถ๊ฐํ ์ ์์ต๋๋ค. mapReady์ "์ด๋ฒคํธ"๋ ์ค์ Google ์ง๋ ์ธ์คํด์ค์ ๋๋ค.HTML
<agm-map (mapReady)="onMapReady($event)" ... plus any other attributes ...> ... </agm-map>
ํ์ ์คํฌ๋ฆฝํธ
Typescript ์ค๋ฅ๋ฅผ ๋ฐฉ์งํ๋ ค๋ฉด Google ์ง๋ ์ ํ ์ ์๋ฅผ ๊ฐ์ ธ์์ผ ํฉ๋๋ค.
import {} from '@types/googlemaps';
๋ค์์ ํตํด ์ค์นํ ์ ์์ต๋๋ค.
npm install --save @types/googlemaps