From 845a016c81d56bdbddf9133f98c514e4c1e6480c Mon Sep 17 00:00:00 2001 From: Jon West Date: Thu, 10 Nov 2016 08:33:39 -0600 Subject: [PATCH] Partial for #603 - Move documentation css to src - Declare built (dist) files for publish - Add tests for GeometryUtil.readableDistance - Add documentation for GeometryUtil, LatLngUtil, Utill, L.Polyline - Simplified .gitignore - Cleaned package.json order TODO: Add conversions to Polyline, Circle --- .gitignore | 183 +++--------------------------- build/leafdoc-templates/html.hbs | 4 +- build/publish.sh | 9 +- docs/examples-0.7.x/basic.html | 2 +- docs/examples-0.7.x/full.html | 124 ++++++++++---------- docs/examples-0.7.x/snapping.html | 2 +- docs/examples/basic.html | 2 +- docs/examples/full.html | 126 ++++++++++---------- docs/examples/popup.html | 4 +- docs/examples/snapping.html | 2 +- package.json | 13 ++- spec/suites/GeometryUtilSpec.js | 16 ++- src/ext/GeometryUtil.js | 54 ++++++--- src/ext/LatLngUtil.js | 6 +- src/ext/LineUtil.Intersect.js | 2 +- src/ext/Polyline.Intersect.js | 6 +- src/ext/TouchEvents.js | 2 +- 17 files changed, 225 insertions(+), 332 deletions(-) diff --git a/.gitignore b/.gitignore index e44221a2d..d86a797da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,170 +1,17 @@ - -################# -## Eclipse -################# - -*.pydevproject -.project -.metadata -bin/** -tmp/** +node_modules +.DS_Store tmp/**/* -*.tmp -*.bak -*.swp -*~.nib -local.properties -.classpath -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - - -################# -## Visual Studio -################# - -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.sln.docstates - -# Build results -**/[Dd]ebug/ -**/[Rr]elease/ -*_i.c -*_p.c -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.vspscc -.builds -**/*.dotCover - -## TODO: If you have NuGet Package Restore enabled, uncomment this -#**/packages/ - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf - -# Visual Studio profiler -*.psess -*.vsp - -# ReSharper is a .NET coding add-in -_ReSharper* - -# Installshield output folder -[Ee]xpress - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish - -# Others -[Bb]in -[Oo]bj -sql -TestResults -*.Cache -ClientBin -stylecop.* -~$* -*.dbmdl -Generated_Code #added for RIA/Silverlight projects - -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML - - - -############ -## Windows -############ - -# Windows image file caches -Thumbs.db - -# Folder config file -Desktop.ini - -# Node modules used during build -node_modules/ - -############# -## Python -############# - -*.py[co] - -# Packages -*.egg -*.egg-info -#dist -#build -eggs -parts -bin -var -sdist -develop-eggs -.installed.cfg - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -.tox - -#Translations -*.mo - -#Mr Developer -.mr.developer.cfg - -#Intellij .idea - -# Mac crap -.DS_Store +*.iml +_site +*.sublime-* +dist/*.js +dist/*.css +dist/*.map +coverage/ +*.js.html +.mailmap +bower.json +component.json +debug/local/ +Gemfile.lock diff --git a/build/leafdoc-templates/html.hbs b/build/leafdoc-templates/html.hbs index cd582a703..c259117f8 100644 --- a/build/leafdoc-templates/html.hbs +++ b/build/leafdoc-templates/html.hbs @@ -12,8 +12,8 @@ - - + +
diff --git a/build/publish.sh b/build/publish.sh index 7a52895da..9fd3b68e1 100755 --- a/build/publish.sh +++ b/build/publish.sh @@ -11,7 +11,14 @@ git checkout -b build jake build[,,true] jake docs -git add -A +git add \ + dist/leaflet.draw.js \ + dist/leaflet.draw-src.js \ + dist/leaflet.draw-src.map \ + dist/leaflet.draw.css \ + dist/leaflet.draw-src.css \ + docs/* \ + -f git commit -m "v$VERSION" diff --git a/docs/examples-0.7.x/basic.html b/docs/examples-0.7.x/basic.html index a7ce82930..b002062fa 100644 --- a/docs/examples-0.7.x/basic.html +++ b/docs/examples-0.7.x/basic.html @@ -4,7 +4,7 @@ Leaflet.draw drawing and editing tools - + diff --git a/docs/examples-0.7.x/full.html b/docs/examples-0.7.x/full.html index 66a625e66..12007b6e5 100644 --- a/docs/examples-0.7.x/full.html +++ b/docs/examples-0.7.x/full.html @@ -1,83 +1,83 @@ - Leaflet.draw vector editing handlers + Leaflet.draw vector editing handlers - - + + - + - + - - + + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - + + + - + - - - - - + + + + + -
+
- + diff --git a/docs/examples-0.7.x/snapping.html b/docs/examples-0.7.x/snapping.html index cd5f99d25..2402da812 100644 --- a/docs/examples-0.7.x/snapping.html +++ b/docs/examples-0.7.x/snapping.html @@ -4,7 +4,7 @@ Leaflet.draw drawing with snapping - + diff --git a/docs/examples/basic.html b/docs/examples/basic.html index ddf09728a..ee557b002 100644 --- a/docs/examples/basic.html +++ b/docs/examples/basic.html @@ -10,7 +10,7 @@ crossorigin="anonymous"> - + diff --git a/docs/examples/full.html b/docs/examples/full.html index 15bb45a69..12007b6e5 100644 --- a/docs/examples/full.html +++ b/docs/examples/full.html @@ -1,83 +1,83 @@ - Leaflet.draw vector editing handlers + Leaflet.draw vector editing handlers - - + + - - - + + + - - + + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - + + + - + - - - - - + + + + + -
+
- + diff --git a/docs/examples/popup.html b/docs/examples/popup.html index 99982df30..df012a5f8 100644 --- a/docs/examples/popup.html +++ b/docs/examples/popup.html @@ -8,7 +8,7 @@ - + @@ -48,7 +48,7 @@ diff --git a/package.json b/package.json index e711f509e..f99a42924 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,11 @@ "version": "0.4.3", "description": "Vector drawing plugin for Leaflet", "devDependencies": { - "happen": "^0.3.1", - "jake": "^8.0.15", "eslint": "^3.5.0 <3.6.0", "eslint-config-mourner": "^2.0.1", + "git-rev": "^0.2.1", + "happen": "^0.3.1", + "jake": "^8.0.15", "karma": "^1.3.0", "karma-chrome-launcher": "^2.0.0", "karma-coverage": "~1.1.1", @@ -19,15 +20,15 @@ "mocha": "^3.1.2", "phantomjs-prebuilt": "^2.1.12", "prosthetic-hand": "^1.3.1", - "uglify-js": "^2.7.3", - "uglifycss": "0.0.25", "source-map": "^0.5.6", - "git-rev": "^0.2.1" + "uglify-js": "^2.7.3", + "uglifycss": "0.0.25" }, "main": "dist/leaflet.draw.js", "style": "dist/leaflet.draw.css", "directories": { - "example": "examples" + "example": "docs/example", + "doc": "docs/" }, "scripts": { "build": "jake build -f ./Jakefile.js", diff --git a/spec/suites/GeometryUtilSpec.js b/spec/suites/GeometryUtilSpec.js index 5c4ffeb76..2f74a64fc 100644 --- a/spec/suites/GeometryUtilSpec.js +++ b/spec/suites/GeometryUtilSpec.js @@ -1,6 +1,4 @@ describe("L.GeometryUtil", function () { - var map, control, container; - it("geodesicArea", function () { expect(L.GeometryUtil.geodesicArea([ { lat: 0, lng: 0 }, @@ -15,11 +13,25 @@ describe("L.GeometryUtil", function () { it("metric", function () { expect(L.GeometryUtil.readableDistance(1000, true)).to.eql('1000 m'); expect(L.GeometryUtil.readableDistance(1500, true)).to.eql('1.50 km'); + expect(L.GeometryUtil.readableDistance(1500, 'metric')).to.eql('1.50 km'); }); it("imperial", function () { expect(L.GeometryUtil.readableDistance(1609.3488537961)).to.eql('1760 yd'); expect(L.GeometryUtil.readableDistance(1610.3488537961)).to.eql('1.00 miles'); + expect(L.GeometryUtil.readableDistance(1610.3488537961, 'yards')).to.eql('1.00 miles'); + }); + + it("imperial feet", function () { + expect(L.GeometryUtil.readableDistance(1609.3488537961, false, true, false)).to.eql('5280 ft'); + expect(L.GeometryUtil.readableDistance(1610.3488537961, false, true, false)).to.eql('5284 ft'); + expect(L.GeometryUtil.readableDistance(1610.3488537961, 'feet')).to.eql('5284 ft'); + }); + + it("nautical", function () { + expect(L.GeometryUtil.readableDistance(1609.3488537961, false, false, true)).to.eql('0.87 nm'); + expect(L.GeometryUtil.readableDistance(1610.3488537961, false, false, true)).to.eql('0.87 nm'); + expect(L.GeometryUtil.readableDistance(1610.3488537961, 'nauticalMile')).to.eql('0.87 nm'); }); }); }); diff --git a/src/ext/GeometryUtil.js b/src/ext/GeometryUtil.js index 3cf7dc798..729adae50 100644 --- a/src/ext/GeometryUtil.js +++ b/src/ext/GeometryUtil.js @@ -5,7 +5,7 @@ L.GeometryUtil = L.extend(L.GeometryUtil || {}, { // Ported from the OpenLayers implementation. See https://github.com/openlayers/openlayers/blob/master/lib/OpenLayers/Geometry/LinearRing.js#L270 - // @method geodesicArea(): void + // @method geodesicArea(): number geodesicArea: function (latLngs) { var pointsCount = latLngs.length, area = 0.0, @@ -25,7 +25,7 @@ L.GeometryUtil = L.extend(L.GeometryUtil || {}, { return Math.abs(area); }, - // @method readableArea(): void + // @method readableArea(): string readableArea: function (area, isMetric) { var areaStr; @@ -50,32 +50,56 @@ L.GeometryUtil = L.extend(L.GeometryUtil || {}, { return areaStr; }, - // @method readableDistance(): void - readableDistance: function (distance, isMetric, useFeet) { - var distanceStr; + // @method readableDistance(distance, isMetric, useFeet, isNauticalMile): string + // @method readableDistance(distance, units): string + // Converts metric distance to distance string. + readableDistance: function (distance, isMetric, isFeet, isNauticalMile) { + var distanceStr, + units; - if (isMetric) { + if (typeof isMetric == "string") { + units = isMetric; + } else { + if (isFeet) { + units = 'feet'; + } else if (isNauticalMile) { + units = 'nauticalMile'; + } else if (isMetric) { + units = 'metric'; + } else { + units = 'yards'; + } + } + + switch (units) { + case 'metric': // show metres when distance is < 1km, then show km if (distance > 1000) { - distanceStr = (distance / 1000).toFixed(2) + ' km'; + distanceStr = (distance / 1000).toFixed(2) + ' km'; } else { distanceStr = Math.ceil(distance) + ' m'; } - } else { + break; + case 'feet': + distance *= 1.09361 * 3; + distanceStr = Math.ceil(distance) + ' ft'; + + break; + case 'nauticalMile': + distance *= 0.53996; + distanceStr = (distance / 1000).toFixed(2) + ' nm'; + break; + case 'yards': + default: distance *= 1.09361; if (distance > 1760) { distanceStr = (distance / 1760).toFixed(2) + ' miles'; } else { - var suffix = ' yd'; - if (useFeet) { - distance = distance * 3; - suffix = ' ft'; - } - distanceStr = Math.ceil(distance) + suffix; + distanceStr = Math.ceil(distance) + ' yd'; } + break; } - return distanceStr; } }); diff --git a/src/ext/LatLngUtil.js b/src/ext/LatLngUtil.js index 513404813..aad9f1a30 100644 --- a/src/ext/LatLngUtil.js +++ b/src/ext/LatLngUtil.js @@ -5,7 +5,8 @@ L.LatLngUtil = { // Clones a LatLngs[], returns [][] - // @method cloneLatLngs(): void + // @method cloneLatLngs(LatLngs[]): L.LatLngs[] + // Clone the latLng point or points or nested points and return an array with those points cloneLatLngs: function (latlngs) { var clone = []; for (var i = 0, l = latlngs.length; i < l; i++) { @@ -19,7 +20,8 @@ L.LatLngUtil = { return clone; }, - // @method cloneLatLng(): void + // @method cloneLatLng(LatLng): L.LatLng + // Clone the latLng and return a new LatLng object. cloneLatLng: function (latlng) { return L.latLng(latlng.lat, latlng.lng); } diff --git a/src/ext/LineUtil.Intersect.js b/src/ext/LineUtil.Intersect.js index 8ea4b9592..f8b08a836 100644 --- a/src/ext/LineUtil.Intersect.js +++ b/src/ext/LineUtil.Intersect.js @@ -5,7 +5,7 @@ */ L.Util.extend(L.LineUtil, { - // @method segmentsIntersect(): void + // @method segmentsIntersect(): boolean // Checks to see if two line segments intersect. Does not handle degenerate cases. // http://compgeom.cs.uiuc.edu/~jeffe/teaching/373/notes/x06-sweepline.pdf segmentsIntersect: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2, /*Point*/ p3) { diff --git a/src/ext/Polyline.Intersect.js b/src/ext/Polyline.Intersect.js index 62c7bdc58..2f5cfabf9 100644 --- a/src/ext/Polyline.Intersect.js +++ b/src/ext/Polyline.Intersect.js @@ -4,7 +4,7 @@ */ L.Polyline.include({ - // @method intersects(): void + // @method intersects(): boolean // Check to see if this polyline has any linesegments that intersect. // NOTE: does not support detecting intersection for degenerate cases. intersects: function () { @@ -29,7 +29,7 @@ L.Polyline.include({ return false; }, - // @method newLatLngIntersects(): void + // @method newLatLngIntersects(): boolean // Check for intersection if new latlng was added to this polyline. // NOTE: does not support detecting intersection for degenerate cases. newLatLngIntersects: function (latlng, skipFirst) { @@ -41,7 +41,7 @@ L.Polyline.include({ return this.newPointIntersects(this._map.latLngToLayerPoint(latlng), skipFirst); }, - // @method newPointIntersects(): void + // @method newPointIntersects(): boolean // Check for intersection if new point was added to this polyline. // newPoint must be a layer point. // NOTE: does not support detecting intersection for degenerate cases. diff --git a/src/ext/TouchEvents.js b/src/ext/TouchEvents.js index 9f26bf5d6..be2579c1d 100644 --- a/src/ext/TouchEvents.js +++ b/src/ext/TouchEvents.js @@ -185,7 +185,7 @@ L.Map.addInitHook('addHandler', 'touchExtend', L.Map.TouchExtend); * @class L.Marker.Touch * @aka Marker.Touch * - * This isn't full Touch support. This is just to get makers to also support dom touch events after creation + * This isn't full Touch support. This is just to get markers to also support dom touch events after creation * #TODO: find a better way of getting markers to support touch. */ L.Marker.Touch = L.Marker.extend({