Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
leaflet-geocsv
Advanced tools
English: Leaflet plugin for loading a CSV file as geoJSON layer.
Castellano: Plugin para Leaflet que permite cargar un archivo CSV como capa geoJSON.
Ease of use: A CSV (comma-separated values) file is a simple and open file format that stores tabular data in plain-text form. Virtually all spreadsheet and database software can import/export this file format.
Save bandwidth: When used to display markers, GeoJSON files can be up to four times as large as a CSV file containing the same information. This plugin provides the ability to download a CSV file that is then parsed into a GeoJSON document on the client side, saving you bandwidth and reducing load times. In similar scenarios, we recommend using GeoCSV together with MarkerCluster as in the Bankia Offices Map Example.
Plugin only (2.4k, uncompressed): leaflet.geocsv.js
Full Repository (includes plugin, all prerequisites and examples): .ZIP or .TAR.GZ
GeoCSV inherits the configuration options and methods of its parent object, the GeoJSON layer, and further defines the following of its own:
titles: An array of field titles in the same order in which they appear within the CSV file. GeoCSV only requires the presence of two field titles, lat
and lng
(latitude and longitude, respectively); all others field titles are permitted, omitting spaces, capitalization, accent characters, etc. By default, titles: ['lat', 'lng', 'popup']
latitudeTitle: The title used for the latitude value of the feature. By default, latitudeTitle: 'lat'
.
longitudeTitle: The title used for the longitude value of the feature. By default, longitudeTitle: 'lng'
.
lineSeparator: The string delimiting lines within the CSV file (between each GeoJSON feature). By default, lineSeparator: '\n'
.
fieldSeparator: The string delimiting individual fields within each feature. By default, fieldSeparator: ';'
.
deleteDoubleQuotes: A boolean indicating if double quotes surrounding individual field values should be removed. By default, true
.
firstLineTitles: A boolean indicating if the first line of the CSV file contains field titles. If set to false, the plugin will ignore the titles
configuration option. By default, false
.
getPropertyTitle( propertyName ): When passed a property name (string), returns the associated property title.
getPropertyName( propertyTitle ): When passed a property title (string), returns the associated property name.
Include the plugin JavaScript file after leaflet.js: <script src="leaflet.geocsv.js"></script>
Create a GeoCSV layer by instantiating the class or calling L.geoCsv()
. Where csvFileContents
is the content of a CSV file and options
is an object literal as described in the previous section: var csvLayer = L.geoCsv(csvFileContents, options);
An example, using jQuery to read a CSV file, and adding a GeoCSV layer to a map:
(function() {
'use strict';
var map = L.map('mapContainer');
$.get('data.csv', function(csvContents) {
var geoLayer = L.geoCsv(csvContents, {firstLineTitles: true, fieldSeparator: ','});
map.addLayer(geoLayer);
});
});
Complete examples can be found within the examples
subdirectory of the repository:
Leaflet GeoCSV hereda de GeoJSON, por lo que pueden usarse todas las opciones y métodos de la superclase. Además define las siguientes opciones propias:
titles: Array con los rótulos o títulos de los campos en el orden en el que aparecen en el CSV. Hay dos títulos especiales que deben aparecer siempre con el mismo nombre: 'lat' → latitud y 'lng' → longitud. El resto puede adoptar cualquier forma, admitiendo espacios, mayúsculas, tildes, etc. Por defecto ['lat', 'lng', 'popup']
latitudeTitle: Título del campo latitud. Por defecto latitudeTitle: 'lat'
.
longitudeTitle: Título del campo longitud. Por defecto longitudeTitle: 'lng'
.
lineSeparator: Carácter o cadena de caracteres que usarán para separar las líneas del archivo CSV, cada una de las features. Por defecto '\n'
fieldSeparator: Carácter o cadena de caracteres que usarán para separar los campos del archivo CSV. Por defecto ';'
deleteDoubleQuotes: Valor booleano que indica si se desea borrar las comillas que delimitan los campos del archivo CSV. Por defecto true
firstLineTitles: Valor booleano que indica si la primera línea del archivo CSV contiene los rótulos de los campos. Por defecto false. Si se pone a true se ignorará la opción titles.
<script src="leaflet.geocsv.js"></script>
var mi_geocsv = L.geoCsv (csv_string, opciones);
Las opciones son las que hemos visto en el apartado anterior. El primer parámetro es un string con el contenido del fichero CSV. Si a la hora de instanciarlo no tenemos disponibles los datos, csv_string puede valer null y cargar los datos más adelante usando el método addData. Ejemplo de carga asíncrona usando jQuery:
//...
var mi_geocsv = L.geoCsv (null, {firstLineTitles: true, fieldSeparator: ','});
//...
$.ajax ({
type:'GET',
dataType:'text',
url:'datos.csv',
error: function() {
alert('No se pudieron cargar los datos');
},
success: function(csv) {
mi_geocsv.addData(csv);
mapa.addLayer(mi_geocsv);
}
});
En el subdirectorio example se encuentran ejemplos completos del uso del plugin:
FAQs
Leaflet plugin for loading a CSV file as geoJSON layer
The npm package leaflet-geocsv receives a total of 8 weekly downloads. As such, leaflet-geocsv popularity was classified as not popular.
We found that leaflet-geocsv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.