2013-09-29 2 views
5

현재 Javascript를 사용하여 고객 데이터의 대화식지도를 작성하는 첫 번째 실제 나가기 작업을하고 있습니다.Leaflet.js 및 JSON 데이터 : 최적화 및 성능

너무 근본적으로 작동하지만 성능이 떨어지기 시작하면 마커가있는 500 개의 poi 또는 원 마커가있는 10,000 개가됩니다. 누구나 내가 최적화 할 수있는 방법에 대한 조언을 제공 할 수 있다면 이미 json 데이터에 대해 mongo와 같은 적절한 DB로 이동하거나 Node Js와 함께 작업 서버 측을 수행하는 것이 가장 좋을까요?

어떤 조언을 많이 주시면 감사하겠습니다 :)

var apiKey = 'BC9A493B41014CAABB98F0471D759707', 
      styleID = '108219'; 
    // styleID = '997'; 


    // var map = L.map('map').setView([54.550, -4.433], 7); 

     var southWest = new L.LatLng(61.029031, 4.746094), 
      northEast = new L.LatLng(48.786962 ,-13.183594), 
      bounds  = new L.LatLngBounds(southWest, northEast); 

     var mapcenter  = new L.LatLng(53.457393,-2.900391); 
     var map   = new L.Map('map', 
           { 
            center: mapcenter, 
            zoom: 7, 
            // maxBounds: bounds, 
            zoomControl: false 
           }); 

     var cloudmadeUrl = generateTileURL(apiKey, styleID), 
      attribution = 'Map data © OpenStreetMap contributors.', 
      tileLayer = new L.TileLayer(
           cloudmadeUrl, 
           { 
            maxZoom: 18, 
            attribution: attribution, 
           }); 

      tileLayer.addTo(map); 

     var zoomControl  = new L.Control.Zoom({ position: 'topleft'}); 
      zoomControl.addTo(map); 
     var scaleControl = new L.Control.Scale({ position: 'bottomleft' }); 
      scaleControl.addTo(map); 




     geojsonLayer = L.geoJson(geojson, { 
      pointToLayer: function(feature, latlng) { 
      return new L.CircleMarker(latlng, {fillColor: feature.properties.MarkerColour, fillOpacity: 0.5, stroke: false, radius: 6}); 
      // return new L.Marker(latlng, {icon: L.AwesomeMarkers.icon({icon: feature.properties.MarkerIcon, color: feature.properties.MarkerColour, iconColor: 'white'}) }); 
      }, 
     onEachFeature: function (feature, layer) { 
      layer.bindPopup('<strong><b>Customer Data</b></strong><br />' + '<b>Result : </b>' + feature.properties.Result + '<br />' + '<b>Postcode : </b>' + feature.properties.Postcode + '<br />'); 
      } 
     }); 

      console.log('starting: ' + window.performance.now()); 

     map.addLayer(geojsonLayer); 

      console.log('ending: ' + window.performance.now()); 




    function generateTileURL(apiKey, styleID) { 
     return 'http://{s}.tile.cloudmade.com/' + apiKey + '/' + styleID + '/256/{z}/{x}/{y}.png'; 
    } 

일부 샘플 데이터 :

렌더링을 처리하는 데 도움 Leaflet plugins의 몇 가지 있습니다
{ 
    "type": "Feature", 
    "geometry": { 
     "type": "Point", 
     "coordinates": [ 
      -0.213467, 
      51.494815 
     ] 
    }, 
    "properties": { 
     "DateTime": "1372719435.39", 
     "Result": "Cable Serviceable", 
     "MarkerIcon": "ok-sign", 
     "MarkerColour": "green", 
     "Postcode": "W14 8UD"  
    } 
}, 
{ 
    "type": "Feature", 
    "geometry": { 
     "type": "Point", 
     "coordinates": [ 
      -0.389445, 
      51.512121 
     ] 
    }, 
    "properties": { 
     "DateTime": "1372719402.083", 
     "Result": "Refer for National Serviceability", 
     "MarkerIcon": "minus-sign", 
     "MarkerColour": "red", 
     "Postcode": "UB1 1NJ", 

    } 
}, 
{ 
    "type": "Feature", 
    "geometry": { 
     "type": "Point", 
     "coordinates": [ 
      -0.411291, 
      51.508012 
     ] 
    }, 
     "properties": { 
     "DateTime": "1372719375.725", 
     "Result": "Cable Serviceable", 
     "MarkerIcon": "ok-sign", 
     "MarkerColour": "green", 
     "Postcode": "UB3 3JJ" 
    } 
}, 
{ 
    "type": "Feature", 
    "geometry": { 
     "type": "Point", 
     "coordinates": [ 
      -2.11054, 
      53.500752 
     ] 
    }, 
    "properties": { 
     "DateTime": "1372719299.088", 
     "Result": "Cable Serviceable", 
     "MarkerIcon": "ok-sign", 
     "MarkerColour": "green", 
     "Postcode": "OL7 9LR", 

    } 
} 
+0

귀하의 병목 현상 데이터를 표시하는 데이터베이스 아니다 . 한 번에 500pois를 보거나 10,000 자 이상의 마커를 표시하는 것이 가장 좋은 방법입니까? 또는 귀하의 질문은 10000 개의 원 마커가 포함 된 정의 된 범위 내에서 데이터베이스 검색을 의미합니까? – Bernhard

+0

현재 데모 버전은 약 500 ~ 2500의 낮은 값을 처리하고 있습니다 ... 최종 버전은 한 번에 10,000 개 이상의 데이터 포인트를 표시 할 수 있어야합니다 ...이 문제는 그로 인해 발생한다고 생각합니다. 실시간으로 브라우저 측에서 렌더링을하고 있습니까? 정말 스케일링 문제를 해결할 수있는 다른 방법이 있는지 궁금합니다. – Guitaraholic

답변

7

클라이언트의 브라우저에서 많은 양의 점.

가장 간단한 방법은 Marker Clusterer과 같은 마커를 클러스터링하는 플러그인을 사용하는 것입니다. Clusterer는 클라이언트 측에서 렌더링을 돕습니다. 이는 클라이언트 컴퓨터가 10,000 포인트를 가져올 필요가 없으므로 10-40을 그립니다.

또한 히트 맵 할 수

- 그 두 가지 플러그인가 모두 HTML5 캔버스에 기반을 :

+3

markercluster 플러그인을 사용하고 있지만 여전히 포인트를 만들어야합니다. 점수를 얻기 위해 ipad에서 약 10 초 정도 걸릴 수 있습니다. – jelle

+0

나는 그 때 최선의 방법은 서버 쪽이라고 생각한다. 서버에서 클러스터링을 수행 한 다음 클러스터 지점을 단일 지점으로 장치에 보내 표시 할 수 있습니다. 그렇게하면 태블릿이나 전화 프로세서 대신 서버의 분석 기능을 활용할 수 있습니다. – Josh