Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bind pop-up with the contents of csv #118

Open
Dishant-P opened this issue Jun 11, 2020 · 3 comments
Open

How to bind pop-up with the contents of csv #118

Dishant-P opened this issue Jun 11, 2020 · 3 comments

Comments

@Dishant-P
Copy link

Hi,
I am using omnivore .csv function to upload the file as a layer on leaflet map. The longitudes and latitudes are detected perfectly and markers are there. But I want other columns of the csv to be displayed as the pop-up content. How can I do that?

@Dishant-P
Copy link
Author

Hi,
Yes, I did. But I switched to Leaflet.geoCsv() functionality to get this done.

@Dishant-P
Copy link
Author

Dishant-P commented Jan 13, 2022

Here is the code. I guess there is one repository for this as well, but I can't remember the name. But this is the code I have from my project file.

function add_csv() {
    var mi_geocsv = L.geoCsv(null, {
        titles: ['lat', 'lng', 'popup'],
        fieldSeparator: ',',
        lineSeparator: '\n',
        deleteDobleQuotes: true,
        firstLineTitles: true,
        onEachFeature: function (feature, layer) {
            var popup = '';
            for (var clave in feature.properties) {
                var title = mi_geocsv.getPropertyTitle(clave);
                popup += '<b>' + title + '</b><br />' + feature.properties[clave] + '<br /><br />';
            }
            layer.bindPopup(popup);
        }
    });

    $.ajax({
        type: 'GET',
        dataType: 'text',
        url: 'csv_test.csv',
        error: function () {
            alert('Error occured');
        },
        success: function (csv) {
            mi_geocsv.addData(csv);
            mi_geocsv.options.name = "MyCSV";
            mi_geocsv.options.color = '#001100';
            mi_geocsv.options.opacity = 0.5;
            map.addLayer(mi_geocsv);
            appearanceControl.addOverlay(mi_geocsv, "Application Data");
        }
    });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@Dishant-P and others