anchor.diff:    return atlasState.placeLayers[p.id];
   };
   
  -atlasJS.updateMetadataPanel = function( ) {
  +atlasJS.updateMetadataPanel = function ( ) {
     $( ".panel" ).remove();
  -  panel = $( "#right" );
  +  var panel = $( "#right" );
     panel.html( "" );
  -  listings_panel = $( "#bottomright" );
  -  listings_panel.html( "" );
  -  var parentWasNotExploded;
  -  _.each( atlasState.selectedPlaces, function( p ) {
  +  var listingsPanel = $( "#bottomright" );
  +  listingsPanel.html( "" );
  +  _.each( atlasState.selectedPlaces, function ( p ) {
       atlasJS.appendPlaceMetadata( panel, p );
  -  });
  -};
  -
  -atlasJS.appendPlaceMetadata = function( panel, place ) {
  +  } );
  +};
  +
  +atlasJS.appendPlaceMetadata = function ( panel, place ) {
     var existing = atlasState.placeLayers[place.id];
     var placeName = place.display_name || place.name;
     panel.append( $( "<h2>" ).text( placeName ) );
  -  if( !existing || ( ( existing.type != "native" && existing.type != "introduced") && existing.type != "exploded" ) ) {
  -    var addPlaceLink = $( "<a href='#'>" ).text( "Add this place" );
  -    addPlaceLink.on( "click", function( e ) {
  +  var addPlaceLink;
  +  if ( !existing || (
  +    ( existing.type !== "native" && existing.type !== "introduced" ) && existing.type !== "exploded"
  +  ) ) {
  +    addPlaceLink = $( "<a href='#'>" ).text( "Add this place" );
  +    addPlaceLink.on( "click", function ( e ) {
         e.preventDefault( );
         atlasJS.alterAtlas( place );
  -    });
  +    } );
       panel.append( addPlaceLink );
       panel.append( "<br>" );
     }
  -  if( existing && ( existing.type == "native" || existing.type == "introduced") ) {
  -    var addPlaceLink = $( "<a href='#'>" ).text( "Remove this place" );
  -    addPlaceLink.on( "click", function( e ) {
  +  if ( existing && ( existing.type === "native" || existing.type === "introduced" ) ) {
  +    addPlaceLink = $( "<a href='#'>" ).text( "Remove this place" );
  +    addPlaceLink.on( "click", function ( e ) {
         e.preventDefault( );
  -      var confirmText = "This will destroy all the listed taxa that are of this taxon (or any descendants)" + 
  -          " for this place (or any standard descendants). This can be very destructive, are you sure?";
  -      if(confirm(confirmText)) {
  +      var confirmText = "This will destroy all the listed taxa that are of this taxon (or any descendants)"
  +        + " for this place (or any standard descendants). This can be very destructive, are you sure?";
  +      if ( confirm( confirmText ) ) {
           atlasJS.alterAtlas( place );
         }
  -    });
  +    } );
       panel.append( addPlaceLink );
       panel.append( "<br>" );
  -    
  -    var addPlaceLink = $( "<a href='#'>" ).text( "Show listed taxa" );
  -    addPlaceLink.on( "click", function( e ) {
  +
  +    addPlaceLink = $( "<a href='#'>" ).text( "Show listed taxa" );
  +    addPlaceLink.on( "click", function ( e ) {
         e.preventDefault( );
         atlasJS.getListings( place );
  -    });
  +    } );
       panel.append( addPlaceLink );
       panel.append( "<br>" );
     }
  -  if( !existing || ( existing.type != "exploded"  && existing.place.admin_level < 20 ) ) {
  +  if ( !existing || ( existing.type !== "exploded" && existing.place.admin_level < <%= Place::COUNTY_LEVEL %> ) ) {
       var explodeLink = $( "<a href='#'>" ).text( "Explode this place" );
  -    explodeLink.on( "click", function( e ) {
  +    explodeLink.on( "click", function ( e ) {
         e.preventDefault( );
         atlasJS.explodePlace( place );
  -    });
  +    } );
       panel.append( explodeLink );
       panel.append( "<br>" );
     }
  -  if( existing && existing.type == "exploded" ) {
  +  if ( existing && existing.type === "exploded" ) {
       var unexplodeLink = $( "<a href='#'>" ).text( "Unexplode this place" );
  -    unexplodeLink.on( "click", function( e ) {
  +    unexplodeLink.on( "click", function ( e ) {
         e.preventDefault( );
         atlasJS.unexplodePlace( place );
  -    });
  +    } );
       panel.append( unexplodeLink );
       panel.append( "<br>" );
     }
  -}
  -
  -atlasJS.bestPlaceForLatLng = function( lat, lng, callback ) {
  +};
  +
  +atlasJS.bestPlaceForLatLng = function ( lat, lng ) {
     atlasJS.removeActivePlaceLayer( );
  -  atlasState.selectedPlaces = [ ];
  -  $.ajax({
  +  atlasState.selectedPlaces = [];
  +  $.ajax( {
       dataType: "json",
       url: "<%= CONFIG.node_api_url %>/places/containing?lat=" + lat + "&lng=" + lng,
  -    success: function( r ) {
  -      var selectedPlaces = [ ];
  +    success: function ( r ) {
  +      var selectedPlaces = [];
         var parentWasNotExploded;
  -      _.each( r.results, function( p ) {
  -        if( !p || !p.geometry_geojson ) { return; }
  -        if( parentWasNotExploded ) { return; }
  +      _.each( r.results, function ( p ) {
  +        if ( !p || !p.geometry_geojson ) { return; }
  +        if ( parentWasNotExploded ) { return; }
           selectedPlaces.push( p );
           var existing = atlasState.placeLayers[p.id];
  -        parentWasNotExploded = !( existing && existing.type == "exploded" );
  -      });
  -      if( selectedPlaces.length == 0 ) { return; }
  +        parentWasNotExploded = !( existing && existing.type === "exploded" );
  +      } );
  +      if ( selectedPlaces.length === 0 ) { return; }
         atlasState.activePlaceLayer = atlasJS.addPlaceToMap(
  -        _.last( selectedPlaces ), null, { selected: true } );
  +        _.last( selectedPlaces ), null, { selected: true }
  +      );
         atlasState.selectedPlaces = selectedPlaces;
         atlasJS.updateMetadataPanel( );
       }
  -  });
  -};
  -
  -atlasJS.addrefreshedPlaces = function( place_hash ) {
  -  var refreshedPlaceIDs = $.map( place_hash, function(v, i){
  -    if( !Object.keys(atlasState.placeLayers).includes(i) || 
  -      ( atlasState.placeLayers[i]["type"] != "native" && 
  -      atlasState.placeLayers[i]["type"] != "introduced" ) ) { return i; }
  -  });
  -  if( refreshedPlaceIDs.length > 0 ) {
  -    $.ajax({
  +  } );
  +};
  +
  +atlasJS.addrefreshedPlaces = function ( placeHash ) {
  +  var refreshedPlaceIDs = $.map( placeHash, function ( v, i ) {
  +    if ( !Object.keys( atlasState.placeLayers ).includes( i ) || (
  +      atlasState.placeLayers[i].type !== "native"
  +        && atlasState.placeLayers[i].type !== "introduced"
  +    ) ) {
  +      return i;
  +    }
  +  } );
  +  if ( refreshedPlaceIDs.length > 0 ) {
  +    $.ajax( {
         dataType: "json",
  -      url: "<%= CONFIG.node_api_url %>/places/" + refreshedPlaceIDs.join(",") + "?per_page=500",
  -      success: function( r ) {
  -        _.each( r.results, function( p ) {
  -          atlasJS.addPlaceToMap( p, place_hash[p.id] );
  -        });
  +      url: "<%= CONFIG.node_api_url %>/places/" + refreshedPlaceIDs.join( "," ) + "?per_page=500",
  +      success: function ( r ) {
  +        _.each( r.results, function ( p ) {
  +          atlasJS.addPlaceToMap( p, placeHash[p.id] );
  +        } );
         }
  -    });
  -  }
  -  $.map( atlasState.placeLayers, function(v, i){
  -    if( !Object.keys(place_hash).includes(i) && 
  -      ( atlasState.placeLayers[i]["type"] == "native" || 
  -      atlasState.placeLayers[i]["type"] == "introduced" ) ) {
  -        atlasState.placeLayers[i].layer.setMap( null );
  -        delete atlasState.placeLayers[i]; 
  -    }
  -  });  
  -};
  -
  -atlasJS.refreshPlaces = function( ) {
  -  $.ajax({
  +    } );
  +  }
  +  $.map( atlasState.placeLayers, function ( v, i ) {
  +    if ( !Object.keys( placeHash ).includes( i ) && (
  +      atlasState.placeLayers[i].type === "native"
  +        || atlasState.placeLayers[i].type === "introduced"
  +    ) ) {
  +      atlasState.placeLayers[i].layer.setMap( null );
  +      delete atlasState.placeLayers[i];
  +    }
  +  } );
  +};
  +
  +atlasJS.refreshPlaces = function ( ) {
  +  $.ajax( {
       dataType: "json",
       url: "/atlases/" + $( "#map" ).data( "atlas-id" ) + ".json",
  -    success: function( r ) {
  +    success: function ( r ) {
         atlasJS.addrefreshedPlaces( r.presence_places );
         atlasState.explodedPlaces = r.exploded_places;
       }
  -  });
  -};
  -
  -atlasJS.showInitialPlaces = function( ) {
  +  } );
  +};
  +
  +atlasJS.showInitialPlaces = function ( ) {
     var initialPlaceIDsWithEstablishment = $( "#map" ).data( "place-ids" );
  -  var initialPlaceIDs = Object.keys(initialPlaceIDsWithEstablishment);
  -  if( initialPlaceIDs.length > 0 ) {
  -    $.ajax({
  +  var initialPlaceIDs = Object.keys( initialPlaceIDsWithEstablishment );
  +  if ( initialPlaceIDs.length > 0 ) {
  +    $.ajax( {
         dataType: "json",
  -      url: "<%= CONFIG.node_api_url %>/places/" + initialPlaceIDs.join(",") + "?per_page=500",
  -      success: function( r ) {
  -        _.each( r.results, function( p ) {
  +      url: "<%= CONFIG.node_api_url %>/places/" + initialPlaceIDs.join( "," ) + "?per_page=500",
  +      success: function ( r ) {
  +        _.each( r.results, function ( p ) {
             atlasJS.addPlaceToMap( p, initialPlaceIDsWithEstablishment[p.id] );
  -        });
  +        } );
         }
  -    });
  -  }
  -
  -  var explodedPlaceIDs = _.map( atlasState.explodedPlaces, function( explodedAtlasPlaceID, placeID ) {
  -    return placeID;
  -  });
  -
  -  if( explodedPlaceIDs.length == 0 ) { return; }
  -  $.ajax({
  -    dataType: "json",
  -    url: "<%= CONFIG.node_api_url %>/places/" + explodedPlaceIDs.join(",") + "?per_page=500",
  -    success: function( r ) {
  -      _.each( r.results, function( p ) {
  +    } );
  +  }
  +
  +  var explodedPlaceIDs = _.map( atlasState.explodedPlaces,
  +    function ( explodedAtlasPlaceID, placeID ) {
  +      return placeID;
  +    } );
  +
  +  if ( explodedPlaceIDs.length === 0 ) { return; }
  +  $.ajax( {
  +    dataType: "json",
  +    url: "<%= CONFIG.node_api_url %>/places/" + explodedPlaceIDs.join( "," ) + "?per_page=500",
  +    success: function ( r ) {
  +      _.each( r.results, function ( p ) {
           atlasJS.addPlaceToMap( p, "exploded" );
  -      });
  -    }
  -  });
  -};
  -
  -atlasJS.alterAtlas = function( place ) {
  -  if( !place ) { return; }
  -  var taxonID = $( "#map" ).data( "taxon-id" );
  -  $.ajax({
  +      } );
  +    }
  +  } );
  +};
  +
  +atlasJS.alterAtlas = function ( place ) {
  +  if ( !place ) { return; }
  +  $.ajax( {
       type: "post",
       dataType: "json",
       url: "/atlases/" + $( "#map" ).data( "atlas-id" ) + "/alter_atlas_presence",
       data: { taxon_id: $( "#map" ).data( "taxon-id" ), place_id: place.id },
  -    success: function( s ) {
  -      if( s.presence ) {
  +    success: function ( s ) {
  +      if ( s.presence ) {
           atlasJS.addPlaceToMap( place,
  -          s.presence == "not allowed" ? "failed" : "native",
  +          s.presence === "not allowed" ? "failed" : "native",
             { selected: true } );
           atlasJS.updateMetadataPanel( );
         } else {
  
positive.code: 
  atlasJS.failedStyle = _.assign( { }, atlasJS.nativeStyle, {
    strokeColor: "red",
    fillColor: "red",
  });
  
  atlasJS.pendingStyle = _.assign( { }, atlasJS.nativeStyle, {
    strokeColor: "#202020",
    fillColor: "#202020",
  });
  
  
  atlasJS.explodedStyle = {
  
negative.code:         atlasJS.updateMetadataPanel( );
        }
      },
      error: function ( e ) {
        alert( e.responseJSON.error );
        atlasJS.addPlaceToMap( place, "failed", { selected: true } );
        atlasJS.updateMetadataPanel( );
      }
    } );
  };
  
  atlasJS.explodePlace = function ( place ) {
    if ( !place ) { return; }
    var taxonID = $( "#map" ).data( "taxon-id" );
    $.ajax( {
      type: "post",
      dataType: "json",
      url: "/exploded_atlas_places",
      data: { atlas_id: $( "#map" ).data( "atlas-id" ), place_id: place.id },
      success: function ( ) {
        atlasJS.addPlaceToMap( place, "exploded", { selected: true } );
        atlasJS.updateMetadataPanel( );
        atlasJS.refreshPlaces( );
      },
      error: function ( ) {
        console.log( "explode failed" );
      }
    } );
  };
  
  atlasJS.unexplodePlace = function ( place ) {
    if ( !place || !atlasState.explodedPlaces[place.id] ) { return; }
    var taxonID = $( "#map" ).data( "taxon-id" );
    $.ajax( {
      type: "delete",
      dataType: "json",
      url: "/exploded_atlas_places/" + atlasState.explodedPlaces[place.id],
      success: function ( ) {
        atlasJS.removeActivePlaceLayer( );
        atlasJS.addPlaceToMap( place, "pending", { selected: true } );
        atlasJS.updateMetadataPanel( );
        atlasJS.refreshPlaces( );
      },
      error: function ( ) {
        console.log( "unexplode failed" );
      }
    } );
  };
  
  atlasJS.getListings = function ( place ) {
    if ( !place ) { return; }
    var taxonID = $( "#map" ).data( "taxon-id" );
    $.ajax( {
      type: "get",
      dataType: "json",
      url: "/atlases/" + $( "#map" ).data( "atlas-id" ) + "/get_defaults_for_taxon_place",
      data: { taxon_id: $( "#map" ).data( "taxon-id" ), place_id: place.id },
      success: function ( s ) {
        var panel = $( "#bottomright" );
        panel.html( "" );
        panel.append( $( "<h4>" ).text( "Listed Taxa" ) );
        $.each( s, function ( key, value ) {
          var placeName = value.place.display_name || value.place.name;
          var explodeLink = $( "<a href='/listed_taxa/" + value.id + "'>" ).text( value.taxon.name + " in " + placeName );
          panel.append( explodeLink );
          panel.append( "<br>" );
        } );
      },
      error: function ( ) { }
    } );
  };
  
  $( function ( ) {
    atlasState.explodedPlaces = $( "#map" ).data( "exploded-places" );
    $( "#map" ).taxonMap( {
      zoomLevel: 2,
      latitude: 28,
      longitude: -34
    } );
    atlasState.map = $( "#map" ).data( "taxonMap" );
    if ( $( "#map" ).data( "is-curator" ) ) {
      atlasState.map.addListener( "click", atlasJS.clickCallback );
    }
  
    atlasJS.showInitialPlaces( );
  
    $( ".destroy_all_alterations" ).on( "click", function ( event ) {
      event.preventDefault();
      var $this = $( this );
      var atlasID = $this.attr( "data-id" );
      $.ajax( {
        type: "POST",
        url: "/atlases/" + atlasID + "/destroy_all_alterations",
        data: { id: atlasID },
        success: function ( ) {
          $( "tbody#alteration tr" ).fadeOut();
          $( "table" ).append( "<div class='no_alteration'>No alterations to this atlas yet</div>" );
          $this.fadeOut();
        },
        error: function ( ) {
          console.log( "error" );
        },
        dataType: "JSON"
      } );
    } );
  
    $( ".remove_atlas_alteration" ).on( "click", function ( event ) {
      event.preventDefault();
      var $this = $( this );
      var aaID = $this.attr( "data-atlas-alteration-id" );
      $.ajax( {
        type: "POST",
        url: "/atlases/" + $( "#map" ).data( "atlas-id" ) + "/remove_atlas_alteration",
        data: { aa_id: aaID },
        success: function ( ) { },
        error: function ( ) {
          console.log( "error" );
        },
        dataType: "JSON"
      } );
    } );
  
    $( ".remove_listed_taxon_alteration" ).on( "click", function ( event ) {
      event.preventDefault();
      var $this = $( this );
      var ltaID = $this.attr( "data-listed-taxon-alteration-id" );
      $.ajax( {
        type: "POST",
        url: "/atlases/" + $( "#map" ).data( "atlas-id" ) + "/remove_listed_taxon_alteration",
        data: { lta_id: ltaID },
        success: function ( ) {
          console.log( "success" );
        },
        error: function ( ) {
          console.log( "error" );
        },
        dataType: "JSON"
      } );
    } );
  } );
  