       lineWidth: 0
 
     sublayers.push
-      sql: "select * from #{args.table} where iso_3 = '#{tileConfig.iso3}'"
-      cartocss: @_addSelectedStyle args
+      sql: "SELECT * FROM #{args.table} WHERE iso_3 = '#{tileConfig.iso3}'"
+      cartocss: @_generateCartocss(args)
     sublayers
 
   addRegionTiles: (tileConfig, sublayers) ->
     args =
-      cartocss: ''
       table: 'continents'
       attrName: 'continent'
       attrVal: "'#{tileConfig.regionName}'"


    L.tileLayer('http://api.tiles.mapbox.com/v3/unepwcmc.ijh17499/{z}/{x}/{y}.png').addTo(@map)

  _addSelectedStyle: (args) ->
    opacity = if args.opacity? then args.opacity else .5
    lineWidth = if args.lineWidth? then args.lineWidth else 0.05
    args.cartocss += """
      ##{args.table}[#{args.attrName} = #{args.attrVal}]{
        line-color:#D41623;
        line-width:#{lineWidth};
        polygon-fill:#E43430;
        polygon-opacity:#{opacity};}
    """

  addSelectedWdpaTiles: (tileConfig, sublayers, idx) ->
    args =
      cartocss: sublayers[idx].cartocss
      table: 'wdpapoly_july2014_0'
      attrName: 'wdpaid'
      attrVal: tileConfig.wdpaId
    cartocss = @_addSelectedStyle args

    sublayers[idx].cartocss = cartocss
    sublayers

  addCountryTiles: (tileConfig, sublayers) ->
    args =
      cartocss: ''
      table: 'countries_geometries'
      attrName: 'iso_3'
      attrVal: "'#{tileConfig.iso3}'"

      lineWidth: 0

    sublayers.push
      sql: "SELECT * FROM #{args.table} WHERE continent = '#{tileConfig.regionName}'"
      cartocss: @_generateCartocss(args)
    sublayers

  addWdpaTiles: (tileConfig, sublayers) ->
    cartocss = [
      @_generateCartocss(
        table: ['wdpa_poly', 'wdpa_point']
        lineColor: '40541b'
        polygonFill: '83ad35'
      )
    ]

    if tileConfig.wdpaId?
      cartocss.push @_generateCartocss(
        table: ['wdpa_poly', 'wdpa_point']
        attrName: 'wdpaid'
        attrVal: tileConfig.wdpaId
      )

    sublayers.push
      sql: "SELECT the_geom FROM wdpa_point UNION ALL SELECT the_geom FROM wdpa_poly"
      cartocss: cartocss.join("\n")
    sublayers

  addCartodbTiles: (tileConfig) ->
    sublayers = []

    @addWdpaTiles(tileConfig, sublayers)

    if tileConfig.iso3?
      sublayers = @addCountryTiles tileConfig, sublayers
    if tileConfig.regionName?
      sublayers = @addRegionTiles tileConfig, sublayers

    carto_tiles = new cartodb.Tiles(
      sublayers: sublayers
      user_name: "carbon-tool"
    )

    carto_tiles.getTiles( (o) =>
      L.tileLayer(o.tiles[0]).addTo @map
    )
