Leaflet: ajaxλ₯Ό 톡해 νŒμ—… μ½˜ν…μΈ λ₯Ό μ±„μš°λŠ” 방법에 λŒ€ν•œ λ¬Έμ„œ

에 λ§Œλ“  2012λ…„ 08μ›” 27일  Β·  10μ½”λ©˜νŠΈ  Β·  좜처: Leaflet/Leaflet

클릭 μ‹œ 마컀 νŒμ—…μ˜ λ‚΄μš©μ„ μ±„μš°λŠ” 방법이 λ¬Έμ„œν™”λ˜μ–΄ μžˆμŠ΅λ‹ˆκΉŒ?

λ˜ν•œ ν‘œμ‹œλ˜λŠ” λͺ¨λ“  λ§ˆμ»€μ— λŒ€ν•œ νŒμ—… λ‚΄μš©μ„ μ±„μšΈ 수 μžˆμŠ΅λ‹ˆκΉŒ? λ‚˜λŠ” Leaflet.markerclusterλ₯Ό μ‚¬μš©ν•˜κ³  있으며 κ°œλ³„ 마컀λ₯Ό λ³Ό 수 μžˆμ„ 만큼 μΆ©λΆ„νžˆ ν™•λŒ€λ˜μ—ˆμ„ λ•Œ νŒμ—… λ‚΄μš©λ§Œ λ‘œλ“œν•˜λŠ” 것이 쒋을 κ²ƒμž…λ‹ˆλ‹€.

λ‚˜λŠ” jsλ₯Ό 잘 μ‚¬μš©ν•˜μ§€ λͺ»ν•˜κ³  λ‚΄ 검색에 아무 것도 λ‚˜μ˜€μ§€ μ•Šμ•˜μ§€λ§Œ λ‚΄κ°€ν•˜λ €λŠ” 일이 κ°€λŠ₯ν•˜λ‹€λŠ” λŠλ‚Œμ΄ λ“€μ—ˆμŠ΅λ‹ˆλ‹€ ... ?

λ‹€μ‹œ ν•œ 번 κ°μ‚¬ν•©λ‹ˆλ‹€!

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

이것은 Googleμ—μ„œ 잘 μ°Έμ‘°λ˜μ—ˆμœΌλ―€λ‘œ μ°ΎλŠ” μ‚¬λžŒλ“€μ„ μœ„ν•΄ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

  • μˆ˜λ™μœΌλ‘œ νŒμ—…μ„ λ§Œλ“€κ³  map.openPopup을 ν˜ΈμΆœν•  ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€. λ§ˆμ»€κ°€ μžˆλŠ” 경우 μ›ν•˜λŠ” 경우 bindPopup() 및 getPopup()을 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
  • popup.update() http://leafletjs.com/reference.html#popup -updateλ₯Ό ν˜ΈμΆœν•˜λŠ” 것을 μžŠμ§€ λ§ˆμ‹­μ‹œμ˜€.

λ‹€μŒμ€ 전단지 0.7.3을 μ‚¬μš©ν•œ μž‘μ—… μ˜ˆμž…λ‹ˆλ‹€.

var marker = L.marker([48.859085, 2.347403]);
marker.bindPopup("Loading...")
marker.on('click', function(e) {
    var popup = e.target.getPopup();
    var url="DYNAMIC_CONTENT_URL";
    $.get(url).done(function(data) {
        popup.setContent(data);
        popup.update();
    });

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

νŒμ—…μ„ λͺ…μ‹œμ μœΌλ‘œ μƒμ„±ν•˜λ©΄ λ‚΄μš©μ„ μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

var popup = new L.Popup();
popup.setLatLng(latlng);
popup.setContent('seme content');
map.openPopup(popup);

http://leaflet.cloudmade.com/reference.html#popup

λ”°λΌμ„œ λ§ˆμ»€μ—μ„œ '클릭' 이벀트λ₯Ό μˆ˜μ‹ ν•©λ‹ˆλ‹€(MarkerClusterGroupμ—μ„œ μ„€μ •ν•  수 있음). 그런 λ‹€μŒ 싀행될 λ•Œ λ‘œλ”© λ©”μ‹œμ§€κ°€ ν¬ν•¨λœ νŒμ—…μ„ λ§Œλ“€κ³  ajaxλ₯Ό 톡해 μ½˜ν…μΈ λ₯Ό λ‘œλ“œν•œ λ‹€μŒ λ‹€μ‹œ 올 λ•Œ 내뢀에 setContentλ₯Ό λ‘œλ“œν•©λ‹ˆλ‹€.

var group = new L.MarkerClusterGroup();
group.on('click', showMarker);

function showMarker(marker) {
//use marker.layer for the marker IIRC
//Create popup here and fetch content
}

도움이 되기λ₯Ό λ°”λžλ‹ˆλ‹€!

κ°μ‚¬ν•©λ‹ˆλ‹€ 이걸 κ³΅λΆ€ν•΄μ„œ κ΅¬ν˜„ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€!

이것은 Googleμ—μ„œ 잘 μ°Έμ‘°λ˜μ—ˆμœΌλ―€λ‘œ μ°ΎλŠ” μ‚¬λžŒλ“€μ„ μœ„ν•΄ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

  • μˆ˜λ™μœΌλ‘œ νŒμ—…μ„ λ§Œλ“€κ³  map.openPopup을 ν˜ΈμΆœν•  ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€. λ§ˆμ»€κ°€ μžˆλŠ” 경우 μ›ν•˜λŠ” 경우 bindPopup() 및 getPopup()을 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
  • popup.update() http://leafletjs.com/reference.html#popup -updateλ₯Ό ν˜ΈμΆœν•˜λŠ” 것을 μžŠμ§€ λ§ˆμ‹­μ‹œμ˜€.

λ‹€μŒμ€ 전단지 0.7.3을 μ‚¬μš©ν•œ μž‘μ—… μ˜ˆμž…λ‹ˆλ‹€.

var marker = L.marker([48.859085, 2.347403]);
marker.bindPopup("Loading...")
marker.on('click', function(e) {
    var popup = e.target.getPopup();
    var url="DYNAMIC_CONTENT_URL";
    $.get(url).done(function(data) {
        popup.setContent(data);
        popup.update();
    });

bindPopup() ν•¨μˆ˜λ₯Ό 전달할 μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. νŒμ—…μ΄ 열릴 λ•Œ 호좜되며 String λ˜λŠ” HTMLElement λ₯Ό λ°˜ν™˜ν•΄μ•Ό ν•©λ‹ˆλ‹€. λ”°λΌμ„œ λ‹€λ₯Έ λ²„μ „μ˜ μ½”λ“œ(νŒμ—…μ„ μ—΄κ²Œ ν•˜λŠ” 이벀트 μœ ν˜•μ„ μ§€μ •ν•˜μ§€ μ•ŠμŒ):

var marker = L.marker([48.859085, 2.347403]);
marker.bindPopup(function() {
    var el = $('<div/>');

    $.get("DYNAMIC_CONTENT_URL").done(function(data) {
        el.setContent(data);
        popup.update();
    });

    return el;
});

λˆ„κ΅¬λ“ μ§€ κ³΅μœ ν•  의ν–₯이 μžˆλŠ” μ‹€μ œ μž‘μ—… 사둀가 μžˆμŠ΅λ‹ˆκΉŒ?

μ—¬κΈ° ν”ŒλŸ°μ»€κ°€ μžˆμŠ΅λ‹ˆλ‹€-

http://plnkr.co/edit/ps1MNhUMMO7vZCnQN7Cg?p=preview

@chriszrc 덕뢄 에 λ§Žμ€ 문제λ₯Ό ν•΄κ²°ν–ˆμŠ΅λ‹ˆλ‹€. κ³ λ§ˆμ›Œμš”

@chriszrc API의 JSON 데이터λ₯Ό μ‚¬μš©ν•˜μ—¬ μˆ˜ν–‰ν•  수 μ—†μŠ΅λ‹ˆλ‹€.

νŒμ—…μ΄ ν‘œμ‹œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

μƒ˜ν”Œ λ°μ΄ν„°λŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.
{"datapoint":[{"intensity":92,"latitud":"18.52","longitud":"82.4767"},{"intensity":68,"latitud":"17.7375","longitud":"82.8347"}]}

νŒμ—…μ— 강도λ₯Ό ν‘œμ‹œν•˜λ €κ³  ν•©λ‹ˆλ‹€.

이것은 λ‚΄κ°€ μ‹œλ„ν•œ κ²ƒμž…λ‹ˆλ‹€ :

```
marker.bindPopup((νŒμ—…)=>{
var el = document.createElement('div');
el.classList.add("λ‚΄ 클래슀");
$.getJSON(" http://www.example.com/data ",function(datapoint){
el.innerHTML = '

' + 데이터 포인트[i].intensity + '

';
});
 return el;

@kunaldhariwal 예 μ—†μ΄λŠ” 말할 수 μ—†λŠ” plunkr λ˜λŠ” 무언가λ₯Ό κ²Œμ‹œν•΄μ•Ό ν•©λ‹ˆλ‹€. ν•˜μ§€λ§Œ μš°μ„  μ½”λ“œ 쑰각을 λ‘œλ“œν•˜λŠ” URL("http://www.example.com/data")이 μœ νš¨ν•œ json-

@chriszrc κ·Έλž˜λ„ μ˜ˆμ‹œ URLμž…λ‹ˆλ‹€. λͺ‡ 가지 λΆ„λͺ…ν•œ 이유둜 μ •ν™•ν•œ URL을 밝힐 수 μ—†μŠ΅λ‹ˆλ‹€.
μ£„μ†‘ν•˜μ§€λ§Œ μ–΄λ–»κ²Œλ“  μ•Œμ•„λ‚΄λ„λ‘ λ…Έλ ₯ν•˜κ² μŠ΅λ‹ˆλ‹€.

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