         'http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
         attribution: '(c) Esri')
 
-      markerLayer = L.featureGroup()
+      categoryMap =
+        "functional" : 0
+        "not functional" : 1
+        "needs repair" : 2
+
+      if clustering
+        markerLayer = new PruneClusterForLeaflet()
+        markerLayer.Cluster.Size = 100
+        markerLayer.PrepareLeafletMarker = (leafletMarker, data) ->
+          if leafletMarker.getPopup()
+            leafletMarker.setPopupContent data
+          else
+            leafletMarker.bindPopup data
+      else
+        markerLayer = L.featureGroup()
 
       map = L.map id,
         center: new L.LatLng -6.3153, 35.15625

        html = '<div class="popup">' + header + fields + '</div>'

      @clearMarkers = () ->
        markerLayer.clearLayers()

      @addWaterpoint = (wp, popup) ->
        [lng,lat] = wp.location.coordinates
        m = L.marker L.latLng(lat,lng),
          stroke: false
          opacity: 0.8
          fillColor: statusColor(wp.status_group)
        if popup
          m.bindPopup popup

        markerLayer.addLayer(m)

      @zoomToMarkers = () ->
        bounds = markerLayer.getBounds()
        if bounds.isValid()
          map.fitBounds(bounds)

      return this


    ApiResource 'services'

  .factory 'Map', ($filter) ->
    (id, clustering) =>
      osmLayer = L.tileLayer(
        'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
        attribution: '(c) OpenStreetMap')
