<commit_before>var infoWindow;

function initializeMap( location, zoom ) {
    location = location || { latitude: 0, longitude: 0 };
    zoom = zoom || 1;
    return new google.maps.Map( document.getElementById( 'map' ), {
        zoom: zoom,
        center: new google.maps.LatLng( location.latitude, location.longitude ),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    } );
}

function initializeMarkerClusterer( map, markers ) {
    return new MarkerClusterer( map, markers, { gridSize: 40, maxZoom: 0 } );
}

function createLocationContent( location ) {
    return [
        '<div>',
            '<a onclick="showAreaInfos( this )" id="location-selection" href="#" data-bounding-box="',
//        'nw_lat=' + location.latitude * 0.9999,
//        '&nw_lng=' + location.longitude * 0.9999,
//        '&se_lat=' + location.latitude * 1.0001,
//        '&se_lng=' + location.longitude * 1.0001,

        'bbox=' + location.latitude * 0.9999 + ',' + location.longitude * 0.9999 + ',' + location.latitude * 1.0001 + ',' + location.longitude * 1.0001,
        '">',
        '<span>Show interactions</span>',
        '</a>',
        '<br />',
        '</div>'
    ].join( '' );
}

function placeMarker( content, location, map ) {
    var latLng = new google.maps.LatLng( location.latitude, location.longitude ),
        marker = new google.maps.Marker( { position: latLng, map: map } );
    infoWindow = new google.maps.InfoWindow( { content: content } );

    google.maps.event.addListener( marker, 'click', function() {

        // @TODO: put this request to eol-globi-data-js and build an api call for only the count (it takes too long)

//        jQuery.ajax( getSpecimensRequestObject( location ) )
//            .done( function( response ) {
//                if ( response.data ) {
//                    infoWindow.content = infoWindow.content.replace( '###count###', response.data.length )
                    infoWindow.open( map, marker );
//                }
//            } );
    } );

    return marker;
}

function getSpecimensRequestObject( location ) {
    var url = 'http://trophicgraph.com:7474/db/data/cypher',
        query = [
            "START location=node:locations('*:*')",
            "MATCH location<-[:COLLECTED_AT]-specimen-[:CLASSIFIED_AS]->species",<commit_msg>[BUGFIX] Fix caching issue for infoWindow / Fix bbox coordinates<commit_after>var currentInfoWindow;

function initializeMap( location, zoom ) {
    location = location || { latitude: 0, longitude: 0 };
    zoom = zoom || 1;
    return new google.maps.Map( document.getElementById( 'map' ), {
        zoom: zoom,
        center: new google.maps.LatLng( location.latitude, location.longitude ),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    } );
}

function initializeMarkerClusterer( map, markers ) {
    return new MarkerClusterer( map, markers, { gridSize: 40, maxZoom: 0 } );
}

function createLocationContent( location ) {
    var longitude = {
        west: location.longitude < 1 ? location.longitude * 1.0001 : location.longitude * 0.9999,
        east: location.longitude < 1 ? location.longitude * 0.9999 : location.longitude * 1.0001
    };
    var latitude = {
        north: location.latitude < 1 ? location.latitude * 1.0001 : location.latitude * 0.9999,
        south: location.latitude < 1 ? location.latitude * 0.9999 : location.latitude * 1.0001
    };
    return [
        '<div>',
            '<a onclick="showAreaInfos( this )" id="location-selection" href="#" data-bounding-box="',
                'bbox=' + longitude.west + ',' + latitude.north + ',' + longitude.east + ',' + latitude.south,
            '">',
        '<span>Show interactions</span>',
        '</a>',
        '<br />',
        '</div>'
    ].join( '' );
}

function placeMarker( content, location, map ) {
    var latLng = new google.maps.LatLng( location.latitude, location.longitude ),
        marker = new google.maps.Marker( { position: latLng, map: map } ),
    infoWindow = new google.maps.InfoWindow( { content: content } );

    google.maps.event.addListener( marker, 'click', function() {

        // @TODO: put this request to eol-globi-data-js and build an api call for only the count (it takes too long)

//        jQuery.ajax( getSpecimensRequestObject( location ) )
//            .done( function( response ) {
//                if ( response.data ) {
//                    infoWindow.content = infoWindow.content.replace( '###count###', response.data.length )
        currentInfoWindow && currentInfoWindow.close();
        currentInfoWindow = infoWindow;
        currentInfoWindow.open( map, marker );
//                    infoWindow.open( map, marker );
//                }
//            } );
    } );

    return marker;
}

function getSpecimensRequestObject( location ) {
    var url = 'http://trophicgraph.com:7474/db/data/cypher',
        query = [
            "START location=node:locations('*:*')",
            "MATCH location<-[:COLLECTED_AT]-specimen-[:CLASSIFIED_AS]->species",
{'fraction_non_alphanumeric': 0.14951961569255404, 'fraction_numerical': 0.020816653322658127, 'mean_word_length': 2.4749652294853965, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3842983', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1482, 'n_words': 338}