@SebastianM ๋ฌธ์์ ์ถ๊ฐ๋ฅผ ์ฌ์ฉํ์ฌ ๊ฒฝ๊ณ๋ฅผ
์ด fitbound ๊ธฐ๋ฅ๋ ์ฌ์ฉํ๊ธฐ ์ํด ๋ง์ปค์์ ๊ฒฝ๊ณ๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์ถ์ต๋๋ค. ๋๋ angular 2 ๋ฐ์ธ๋ฉ์ ์ฌ์ฉํ๊ณ sebm-google-map-marker์ fitBounds ์์ฑ์ ๋ด bounds ๋ณ์์ ๋งคํํ ์ ์๋๋ก bound.exists ํจ์์ ์ ๋ฌํ LatLng ๊ฐ์ฒด๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ์ ํ์ ์ ์ ์์์ต๋๋ค.
@suleymanozev -- LatLng ๊ฐ์ฒด๋ฅผ ์์ฑํ ์ ์๋ ํ fitbounds๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์์ต๋๋ค. ํจ๊ป ์์
ํ์๊ฒ ์ต๋๊น?
์์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฅ์น ๋ฐ์ดํฐ๋ฅผ ๋ฐ๋ณตํ๊ณ ์์ ์ ์ ํฉํ์ง ์๊ธฐ ๋๋ฌธ์ ์์ชฝ, ๋์ชฝ, ๋ถ์ชฝ ๋ฐ ๋จ์ชฝ ์ฌ์ด์ ํ๊ท ์ ์ฌ์ฉํ์ฌ ์๋์ผ๋ก ์ค์ฌ์ ์ ๊ณ์ฐํ๋ ๊ฒ์ ๋๋ค. ๋ถ๋ช ํ ์ด ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ฉด ์ค์ฌ์ ์ฌ๋ฐ๋ฅด๊ฒ ์ป์ ์ ์์ง๋ง ํ๋/์ถ์ ์์ค์ด ์ฌ๋ฐ๋ฅด์ง ์์ ๊ฒ์ ๋๋ค.
west = devicedata[0].Long;
east = devicedata[0].Long;
north = devicedata[0].Lat;
south = devicedata[0].Lat;
for(let dev of this.devicedata) {
if(west > dev.Long){
west = dev.Long
}
if(east < dev.Long){
east = dev.Long
}
if( north < dev.Lat){
north = dev.Lat
}
if( south > dev.Lat){
south = dev.Lat
}
}
this.center.lat = (north + south)/2;
this.center.lng = (east + west)/2;
์
๋ฐ์ดํธ
LatLngBoundsLiteral์ ์ฌ์ฉํ๊ธฐ๋ก ๊ฒฐ์ ํ๊ณ ๊ณ์ฐ๋ ๋์ชฝ, ์์ชฝ, ๋ถ์ชฝ, ๋จ์ชฝ์ ์ง์ ๋งคํํ์ผ๋ฉฐ ์๋ํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
var offset = 0.25;
this.boundsl = <LatLngBoundsLiteral>{west: west - offset, north: north + offset, south: south - offset, east: east + offset};
๊ทธ๋ฐ ๋ค์ HTML ์ฝ๋
<sebm-google-map #mygmap [latitude]="center.lat" [longitude]="center.lng" usePanning="true" [fitBounds]="boundsl">
๋ค์ ํจ์๋ฅผ ์ฌ์ฉํ์ฌ LatLngBounds๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.
import { MapsAPILoader } from 'angular2-google-maps/core';
constructor(private mapsAPILoader:MapsAPILoader) {}
this.mapsAPILoader.load().then(() => {let latlngbounds = new google.maps.LatLngBounds();})
์ค์ํ ๋ถ๋ถ์ ์ด ์ด๋ฒคํธ๊ฐ ์์๋๊ธฐ ์ ์ google.maps ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์ angular2-google-maps์ MapsApiLoader์ ๋๋ค.
์ฌ๋ฌ๋ถ, @SebastianM์์ ์ด ์ปค๋ฐ์ ๋ณด์์ต๋๋ค. https://github.com/SebastianM/angular2-google-maps/commit/d625ab6796768d167d7a0f9f2b9a504fce8a2bea
๊ทธ๊ฐ ์ด๋ฏธ fitbounds ์์ฑ์ ์ ๊ฑฐํ ๊ฒ ๊ฐ์ต๋๋ค. ๋์ ์๋์ ๊ฒฝ๋๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๊น?
AngularJS์์ ์ฌ์ฉํ๋ฉด์ ๊ฒฝ๊ณ๋ฅผ ์์ฑํ ๋ค์ ๊ฒฝ๊ณ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ค์ฌ ์๋์ ๊ฒฝ๋๋ฅผ ๊ณ์ฐํ์ต๋๋ค. ํ๋/์ถ์ ์์ค๊ณผ ๊ฐ์ด ์ฒ๋ฆฌํด์ผ ํ ๋ช ๊ฐ์ง ์ฌํญ์ด ๋ ์์ต๋๋ค.
๋ถ๋ค์๊ฒ ๋์์ด ๋ ์ ์์ต๋๋ค.
generateBounds(markers): any {
if (markers && markers.length > 0) {
var bounds = new google.maps.LatLngBounds();
markers.forEach((marker: any) => {
bounds.extend(new google.maps.LatLng({ lat: marker.latitude, lng: marker.longitude }));
});
//check if there is only one marker
if (bounds.getNorthEast().equals(bounds.getSouthWest())) {
var extendPoint = new google.maps.LatLng(bounds.getNorthEast().lat() + 0.01, bounds.getNorthEast().lng() + 0.01);
bounds.extend(extendPoint);
}
return {
northeast: {
latitude: bounds.getNorthEast().lat(),
longitude: bounds.getNorthEast().lng()
},
southwest: {
latitude: bounds.getSouthWest().lat(),
longitude: bounds.getSouthWest().lng()
}
}
}
//return empty object when no bundle selected
return {};
}
this.bounds = this.generateBounds(this.bundleMarkers)
this.lat = (this.bounds.northeast.latitude + this.bounds.southwest.latitude) / 2;
this.lng = (this.bounds.northeast.longitude + this.bounds.southwest.longitude) / 2;
<sebm-google-map [latitude]="lat" [longitude]="lng">
<sebm-google-map-marker
*ngFor="let marker of bundleMarkers"
[latitude]="marker.latitude"
[longitude]="marker.longitude"
[label]="marker.label"
[title]="marker.title">
</sebm-google-map-marker>
</sebm-google-map>
์๋
ํ์ธ์, ์ด lib๋ฅผ ์ฌ์ฉํ๊ธฐ ์์ํ๋๋ฐ ๋๋์ต๋๋ค. ๋ง์ปค๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ง๋๋ฅผ ์ค์์ ๋ฐฐ์นํ๋ ค๊ณ ํ๋๋ฐ ์ ์ด๋ ๊ฒ ์ด๋ ต๊ฒ ๋ง๋๋์ง ์ดํด๊ฐ ๋์ง ์์ต๋๋ค...
๋ง์ปค๋ฅผ ์ ์ธํ๊ณ ๋ง์ปค๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ง๋๋ฅผ ์ค์์ ๋ฐฐ์นํ๋ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ ์์ฑํ์ต๋๋ค.
getCenterMarkers(): ๋ฌดํจ{
let lat: number = 0;
let lng: number = 0;
this.markers.forEach(marker => {
lat += marker.lat;
lng += marker.lng;
});
this.center.lat = lat/this.markers.length;
this.center.lng = lng/this.markers.length;
}
@VinceEeckhout ์ด๊ฒ ์ ์ด๋ ๊ฒ ์ด๋ ต๊ฒ ๋ง๋ค์ด์ก๋์ง ์ดํด๊ฐ
์ค์ฌ์ ์ก๋ ๊ฒ์ ๊ด์ฐฎ์ง๋ง 'ํ๋' ์์ค์ ์ด๋ป์ต๋๊น? ์ด๊ฒ์ด LatBounds๊ฐ ํ์ํ ๊ณณ์ด๋ฉฐ ๋๋ ์ฌ์ ํ ์ด๊ฒ์ ๊ตฌํํ๋ ์ ์ ํ ๋ฐฉ๋ฒ์ ์ฐพ์์ผ ํฉ๋๋ค.
import {MapsAPILoader} from 'angular2-google-maps/core';
constructor(private mapsAPILoader: MapsAPILoader) {
this.mapsAPILoader.load().then(() => {
**this.latlngBounds = new window['google'].maps.LatLngBounds();**
this.measurement.locations.forEach((location) => {
this.latlngBounds.extend(new window['google'].maps.LatLng(location.lat, location.lng))
})
}
)
)
<sebm-google-map
[latitude]="lat"
[longitude]="lng"
[zoomControl]="false"
[disableDefaultUI]="true"
[streetViewControl]="false"
[mapDraggable]="false"
**[fitBounds]="latlngBounds"**
[scrollwheel]="false">
<sebm-google-map-marker
*ngFor="let location of measurement.locations"
[latitude]="location.lat"
[longitude]="location.lng">
</sebm-google-map-marker>
</sebm-google-map>
@trungk18 ์ง๋ ์ค์์ ์๋ ๋ชจ๋ ๋ง์ปค๋ฅผ ๋ณด๊ธฐ ์ํด ์ถ์ ๋๋ ํ๋ํ๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น?
@Jonatthu ์ค๋ซ๋์ ์ฌ์ฉํ์ง ์์์ง๋ง ์์ generateBounds ๊ธฐ๋ฅ์ ์ฌ์ฉํด
@trungk18 ์, ์๋ํ์ง๋ง ์ฌ์ฉ์๊ฐ ๋ง์ง๋ง์ผ๋ก ์ ์ฉํ ํ๋/์ถ์๋ฅผ ์ ์งํ๋ ๊ฒ ๊ฐ์ต๋๋ค
@tscislo ์์ฑ์๋ ํฌํจํ ์ ์์ต๋๊น?
ILocation์ ์ด๋์์ ์ฐพ์ ์ ์์ต๋๊น? ์ธก์ ์ ํ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
@angular/common์์๋ง ์์น๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.
@Jonatthu ๋ sebm ์ปจํ ์ด๋๋ฅผ ๋ณด๋ฉด 'scrollwheel=false'๋ผ๊ณ ๋์ด ์์ต๋๋ค. ํ๋ํ๊ฑฐ๋ ์ถ์ํ ์ ์๋ ๊ฒ์ ๋น์ฐํฉ๋๋ค.
๊ทธ๋ฆฌ๊ณ ์ด๊ธฐ latbounds ์ดํ์ ๋ฌด์ธ๊ฐ๋ฅผ ๋ณ๊ฒฝํ๋ฉด latlngbounds๋ฅผ ์ฌ์ค์ ํ๊ธฐ ์ํด ํ๋/์ถ์ ์์ค์ ๋ค์ ํ ๋นํด์ผ ํฉ๋๋ค.
@tscislo ๋ ๊ทธ๊ฒ์ ์ํ๊ณ ๋๋ ๊ทธ๊ฒ์ ์๋์ํฌ ์์์์ต๋๋ค. ๊ทธ๋ ๋ค๋ฅธ ๋ณ์๋ฅผ ์ฌ์ฉํ์ง๋ง ๋ชจ๋ ํ๋ก๊ทธ๋๋จธ๊ฐ ์์๋ผ ์ ์์ต๋๋ค.
๋๋ ๊ทธ๊ฒ์ ๋ค์๊ณผ ๊ฐ์ด ํ๋ค:
import { MapsAPILoader } from 'angular2-google-maps/core';
latlngBounds;
constructor(
...
private mapsAPILoader: MapsAPILoader
) { };
this.mapsAPILoader.load().then(() => {
this.latlngBounds = new window['google'].maps.LatLngBounds();
this.markers.forEach((location) => {
this.latlngBounds.extend(new window['google'].maps.LatLng(location.lat, location.lng))
})
});
md5-3b89998d3378d7952a828cbdec3a9606
<sebm-google-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" [disableDefaultUI]="false" [zoomControl]="false" (mapClick)="mapClicked($event)" [streetViewControl]="false" [fitBounds]="latlngBounds" class="content-map"> </sebm-google-map>
@Ccanny ์ง๋์ ์คํ์ ์ ๋ฃ์ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
@VinceEeckhout
๋ด ์์ ๋ฅผ ์
๋ฐ์ดํธํ๊ณ ์ ํ ํ์ํ์ง ์์ ์ฌ์ฉ์ ์ง์ ILocation ์ธํฐํ์ด์ค๋ฅผ ์ ๊ฑฐํ์ต๋๋ค. ๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค!
@tscislo ๋์ ๊ฐ์ฌํฉ๋๋ค ๐
@Ccanny ๋์ ๊ฐ์ฌํฉ๋๋ค ๐
@Ccanny๋ ๊ณผ @tscislo๋ ์๋
ํ์ธ์. Observable ์์ ๊ฐ์ ๊ฒ์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์
๋๋ค. ์์ ์์
์ ์ํํ๋ฉด ๋ ๋ค๋ฅธ ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค. params๋ฅผ ๋ค์ ์ ๋ฌํ ํ(์ฅ์ ๋ชฉ๋ก์ผ๋ก ํ์ด์ง๋ฅผ ๋ค์ ๋ ๋๋ง) this.marker๊ฐ ์ ์๋์ง ์์ ์ค๋ฅ๋ฅผ ํ์ํฉ๋๋ค. ๋ค๋ฅธ ๋ฐฉ๋ฒ์ด ์์ต๋๊น? ๋ต๋ณ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
NgZone์ ์ฌ์ฉํ๋ฉด ์ด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๋ค. ๊ทธ๋ ๋ค๋ฉด ์ด ์ฝ๋์์ Ngzone์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ.
์ด๊ฒ์ด ์ด๋ป๊ฒ ๋ซํ๋์ง, ๋ฌธ์๋ ์์ง API ๋ฌธ์์ ์ถ๊ฐ๋์ง ์์์ต๋๋ค.
@tscislo ๊ทํ์ ์๋ ์ด๋์
@samtidbit 1์ 23์ผ ๋ด ์๊ฒฌ ์์์ ๋ด์ฃผ์ธ์
์, ๋ค๋ฅธ ์์ ํ์ ๊ฐ์ ธ์์ผ ํ๋ ํดํน์ด ์๋ ์ค์ ์๊ฐ ์์ต๋๊น?
@tscislo , ์ ์๋ํฉ๋๋ค. ์ ๋ณด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ