Skip to content

Commit 7e12f2d

Browse files
Merge pull request #9 from gabriel-russo/typescript
Typescript migration
2 parents 50c35df + fa4aa99 commit 7e12f2d

38 files changed

+5461
-6753
lines changed

.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 57 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
dist
22
node_modules
33
.idea
4+
*.zip
5+
*.tgz

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2023 Gabriel Russo
1+
Copyright (c) 2025 Gabriel Russo
22

33
Permission is hereby granted, free of charge, to any person obtaining a
44
copy of this software and associated documentation files (the "Software"),

README.md

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
---
1111

12-
This is a [Leaflet](http://leafletjs.com/) plugin for loading your spatialized data into leaflet based on [leaflet-omnivore](https://github.com/mapbox/leaflet-omnivore) and [Leaflet.FileLayer](https://github.com/makinacorpus/Leaflet.FileLayer) plugins.
13-
This plugin was made looking for a convenient and easy to use plugin for loading external spatial files to leaflet.
12+
This is a [Leaflet](http://leafletjs.com/) plugin for loading your spatialized data into leaflet based
13+
on [leaflet-omnivore](https://github.com/mapbox/leaflet-omnivore)
14+
and [Leaflet.FileLayer](https://github.com/makinacorpus/Leaflet.FileLayer) plugins.
15+
This plugin was made looking for a convenient and easy to use plugin for loading external spatial files to leaflet.
1416

1517
It currently supports:
1618

@@ -22,8 +24,10 @@ It currently supports:
2224
* [KMZ](https://developers.google.com/kml/documentation/kmzarchives)
2325
* [WKT](http://en.wikipedia.org/wiki/Well-known_text) (via [wellknown](https://github.com/mapbox/wellknown))
2426
* [TopoJSON](https://github.com/mbostock/topojson) (via [topojson-client](https://github.com/topojson/topojson-client))
25-
* [Encoded Polylines](https://developers.google.com/maps/documentation/utilities/polylinealgorithm) (via [polyline](https://github.com/mapbox/polyline))
26-
* [Shapefile](https://en.wikipedia.org/wiki/Shapefile) (via [shpjs](https://github.com/calvinmetcalf/shapefile-js/tree/gh-pages)) (zipped or separate files)
27+
* [Encoded Polylines](https://developers.google.com/maps/documentation/utilities/polylinealgorithm) (
28+
via [polyline](https://github.com/mapbox/polyline))
29+
* [Shapefile](https://en.wikipedia.org/wiki/Shapefile) (
30+
via [shpjs](https://github.com/calvinmetcalf/shapefile-js/tree/gh-pages)) (zipped or separate files)
2731

2832
## Installation
2933

@@ -35,6 +39,9 @@ npm install leaflet-better-filelayer
3539

3640
Checkout the [Demo](https://gabriel-russo.github.io/Leaflet.BetterFileLayer/example/)
3741

42+
Checkout
43+
the [Demo with external button](https://gabriel-russo.github.io/Leaflet.BetterFileLayer/example/with-button.html)
44+
3845
Below gif show an example of loading a separated shapefile using drag and drop.
3946

4047
Note: The plugin only looks for `.shp`, `.dbf`, `.shx`, `.prj` with the same name.
@@ -52,51 +59,30 @@ const map = L.map('map', { betterFileLayerControl: true })
5259
Or like any control
5360

5461
```js
55-
L.Control.betterFileLayer().addTo(map);
56-
```
62+
L.control.betterFileLayer()
63+
.addTo(map);
5764

58-
## Docs
65+
// or
5966

60-
> For more detailed docs, please check the [wiki](https://github.com/gabriel-russo/Leaflet.BetterFileLayer/wiki)
67+
const control = new L.Control.BetterFileLayer();
6168

62-
### Options:
63-
```js
64-
// The Options object
65-
options = {
66-
position: 'topleft', // Leaflet control position
67-
fileSizeLimit: 1024, // File size limit in kb (default: 1024 kb)
68-
style: () => {}, // Overwrite the default BFL GeoJSON style function
69-
onEachFeature: () => {}, // Overwrite the default BFL GeoJSON onEachFeature function
70-
layer: L.customLayer, // If you want a custom layer to be used (must be a GeoJSON class inheritance)
71-
// Restrict accepted file formats (default: .gpx, .kml, .kmz, .geojson, .json, .csv, .topojson, .wkt, .shp, .shx, .prj, .dbf, .zip)
72-
formats:['.geojson', '.kml', '.gpx'],
73-
importOptions: { // Some file types may have import options, for now, just csv is documented
74-
csv: {
75-
delimiter: ';',
76-
latfield: 'LAT',
77-
lonfield: 'LONG',
78-
},
79-
},
80-
text: { // If you need translate
81-
title: "Import a layer", // Plugin Button Text
82-
},
83-
}
69+
control.addTo(map);
8470
```
8571

86-
### Events
72+
## Documentation
8773

88-
| Event Name | Data | Description |
89-
|------------------------------|--------------------|----------------------------------------------------------------------------------------------------------------------|
90-
| `bfl:layerloaded` | { layer: L.Layer } | Event fired when the data is sucessfuly loaded on map. It returns the layer reference |
91-
| `bfl:layerloaderror` | { layer: string } | Event fired when the loader fails to load your file. It returns the name of the file |
92-
| `bfl:filenotsupported` | { layer: string } | Event fired when the loader does not support the file type of your file. It returns the name of the file |
93-
| `bfl:layerisempty` | { layer: string } | Event fired when the layer haven't any features. It returns the name of the file |
94-
| `bfl:filesizelimit` | { layer: string } | Event fired when the file's size exceeds the file size limit (fileSizeLimit option). It returns the name of the file |
74+
> [Go to Wiki page](https://github.com/gabriel-russo/Leaflet.BetterFileLayer/wiki)
9575
76+
## Typescript support
77+
78+
![event_types](docs/images/class_types.png)
79+
![event_types](docs/images/event_types.png)
80+
![event_types](docs/images/event_handler_types.png)
9681

9782
### Custom html button
9883

99-
If you are developing a web application and you want to use your own html button outside the map container, you can use the following code:
84+
If you are developing a web application and you want to use your own html button outside the map container, you can use
85+
the following code:
10086

10187
```js
10288
// Note: The button have to be type "file"
@@ -105,41 +91,62 @@ const options = {
10591
button: document.getElementById('my-button'), // Your button HTML reference
10692
}
10793

108-
const control = L.Control.betterFileLayer(options)
94+
const control = L.control.betterFileLayer(options)
10995
.addTo(map);
11096
```
97+
11198
After that, the plugin will bind an "on change" event on this button, waiting for files.
11299

113100
You can see the example [here](https://gabriel-russo.github.io/Leaflet.BetterFileLayer/example/with-button.html)
114101

115102
`Note:` The Drag and Drop event listener will bind it self automatically
116103

104+
#### For Framework (React, Angular...) devs
105+
106+
To be less painful to handle render states with Frameworks + Leaflet Control, you can bind the button
107+
later, doing this:
108+
109+
```ts
110+
const options = {
111+
will_bind_button_later: true
112+
}
113+
114+
const control = L.control.betterFileLayer(options)
115+
.addTo(map);
116+
117+
// Example using React
118+
// ref = useRef();....
119+
// <input ref={ref} ... />
120+
control.bind_button(ref.current);
121+
```
122+
117123
## Development
118124

119125
Install the development dependencies
126+
120127
```commandline
121128
npm install --save-dev
122129
```
123130

124-
Start the webpack watch to compile and save at dist/ after any change
125-
```commandline
126-
npm run dev
127-
```
131+
`npm run build` after any change and check changes.
128132

129-
Open `index.html` in your browser and start editing
133+
Open `index.html` in your browser and start editing.
130134

131135
### Test
132136

133137
To run unity tests:
138+
134139
```commandline
135140
npm run test
136141
```
137142

138143
## Authors
139-
- Gabriel Russo
144+
145+
- Gabriel Russo <gabrielrusso@protonmail.com>
140146

141147
## Credits
142148

149+
- Copyright (c) 2025, Gabriel Russo
143150
- Copyright (c) 2014, Mapbox
144151
- Copyright (c) 2012, Michael Bostock
145152
- Copyright (c) 2012 Makina Corpus

docs/images/class_types.png

13 KB
Loading
29.1 KB
Loading

docs/images/event_types.png

13.5 KB
Loading

eslint.config.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @ts-check
2+
3+
import eslint from '@eslint/js';
4+
import tseslint from 'typescript-eslint';
5+
6+
export default tseslint.config(
7+
eslint.configs.recommended,
8+
tseslint.configs.recommended,
9+
{
10+
rules: { '@typescript-eslint/no-namespace': 'off' },
11+
extends: [],
12+
settings: {
13+
'import/resolver': {
14+
node: {
15+
paths: ['src'],
16+
},
17+
},
18+
},
19+
}
20+
);

example/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
<!-- Leaflet BetterFileLayer -->
1515
<script type="application/javascript"
16-
src="https://unpkg.com/leaflet-better-filelayer@0.1.1/dist/leaflet.betterfilelayer.min.js"
16+
src="https://unpkg.com/leaflet-better-filelayer@1.0.0/dist/leaflet.betterfilelayer.js"
1717
crossorigin="anonymous"></script>
18-
<link rel="stylesheet" href="https://unpkg.com/leaflet-better-filelayer@0.1.1/dist/leaflet.betterfilelayer.css"
18+
<link rel="stylesheet" href="https://unpkg.com/leaflet-better-filelayer@1.0.0/dist/leaflet.betterfilelayer.css"
1919
crossorigin="anonymous" referrerpolicy="no-referrer">
2020
</head>
2121

0 commit comments

Comments
 (0)