Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
tmuguet committed Dec 16, 2018
0 parents commit 9f91ae4
Show file tree
Hide file tree
Showing 16 changed files with 13,478 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,8 @@
{
"extends": "airbnb-base",
"rules": {
"no-underscore-dangle": "off",
"no-param-reassign": ["error", { "props": false }],
"max-len": ["error", { "code": 120 }]
}
}
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules/
coverage/
8 changes: 8 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,8 @@
{
"git.ignoreLimitWarning": true,
"prettier.eslintIntegration": true,
"prettier.printWidth": 120,
"prettier.singleQuote": true,
"prettier.tabWidth": 2,
"prettier.trailingComma": "es5"
}
16 changes: 16 additions & 0 deletions .vscode/tasks.json
@@ -0,0 +1,16 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "bundle",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Thomas Muguet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
290 changes: 290 additions & 0 deletions dist/leaflet.trackdrawer.filelayer.js
@@ -0,0 +1,290 @@
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
function corslite(url, callback, cors) {
var sent = false;

if (typeof window.XMLHttpRequest === 'undefined') {
return callback(Error('Browser not supported'));
}

if (typeof cors === 'undefined') {
var m = url.match(/^\s*https?:\/\/[^\/]*/);
cors = m && (m[0] !== location.protocol + '//' + location.hostname +
(location.port ? ':' + location.port : ''));
}

var x = new window.XMLHttpRequest();

function isSuccessful(status) {
return status >= 200 && status < 300 || status === 304;
}

if (cors && !('withCredentials' in x)) {
// IE8-9
x = new window.XDomainRequest();

// Ensure callback is never called synchronously, i.e., before
// x.send() returns (this has been observed in the wild).
// See https://github.com/mapbox/mapbox.js/issues/472
var original = callback;
callback = function() {
if (sent) {
original.apply(this, arguments);
} else {
var that = this, args = arguments;
setTimeout(function() {
original.apply(that, args);
}, 0);
}
}
}

function loaded() {
if (
// XDomainRequest
x.status === undefined ||
// modern browsers
isSuccessful(x.status)) callback.call(x, null, x);
else callback.call(x, x, null);
}

// Both `onreadystatechange` and `onload` can fire. `onreadystatechange`
// has [been supported for longer](http://stackoverflow.com/a/9181508/229001).
if ('onload' in x) {
x.onload = loaded;
} else {
x.onreadystatechange = function readystate() {
if (x.readyState === 4) {
loaded();
}
};
}

// Call the callback with the XMLHttpRequest object as an error and prevent
// it from ever being called again by reassigning it to `noop`
x.onerror = function error(evt) {
// XDomainRequest provides no evt parameter
callback.call(this, evt || true, null);
callback = function() { };
};

// IE9 must have onprogress be set to a unique function.
x.onprogress = function() { };

x.ontimeout = function(evt) {
callback.call(this, evt, null);
callback = function() { };
};

x.onabort = function(evt) {
callback.call(this, evt, null);
callback = function() { };
};

// GET is the only supported HTTP Verb by XDomainRequest and is the
// only one supported here.
x.open('GET', url, true);

// Send the request. Sending data is not supported.
x.send(null);
sent = true;

return x;
}

if (typeof module !== 'undefined') module.exports = corslite;

},{}],2:[function(_dereq_,module,exports){
(function (global){
"use strict";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null);

var corslite = _dereq_('@mapbox/corslite');

if (L.TrackDrawer === undefined) {
throw new Error('Cannot find module "L.TrackDrawer"');
}

L.TrackDrawer.Track.include({
_createFileLoader: function _createFileLoader() {
this._fileLoader = L.FileLayer.fileLoader(null, {
addToMap: false,
fileSizeLimit: this.options.fileSizeLimit || 1024,
formats: this.options.fileFormat || ['.geojson', '.json', '.kml', '.gpx']
});
},
createFileLoaderControl: function createFileLoaderControl() {
var _this = this;

this._fileLoaderController = L.Control.fileLayerLoad({
addToMap: false,
fileSizeLimit: this.options.fileSizeLimit || 1024,
formats: this.options.fileFormat || ['.geojson', '.json', '.kml', '.gpx']
}).addTo(this._map);

this._fileLoaderController.loader.on('data:loaded', function (event) {
_this._dataLoadedHandler(event.layer);
});

return this._fileLoaderController;
},
_dataLoadedHandler: function () {
var _dataLoadedHandler2 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee2(layer) {
var _this2 = this;

var oldValue, layers, lastMarker, i;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
if (this._fireEvents) {
this.fire('TrackDrawer:start', {});
}

oldValue = this._fireEvents;
this._fireEvents = false;
this.clean();
layers = layer.getLayers();
i = 0;

case 6:
if (!(i < layers.length)) {
_context2.next = 12;
break;
}

if (!(layers[i] instanceof L.Polyline)) {
_context2.next = 9;
break;
}

return _context2.delegateYield(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
var latlngs;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
latlngs = layers[i].getLatLngs();

if (!(lastMarker === undefined)) {
_context.next = 5;
break;
}

lastMarker = L.TrackDrawer.node(latlngs[0]);
_context.next = 5;
return _this2.addNode(lastMarker);

case 5:
lastMarker = L.TrackDrawer.node(latlngs[latlngs.length - 1], {
type: 'stopover'
});
_context.next = 8;
return _this2.addNode(lastMarker, function (n1, n2, cb) {
cb(null, latlngs);
});

case 8:
case "end":
return _context.stop();
}
}
}, _callee, this);
})(), "t0", 9);

case 9:
i += 1;
_context2.next = 6;
break;

case 12:
/* eslint-enable no-await-in-loop */
this._fireEvents = oldValue;
if (this._fireEvents) this.fire('TrackDrawer:done', {});

case 14:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));

return function _dataLoadedHandler(_x) {
return _dataLoadedHandler2.apply(this, arguments);
};
}(),
loadFile: function loadFile(file) {
var _this3 = this;

return new Promise(function (resolve, reject) {
_this3._fileLoader.on('data:loaded', function (event) {
_this3._dataLoadedHandler(event.layer);

_this3._fileLoader.off();

resolve();
});

_this3._fileLoader.on('data:error', function (error) {
_this3._fileLoader.off();

reject(error);
});

_this3._fileLoader.load(file);
});
},
loadUrl: function loadUrl(url) {
var _this4 = this;

var filename = url.split('/').pop();
var ext = filename.split('.').pop();
return new Promise(function (resolve, reject) {
corslite(url, function (err, resp) {
if (!err) {
try {
_this4._fileLoader.on('data:loaded', function (event) {
_this4._dataLoadedHandler(event.layer);

_this4._fileLoader.off();

resolve();
});

_this4._fileLoader.on('data:error', function (error) {
_this4._fileLoader.off();

reject(error);
});

_this4._fileLoader.loadData(resp.responseText, filename, ext);

resolve();
} catch (ex) {
reject(ex);
}
} else {
try {
var data = JSON.parse(err.responseText);
reject(new Error(data.error));
} catch (ex) {
reject(ex);
}
}
}, false);
});
}
});
L.TrackDrawer.Track.addInitHook('_createFileLoader');

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"@mapbox/corslite":1}]},{},[2]);
1 change: 1 addition & 0 deletions dist/leaflet.trackdrawer.filelayer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9f91ae4

Please sign in to comment.