Leaflet: μž‘μ—… μ’…λ£Œ ν›„ 콜백이 μžˆλŠ” map.fitBounds

에 λ§Œλ“  2018λ…„ 11μ›” 28일  Β·  3μ½”λ©˜νŠΈ  Β·  좜처: Leaflet/Leaflet

map.fitBounds()κ°€ μž‘μ—…μ„ μ’…λ£Œν•  λ•Œλ§ˆλ‹€ μ½œλ°±μ„ μΆ”κ°€ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€. 였늘 μš°λ¦¬λŠ” map.once('zoomend moveend', function()); λ₯Ό μΆ”κ°€ν•˜λŠ” 것에 μ˜μ‘΄ν•΄μ•Ό ν•©λ‹ˆλ‹€.

예λ₯Ό λ“€μ–΄, λ§ˆμ»€κ°€ λ‚˜νƒ€λ‚œ ν›„ λ°”μš΄μŠ€λ˜λ„λ‘ ν•˜λ €λ©΄ λ‹€μŒμ„ μˆ˜ν–‰ν•΄μ•Ό ν•©λ‹ˆλ‹€.

var marker = getMarker();
map.once('zoomend moveend', ()=>{bounceMarker(marker);});
map.fitBounds(marker.getBounds());

λ‹€μŒκ³Ό 같이 ν•˜λ©΄ 쒋을 κ²ƒμž…λ‹ˆλ‹€.
map.fitBounds(marker.getBounds()).then(()=>{bounceMarker(marker);});

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

지도 μƒνƒœλ₯Ό μˆ˜μ •ν•˜λŠ” 지도 ν•¨μˆ˜κ°€ Promise λ°˜ν™˜ν•˜λ©΄ 쒋을 κ²ƒμž…λ‹ˆλ‹€.

λͺ¨λ“  3 λŒ“κΈ€

지도 μƒνƒœλ₯Ό μˆ˜μ •ν•˜λŠ” 지도 ν•¨μˆ˜κ°€ Promise λ°˜ν™˜ν•˜λ©΄ 쒋을 κ²ƒμž…λ‹ˆλ‹€.

λ‚΄κ°€ ν•œ 것은 λ‚΄ 지도에 λ©”μ„œλ“œλ₯Ό μΆ”κ°€ν•˜λŠ” κ²ƒμ΄μ—ˆμŠ΅λ‹ˆλ‹€(jquery 약속을 μ‚¬μš©ν•˜μ§€λ§Œ μ‰½κ²Œ λŒ€μ²΄ν•  수 있음).

zoomToBounds: function () {
  var promise = $.Deferred();
  this.once("moveend", function () {setTimeout(function () {promise.resolve();}, 20);});
  this.fitBounds.call(this, arguments);
  return promise;
}

$.Deferred() λ₯Ό new Promise() λŒ€μ²΄ν•œ λ‹€μŒ pull μš”μ²­μ„ 생성할 수 μžˆμŠ΅λ‹ˆκΉŒ?

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰