Skip to content

Commit 8299a7e

Browse files
committed
update readme and examples
1 parent f898998 commit 8299a7e

4 files changed

Lines changed: 30 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Leaflet.Geodesic is available from [unpkg](https://unpkg.com/browse/leaflet.geod
2222

2323
Add it in your nodejs-project with `npm i leaflet.geodesic`.
2424

25+
If possible, pin the plug-in to a specific version and use [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity). Check the [release page](https://github.com/henrythasler/Leaflet.Geodesic/releases) for the latest version, links and checksum. A checksum can by verified with `npm run build`, is stored in `dist/leaflet.geodesic.umd.min.js.sha256` on [jsDelivr](https://www.jsdelivr.com/package/npm/leaflet.geodesic?path=dist) and [unpkg](https://unpkg.com/browse/leaflet.geodesic@2.5.1/dist/leaflet.geodesic.umd.min.js.sha256) and is shown in the [build-log](https://travis-ci.org/henrythasler/Leaflet.Geodesic/builds) for a tagged version.
26+
2527
## Basic usage
2628

2729
- `L.Geodesic` draws geodesic lines between all points of a given line- or multiline-string.

docs/circle-interactive.html

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353

5454
var map = L.map('map', {
5555
maxBounds: [
56-
[-90, -180],
57-
[90, 180]
56+
[-90, -200],
57+
[90, 200]
5858
],
5959
center: [50, 0],
6060
zoom: 4
@@ -90,16 +90,16 @@
9090

9191
// method that we will use to update the control based on feature properties passed
9292
info.update = function (stats) {
93-
const circumfenceString = (stats.totalDistance ? (stats.totalDistance>10000)?(stats.totalDistance/1000).toFixed(0)+' km':(stats.totalDistance).toFixed(0)+' m' : 'invalid')
94-
const radiusString = (geodesiccircle.radius ? (geodesiccircle.radius>10000)?(geodesiccircle.radius/1000).toFixed(0)+' km':(geodesiccircle.radius).toFixed(0)+' m' : 'invalid')
95-
this._div.innerHTML = '<h4>Statistics</h4><b>Radius</b><br/>' + radiusString +
96-
'<br/><br/><b>Circumfence</b><br/>' + circumfenceString +
93+
const circumfenceString = (stats.totalDistance ? (stats.totalDistance > 10000) ? (stats.totalDistance / 1000).toFixed(0) + ' km' : (stats.totalDistance).toFixed(0) + ' m' : 'invalid')
94+
const radiusString = (geodesiccircle.radius ? (geodesiccircle.radius > 10000) ? (geodesiccircle.radius / 1000).toFixed(0) + ' km' : (geodesiccircle.radius).toFixed(0) + ' m' : 'invalid')
95+
this._div.innerHTML = '<h4>Statistics</h4><b>Radius</b><br/>' + radiusString +
96+
'<br/><br/><b>Circumfence</b><br/>' + circumfenceString +
9797
'<br/><br/><b>Vertices</b><br/>' + stats.vertices;
98-
};
98+
};
9999

100100
info.update(geodesiccircle.statistics);
101101

102-
var diff = {lat:0, lng:0};
102+
var diff = { lat: 0, lng: 0 };
103103
A.on('dragstart', function () {
104104
diff = { lat: A.getLatLng().lat - B.getLatLng().lat, lng: A.getLatLng().lng - B.getLatLng().lng }; // remember difference between A and B
105105
});
@@ -110,8 +110,9 @@
110110
lat: Math.max(-90, Math.min(90, A.getLatLng().lat - diff.lat)),
111111
lng: A.getLatLng().lng - diff.lng
112112
}); // move B parallel to A
113-
geodesiccircle.setLatLng(e.latlng);
114-
geodesiccircle.setRadius(geodesiccircle.distanceTo(B.getLatLng()));
113+
114+
const radius = geodesiccircle.geom.distance(e.latlng, B.getLatLng());
115+
geodesiccircle.setLatLng(e.latlng, radius);
115116
info.update(geodesiccircle.statistics);
116117
});
117118
B.on('drag', (e) => {

docs/testing-circle.html

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
<script type="text/javascript">
5353

5454
var map = L.map('map', {
55-
// maxBounds: [
56-
// [-90, -180],
57-
// [90, 180]
58-
// ],
55+
maxBounds: [
56+
[-90, -200],
57+
[90, 200]
58+
],
5959
center: [50, 0],
6060
zoom: 4
6161
});
@@ -117,13 +117,23 @@
117117
geodesiccircle.setLatLng(e.latlng, radius);
118118
info.update(geodesiccircle.statistics);
119119

120+
// console.log(geodesiccircle.getLatLngs().length);
121+
122+
geodesiccircle.setStyle({
123+
color: (geodesiccircle.getLatLngs().length === 1)?'red':'blue'
124+
})
125+
120126
// this is only valid for small radii where the resulting circle is flat compared to the earth surface
121127
geodesiccircle.setTooltipContent(`Area: ${Math.round(geodesiccircle.radius ** 2 * Math.PI / 1000 ** 2)} km²`);
122128
});
123129
B.on('drag', (e) => {
124130
B.setTooltipContent(`${Math.round(10000 * e.latlng.lat) / 10000} ${Math.round(10000 * e.latlng.lng) / 10000}`);
125131
geodesiccircle.setRadius(geodesiccircle.distanceTo(e.latlng));
126132
info.update(geodesiccircle.statistics);
133+
134+
geodesiccircle.setStyle({
135+
color: (geodesiccircle.getLatLngs().length === 1)?'red':'blue'
136+
})
127137

128138
// this is only valid for small radii where the resulting circle is flat compared to the earth surface
129139
geodesiccircle.setTooltipContent(`Area: ${Math.round(geodesiccircle.radius ** 2 * Math.PI / 1000 ** 2)} km²`);

docs/testing.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@
106106
});
107107
B.on('drag', (e) => {
108108
// console.log(`B=${e.latlng}`);
109-
B.setTooltipContent(`${Math.round(10000 * e.latlng.lat) / 10000} ${Math.round(10000 * e.latlng.lng) / 10000}`);
109+
// B.setTooltipContent(`${Math.round(10000 * e.latlng.lat) / 10000} ${Math.round(10000 * e.latlng.lng) / 10000}`);
110+
B.setTooltipContent(`${map.latLngToLayerPoint(e.latlng)}`);
111+
110112
geodesic.setLatLngs([A.getLatLng(), e.latlng])
111113
info.update(geodesic.statistics);
112114
});

0 commit comments

Comments
 (0)