diff --git a/.gitignore b/.gitignore index 78b49ee..16a336c 100644 --- a/.gitignore +++ b/.gitignore @@ -229,3 +229,7 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk + +# Others +bower_components +node_modules \ No newline at end of file diff --git a/.settings/launch.json b/.settings/launch.json new file mode 100644 index 0000000..1903b0b --- /dev/null +++ b/.settings/launch.json @@ -0,0 +1,51 @@ +{ + "version": "0.1.0", + // List of configurations. Add new configurations or edit existing ones. + // ONLY "node" and "mono" are supported, change "type" to switch. + "configurations": [ + { + // Name of configuration; appears in the launch configuration drop down menu. + "name": "Launch app.js", + // Type of configuration. Possible values: "node", "mono". + "type": "node", + // Workspace relative or absolute path to the program. + "program": "app.js", + // Automatically stop program after launch. + "stopOnEntry": true, + // Command line arguments passed to the program. + "args": [], + // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace. + "cwd": ".", + // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH. + "runtimeExecutable": null, + // Environment variables passed to the program. + "env": { } + }, + { + // Name of configuration; appears in the launch configuration drop down menu. + "name": "Launch gulp.js", + // Type of configuration. Possible values: "node", "mono". + "type": "node", + // Workspace relative or absolute path to the program. + "program": "./node_modules/gulp/bin/gulp.js", + // Automatically stop program after launch. + "stopOnEntry": true, + // Command line arguments passed to the program. + "args": ["test"], + // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace. + "cwd": ".", + // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH. + "runtimeExecutable": null, + // Environment variables passed to the program. + "env": { } + }, + { + "name": "Attach", + "type": "node", + // TCP/IP address. Default is "localhost". + "address": "localhost", + // Port to attach to. + "port": 5858 + } + ] +} diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..3df2b58 --- /dev/null +++ b/bower.json @@ -0,0 +1,17 @@ +{ + "name": "travelMap", + "version": "0.1.0", + "main": "travelmap.min.js", + "ignore": [ + ".git", + "**/*.txt", + ".settings", + "node_modules", + ".gitattributes", + ".gitignore", + "karma.conf.js" + ], + "dependencies": { + "gmaps": "~0.4.17" + } +} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..5a17791 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,38 @@ +/* jshint node:true, camelcase:false */ +var gulp = require('gulp'); +var rename = require('gulp-rename'); +var uglify = require('gulp-uglify'); +var jshint = require("gulp-jshint"); +var sourcemaps = require("gulp-sourcemaps"); +var karma = require('karma').server; + +gulp.task("test", function (done) { + karma.start({ + configFile: __dirname + '/karma.conf.js', + singleRun: true + }, done); +}); + +gulp.task('js', function () { + + return gulp.src("travelmap.js") + .pipe(sourcemaps.init()) + .pipe(uglify({ preserveComments: "some" })) + .pipe(sourcemaps.write('.')) + .pipe(rename(function (path) { + if (path.extname === '.js') { + path.basename += '.min'; + } + })) + .pipe(gulp.dest(".")); +}); + +gulp.task('lint', function () { + return gulp.src("src/*.js") + .pipe(jshint()) + .pipe(jshint.reporter('default')); +}); + +// Default should be to build the js file +gulp.task('default', ['lint', 'js'], function () { +}); \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..9bd4d8e --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,12 @@ +module.exports = function (config) { + config.set({ + browsers: ['Firefox'], + frameworks: ['jasmine'], + files: [ + 'http://maps.google.com/maps/api/js?sensor=true', + 'bower_components/gmaps/gmaps.js', + 'travelmap.js', + 'tests/**/*.js' + ] + }); +}; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..93c0881 --- /dev/null +++ b/package.json @@ -0,0 +1,50 @@ +{ + "name": "travelmap", + "version": "0.1.0", + "description": "Extension to GMaps to create a map of a trip.", + "main": "travelmap.js", + "directories": { + "test": "tests" + }, + "scripts": { + "test": "gulp tests" + }, + "repository": { + "type": "git", + "url": "https://github.com/shawnwildermuth/TravelMapJs" + }, + "keywords": [ + "Gmaps" + ], + "author": "Shawn Wildermuth", + "maintainers": [ + { + "name": "Shawn Wildermuth", + "web": "http://wildermuth.com", + "twitter": "@shawnwildermuth" + } + ], + "licenses": [ + { + "type": "MIT", + "url": "http://www.opensource.org/licenses/mit-license.php" + } + ], + "bugs": { + "url": "https://github.com/shawnwildermuth/TravelMapJs/issues" + }, + "readme": "readme.md", + "homepage": "https://github.com/shawnwildermuth/TravelMapJs", + "devDependencies": { + "gulp": "^3.8.11", + "gulp-jshint": "^1.10.0", + "gulp-rename": "^1.2.2", + "gulp-sourcemaps": "^1.5.2", + "gulp-uglify": "^1.2.0", + "jasmine-core": "^2.3.2", + "karma": "^0.12.31", + "karma-chrome-launcher": "^0.1.10", + "karma-firefox-launcher": "^0.1.6", + "karma-jasmine": "^0.3.5" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4cfdb90 --- /dev/null +++ b/readme.md @@ -0,0 +1,4 @@ +# travelMap + +This project extends the GMaps project and allow a building of map that shows a travel map. + diff --git a/tests/tests.js b/tests/tests.js new file mode 100644 index 0000000..129c0e0 --- /dev/null +++ b/tests/tests.js @@ -0,0 +1,114 @@ +// Jasmine Tests +describe("travelMap tests", function () { + + beforeAll(function () { + + // Inject a map element for testing + var div = document.createElement("div"); + div.setAttribute("id", "map"); + document.body.appendChild(div); + + }); + + it("travelMap exists", function () { + expect(travelMap).toBeDefined(); + }); + + var stops = [ + { lat: 33.748995, long: -84.387982, info: "Atlanta, Georgia - Departed Jun 3, 2014"}, + { lat: 48.856614, long: 2.352222, info: "Paris, France - Jun 4-24, 2014"}, + { lat: 50.850000, long: 4.350000, info: "Brussels, Belgium - Jun 25-27, 2014"}, + { lat: 51.209348, long: 3.224700, info: "Bruges, Belgium - Jun 28-30, 2014"}, + { lat: 48.856614, long: 2.352222, info: "Paris, France - Jun 30-July 8, 2014"}, + { lat: 51.508515, long: -0.125487, info: "London, UK - Jul 8-23, 2014"}, + { lat: 51.454513, long: -2.587910, info: "Bristol, UK - Jul 24-28, 2014"}, + { lat: 52.078000, long: -2.783000, info: "Stretton Sugwas, UK - Jul 29, 2014"}, + { lat: 51.864211, long: -2.238034, info: "Gloucestershire, UK - Jul 30, 2014"}, + { lat: 52.954783, long: -1.158109, info: "Nottingham, UK - Jul 31, 2014"}, + { lat: 51.508515, long: -0.125487, info: "London, UK - Aug 1-4, 2014"}, + { lat: 55.953252, long: -3.188267, info: "Edinburgh, UK - Aug 5, 2014"}, + { lat: 55.864237, long: -4.251806, info: "Glasgow, UK - Aug 6, 2014"}, + { lat: 57.149717, long: -2.094278, info: "Aberdeen, UK - Aug 7, 2014"}, + { lat: 55.953252, long: -3.188267, info: "Edinburgh, UK - Aug 8-9, 2014"}, + { lat: 51.508515, long: -0.125487, info: "London, UK - Aug 10-13, 2014"}, + { lat: 52.370216, long: 4.895168, info: "Amsterdam, Netherlands - Aug 14-16, 2014"}, + { lat: 48.583148, long: 7.747882, info: "Strasbourg, France - Aug 17-18, 2014"}, + { lat: 46.519962, long: 6.633597, info: "Lausanne, Switzerland - Aug 19-26, 2014"}, + { lat: 46.021073, long: 7.747937, info: "Zermatt, Switzerland - Aug 27-28, 2014"}, + { lat: 46.519962, long: 6.633597, info: "Lausanne, Switzerland - Aug 29-Sept 1, 2014"}, + { lat: 53.349805, long: -6.260310, info: "Dublin, Ireland - Sep 2-6, 2014"}, + { lat: 54.597285, long: -5.930120, info: "Belfast, Northern Ireland - Sep 7-8, 2014"}, + { lat: 53.349805, long: -6.260310, info: "Dublin, Ireland - Sep 9-15, 2014"}, + { lat: 47.368650, long: 8.539183, info: "Zurich, Switzerland - Sep 16-18, 2014"}, + { lat: 48.135125, long: 11.581981, info: "Munich, Germany - Sep 19-20, 2014"}, + { lat: 50.075538, long: 14.437800, info: "Prague, Czech Republic - Sep 21-30, 2014"}, + { lat: 51.050409, long: 13.737262, info: "Dresden, Germany - Oct 1-3, 2014"}, + { lat: 50.075538, long: 14.437800, info: "Prague, Czech Republic - Oct 4-10, 2014"}, + { lat: 42.650661, long: 18.094424, info: "Dubrovnik, Croatia - Oct 10-15, 2014"}, + { lat: 42.697708, long: 23.321868, info: "Sofia, Bulgaria - Oct 16-19, 2014"}, + { lat: 45.658928, long: 25.539608, info: "Brosov, Romania - Oct 20-31, 2014"}, + { lat: 41.005270, long: 28.976960, info: "Istanbul, Turkey - Nov 1-10, 2014"}, + { lat: 45.815011, long: 15.981919, info: "Zagreb, Croatia - Nov 11-14, 2014"}, + { lat: 41.005270, long: 28.976960, info: "Istanbul, Turkey - Nov 15-24, 2014"}, + { lat: 50.850000, long: 4.350000, info: "Brussels, Belgium - Nov 25-29, 2014"}, + { lat: 50.937531, long: 6.960279, info: "Cologne, Germany - Nov 30-Dec 3, 2014"}, + { lat: 48.208174, long: 16.373819, info: "Vienna, Austria - Dec 4-27, 2014"}, + { lat: 47.497912, long: 19.040235, info: "Budapest, Hungary - Dec 28,2014 - Jan 2, 2015"}, + { lat: 37.983716, long: 23.729310, info: "Athens, Greece - Jan 2-18, 2015"}, + { lat: -25.746111, long: 28.188056, info: "Pretoria, South Africa - Jan 19-31, 2015"}, + { lat: 43.771033, long: 11.248001, info: "Florence, Italy - Feb 1-8, 2015"}, + { lat: 45.440847, long: 12.315515, info: "Venice, Italy - Feb 9-12, 2015"}, + { lat: 43.771033, long: 11.248001, info: "Florence, Italy - Feb 13-16, 2015"}, + { lat: 41.872389, long: 12.480180, info: "Rome, Italy - Feb 17-Mar 3, 2015"}, + { lat: 28.632244, long: 77.220724, info: "New Delhi, India - Mar 4-9, 2015"}, + { lat: 27.700000, long: 85.333333, info: "Kathmandu, Nepal - Mar 10-Mar 13, 2015"}, + { lat: 28.632244, long: 77.220724, info: "New Delhi, India - Mar 11-20, 2015"}, + { lat: 22.1667, long: 113.5500, info: "Macau - Mar 21-23, 2015"}, + { lat: 22.396428, long: 114.109497, info: "Hong Kong - Mar 24-Apr 18, 2015"}, + { lat: 39.904030, long: 116.407526, info: "Beijing, China - Apr 19-23, 2015"}, + { lat: 22.396428, long: 114.109497, info: "Hong Kong - Apr 24-29, 2015"}, + { lat: 1.352083, long: 103.819836, info: "Singapore - Apr 30-May 6, 2015"}, + { lat: 3.139003, long: 101.686855, info: "Kuala Lumpor, Malaysia - May 7-23, 2015"}, + { lat: 13.727896, long: 100.524123, info: "Bangkok, Thailand - May 24-28, 2015"}, + { lat: 14.599512, long: 120.984219, info: "Manila, Philippines - May 29-31, 2015"}, + { lat: 13.727896, long: 100.524123, info: "Bangkok, Thailand - Jun 1-Jun 6, 2015"}, + { lat: 13.413227, long: 103.865991, info: "Ankor Wat, Cambodia - Jun 7-10, 2015"}, + { lat: 13.727896, long: 100.524123, info: "Bangkok, Thailand - Jun 11-16, 2015"}, + { lat: 37.566535, long: 126.977969, info: "Seoul, S. Korea - June 17-30, 2015"}, + { lat: 35.689487, long: 139.691706, info: "Toyko, Japan - July 1-31, 2015"}, + { lat: 47.606209, long: -122.332071, info: "Seattle, WA - Aug 1-3, 2015"}, + { lat: 49.282729, long: -123.120738, info: "Vancouver, BC Canada - Aug 4, 2015"}, + { lat: 47.606209, long: -122.332071, info: "Seattle, WA - Aug 5-7, 2015"}, + { lat: 45.523062, long: -122.676482, info: "Portland, OR - Aug 8-10, 2015"}, + { lat: 37.774929, long: -122.419416, info: "San Francisco, CA - Aug 11-15, 2015"}, + { lat: 33.448377, long: -112.074037, info: "Phoenix, AZ - Aug 16-19, 2015"}, + { lat: 39.739236, long: -104.990251, info: "Denver, CO - Aug 20-22, 2015"}, + { lat: 38.627003, long: -90.199404, info: "St. Louis, MO - Aug 23-24, 2015"}, + { lat: 41.878114, long: -87.629798, info: "Chicago, IL - Aug 25-30, 2015"}, + { lat: 43.653226, long: -79.383184, info: "Toronto, ON Canada - Aug 30-Sep 2, 2015"}, + { lat: 42.360082, long: -71.058880, info: "Boston, MA - Sep 3-8, 2015"}, + { lat: 41.355654, long: -72.099521, info: "New London, CT - Sep 9, 2015"}, + { lat: 40.712784, long: -74.005941, info: "New York, NY - Sep 10-14, 2015"}, + { lat: 39.952584, long: -75.165222, info: "Philadelphia, PA - Sep 15-16, 2015"}, + { lat: 38.907192, long: -77.036871, info: "Washington, DC - Sep 17-21, 2015"}, + { lat: 37.540725, long: -77.436048, info: "Richmond, VA - Sep 22-23, 2015"}, + { lat: 35.779590, long: -78.638179, info: "Raleigh, NC - Sep 24-25, 2015"}, + { lat: 35.227087, long: -80.843127, info: "Charlotte, SC - Sep 26-27, 2015"}, + { lat: 34.852618, long: -82.394010, info: "Greenville, SC - Sep 28-29, 2015"}, + { lat: 34.625584, long: -83.793334, info: "North Georgia Mountains, GA - Sept 30, 2015"}, + { lat: 33.748995, long: -84.387982, info: "Atlanta, GA - August 1, 2015"} + ]; + + it("travelMap default creation", function () { + + var map = travelMap.createMap({ + stops: stops, + selector: "#map" + }); + expect(map).toBeDefined(); + expect(map.map).toBeDefined(); + expect(map.settings).toBeDefined(); + expect(map.currentLocation).toBeDefined(); + + }); +}); \ No newline at end of file diff --git a/travelmap.js b/travelmap.js new file mode 100644 index 0000000..d031c2e --- /dev/null +++ b/travelmap.js @@ -0,0 +1,170 @@ +//! travelmap.js +//! version : 0.01.0 +//! authors : Shawn Wildermuth +//! license : MIT + +// Build support for AMD or simple global (borrowed pattern from moment.js) +(function () { + + "use strict"; + + // travelMap object + var _travelMap = {}; + + var _defaultOptions = { + stops: [], + currentStop: 0, + selector: "#map", + iconUrl: "http://wildermuth.com/", + initialZoom: 4, + pastStroke: { + color: '#190300', + opacity: 0.5, + weight: 2 + }, + futureStroke: { + color: '#D30000', + opacity: 0.6, + weight: 2 + } + }; + + + _travelMap.createMap = function (options) { + + var map; + var settings = _extend(options, _defaultOptions); + + if (!settings.stops || settings.stops.length == 0) { + throw "You must supply stops when creating a map."; + } + + // calculate past, future and current stops + var pastLines = settings.stops.slice(0, settings.currentStop + 1); + var futureLines = settings.stops.slice(settings.currentStop, settings.stops.length); + var currentLocation = settings.stops[settings.currentStop]; + + _initStyle(); + + // Require GMaps and Google Maps API + if (!(typeof window.GMaps === 'function' && window.GMaps)) { + console.log('GMaps (and Google Maps API) is required. Please register the following JavaScript library https://hpneo.github.io/gmaps/documentation.html'); + } + + map = new GMaps({ + div: settings.selector, + lat: currentLocation.lat, + lng: currentLocation.long, + zoom: settings.initialZoom + }); + + map.map.setOptions({ + draggable: true, + scrollwheel: false, + disableDoubleClickZoom: true, + zoomControl: true + }); + + // Past Lines + map.drawPolyline({ + path: _toLatLongCollection(pastLines), + strokeColor: settings.pastStroke.color, + strokeOpacity: settings.pastStroke.opacity, + strokeWeight: settings.pastStroke.weight + }); + + // Future Lines + map.drawPolyline({ + path: _toLatLongCollection(futureLines), + strokeColor: settings.futureStroke.color, + strokeOpacity: settings.futureStroke.opacity, + strokeWeight: settings.futureStroke.weight + }); + + for (var i = 0; i < settings.stops.length; ++i) { + var stop = settings.stops[i]; + if (i != settings.currentStop) { + map.addMarker({ + lat: stop.lat, + lng: stop.long, + icon: settings.iconUrl, + infoWindow: { content: stop.info }, + anchorPoint: { x: 3, y: 3 } + }); + } + } + + map.drawOverlay({ + lat: currentLocation.lat, + lng: currentLocation.long, + content: '
Current Location
' + currentLocation.info + '
', + verticalAlign: 'top', + horizontalAlign: 'center', + layer: "overlayImage" + }); + + return { + map: map, + settings: settings, + currentLocation: currentLocation + }; + }; + + var _toLatLong = function (stop) { + return [ stop.lat, stop.long ]; + }; + + var _toLatLongCollection = function (stops) { + var collection = []; + for (var x = 0; x < stops.length; ++x) { + collection.push(_toLatLong(stops[x])); + } + + return collection; + }; + + var _initStyle = function () { + + var stopStyle = ".stopName { background: none repeat scroll 0 0 #222; width: 4px; height: 4px; }" + + ".gm-style-iw{ overflow: hidden !important; }"; + + var style = document.createElement("style"); + style.innerHTML = stopStyle; + document.head.appendChild(style); + }; + + var _extend = function (base, defaults) { + + var extended = defaults; + + // Extend options with defaults + for (var key in base) { + if (base.hasOwnProperty(key)) { + if (base[key] !== undefined) { + extended[key] = base[key]; + } + } + } + + return extended; + + }; + + // Expose it as a public + if (typeof exports !== 'undefined') { + if (typeof module !== 'undefined' && module.exports) { + exports = module.exports = _travelMap; + } + exports.travelMap = _travelMap; + } else { + this.travelMap = _travelMap; + } + + // AMD registration + if (typeof define === 'function' && define.amd) { + define('travelMap', [], function () { + return _travelMap; + }); + } + +}.call(this)); \ No newline at end of file diff --git a/travelmap.js.map b/travelmap.js.map new file mode 100644 index 0000000..f4b8fa5 --- /dev/null +++ b/travelmap.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["travelmap.js"],"names":["_travelMap","_defaultOptions","stops","currentStop","selector","iconUrl","initialZoom","pastStroke","color","opacity","weight","futureStroke","createMap","options","map","settings","_extend","length","pastLines","slice","futureLines","currentLocation","_initStyle","window","GMaps","console","log","div","lat","lng","zoom","setOptions","draggable","scrollwheel","disableDoubleClickZoom","zoomControl","drawPolyline","path","_toLatLongCollection","strokeColor","strokeOpacity","strokeWeight","i","stop","addMarker","icon","infoWindow","content","info","anchorPoint","x","y","drawOverlay","verticalAlign","horizontalAlign","layer","_toLatLong","collection","push","stopStyle","style","document","createElement","innerHTML","head","appendChild","base","defaults","extended","key","hasOwnProperty","undefined","exports","module","travelMap","this","define","amd","call"],"mappings":";;;;CAMC,WAEC,YAGA,IAAIA,MAEAC,GACFC,SACAC,YAAa,EACbC,SAAU,OACVC,QAAS,yBACTC,YAAa,EACbC,YACEC,MAAO,UACPC,QAAS,GACTC,OAAQ,GAEVC,cACEH,MAAO,UACPC,QAAS,GACTC,OAAQ,GAKZV,GAAWY,UAAY,SAAUC,GAE/B,GAAIC,GACAC,EAAWC,EAAQH,EAASZ,EAEhC,KAAKc,EAASb,OAAkC,GAAzBa,EAASb,MAAMe,OACpC,KAAM,4CAIR,IAAIC,GAAYH,EAASb,MAAMiB,MAAM,EAAGJ,EAASZ,YAAc,GAC3DiB,EAAcL,EAASb,MAAMiB,MAAMJ,EAASZ,YAAaY,EAASb,MAAMe,QACxEI,EAAkBN,EAASb,MAAMa,EAASZ,YAE9CmB,KAG8B,kBAAjBC,QAAOC,OAAwBD,OAAOC,OACjDC,QAAQC,IAAI,8IAGdZ,EAAM,GAAIU,QACRG,IAAKZ,EAASX,SACdwB,IAAKP,EAAgBO,IACrBC,IAAKR,EAAAA,QACLS,KAAMf,EAAST,cAGjBQ,EAAIA,IAAIiB,YACNC,WAAW,EACXC,aAAa,EACbC,wBAAwB,EACxBC,aAAa,IAIfrB,EAAIsB,cACFC,KAAMC,EAAqBpB,GAC3BqB,YAAaxB,EAASR,WAAWC,MACjCgC,cAAezB,EAASR,WAAWE,QACnCgC,aAAc1B,EAASR,WAAWG,SAIpCI,EAAIsB,cACFC,KAAMC,EAAqBlB,GAC3BmB,YAAaxB,EAASJ,aAAaH,MACnCgC,cAAezB,EAASJ,aAAaF,QACrCgC,aAAc1B,EAASJ,aAAaD,QAGtC,KAAK,GAAIgC,GAAI,EAAGA,EAAI3B,EAASb,MAAMe,SAAUyB,EAAG,CAC9C,GAAIC,GAAO5B,EAASb,MAAMwC,EACtBA,IAAK3B,EAASZ,aAChBW,EAAI8B,WACFhB,IAAKe,EAAKf,IACVC,IAAKc,EAAAA,QACLE,KAAM9B,EAASV,QACfyC,YAAcC,QAASJ,EAAKK,MAC5BC,aAAeC,EAAG,EAAGC,EAAG,KAc9B,MATArC,GAAIsC,aACFxB,IAAKP,EAAgBO,IACrBC,IAAKR,EAAAA,QACL0B,QAAS,6CAA+C1B,EAAgB2B,KAAO,gDAC/EK,cAAe,MACfC,gBAAiB,SACjBC,MAAO,kBAIPzC,IAAKA,EACLC,SAAUA,EACVM,gBAAiBA,GAIrB,IAAImC,GAAa,SAAUb,GACzB,OAASA,EAAKf,IAAKe,EAAAA,UAGjBL,EAAuB,SAAUpC,GAEnC,IAAK,GADDuD,MACKP,EAAI,EAAGA,EAAIhD,EAAMe,SAAUiC,EAClCO,EAAWC,KAAKF,EAAWtD,EAAMgD,IAGnC,OAAOO,IAGLnC,EAAa,WAEf,GAAIqC,GAAY,8HAGZC,EAAQC,SAASC,cAAc,QACnCF,GAAMG,UAAYJ,EAClBE,SAASG,KAAKC,YAAYL,IAGxB5C,EAAU,SAAUkD,EAAMC,GAE5B,GAAIC,GAAWD,CAGf,KAAK,GAAIE,KAAOH,GACVA,EAAKI,eAAeD,IACJE,SAAdL,EAAKG,KACPD,EAASC,GAAOH,EAAKG,GAK3B,OAAOD,GAKc,oBAAZI,UACa,mBAAXC,SAA0BA,OAAOD,UAC1CA,QAAUC,OAAOD,QAAUxE,GAE7BwE,QAAQE,UAAY1E,GAEpB2E,KAAKD,UAAY1E,EAIG,kBAAX4E,SAAyBA,OAAOC,KACzCD,OAAO,eAAiB,WACtB,MAAO5E,OAIX8E,KAAKH","file":"travelmap.js","sourcesContent":["//! travelmap.js\r\n//! version : 0.01.0\r\n//! authors : Shawn Wildermuth\r\n//! license : MIT\r\n\r\n// Build support for AMD or simple global (borrowed pattern from moment.js)\r\n(function () {\r\n\r\n \"use strict\";\r\n\r\n // travelMap object\r\n var _travelMap = {};\r\n\r\n var _defaultOptions = {\r\n stops: [],\r\n currentStop: 0,\r\n selector: \"#map\",\r\n iconUrl: \"http://wildermuth.com/\",\r\n initialZoom: 4,\r\n pastStroke: {\r\n color: '#190300',\r\n opacity: 0.5,\r\n weight: 2\r\n },\r\n futureStroke: {\r\n color: '#D30000',\r\n opacity: 0.6,\r\n weight: 2\r\n }\r\n };\r\n\r\n\r\n _travelMap.createMap = function (options) {\r\n\r\n var map;\r\n var settings = _extend(options, _defaultOptions);\r\n\r\n if (!settings.stops || settings.stops.length == 0) {\r\n throw \"You must supply stops when creating a map.\";\r\n }\r\n\r\n // calculate past, future and current stops\r\n var pastLines = settings.stops.slice(0, settings.currentStop + 1);\r\n var futureLines = settings.stops.slice(settings.currentStop, settings.stops.length);\r\n var currentLocation = settings.stops[settings.currentStop];\r\n\r\n _initStyle();\r\n\r\n // Require GMaps and Google Maps API\r\n if (!(typeof window.GMaps === 'function' && window.GMaps)) {\r\n console.log('GMaps (and Google Maps API) is required. Please register the following JavaScript library https://hpneo.github.io/gmaps/documentation.html');\r\n }\r\n\r\n map = new GMaps({\r\n div: settings.selector,\r\n lat: currentLocation.lat,\r\n lng: currentLocation.long,\r\n zoom: settings.initialZoom\r\n });\r\n\r\n map.map.setOptions({\r\n draggable: true,\r\n scrollwheel: false,\r\n disableDoubleClickZoom: true,\r\n zoomControl: true\r\n });\r\n\r\n // Past Lines\r\n map.drawPolyline({\r\n path: _toLatLongCollection(pastLines),\r\n strokeColor: settings.pastStroke.color,\r\n strokeOpacity: settings.pastStroke.opacity,\r\n strokeWeight: settings.pastStroke.weight\r\n });\r\n\r\n // Future Lines\r\n map.drawPolyline({\r\n path: _toLatLongCollection(futureLines),\r\n strokeColor: settings.futureStroke.color,\r\n strokeOpacity: settings.futureStroke.opacity,\r\n strokeWeight: settings.futureStroke.weight\r\n });\r\n\r\n for (var i = 0; i < settings.stops.length; ++i) {\r\n var stop = settings.stops[i];\r\n if (i != settings.currentStop) {\r\n map.addMarker({\r\n lat: stop.lat,\r\n lng: stop.long,\r\n icon: settings.iconUrl,\r\n infoWindow: { content: stop.info },\r\n anchorPoint: { x: 3, y: 3 }\r\n });\r\n }\r\n }\r\n\r\n map.drawOverlay({\r\n lat: currentLocation.lat,\r\n lng: currentLocation.long,\r\n content: '
Current Location
' + currentLocation.info + '
',\r\n verticalAlign: 'top',\r\n horizontalAlign: 'center',\r\n layer: \"overlayImage\"\r\n });\r\n\r\n return {\r\n map: map,\r\n settings: settings,\r\n currentLocation: currentLocation\r\n };\r\n };\r\n\r\n var _toLatLong = function (stop) {\r\n return [ stop.lat, stop.long ];\r\n };\r\n\r\n var _toLatLongCollection = function (stops) {\r\n var collection = [];\r\n for (var x = 0; x < stops.length; ++x) {\r\n collection.push(_toLatLong(stops[x]));\r\n }\r\n \r\n return collection;\r\n };\r\n\r\n var _initStyle = function () {\r\n\r\n var stopStyle = \".stopName { background: none repeat scroll 0 0 #222; width: 4px; height: 4px; }\" +\r\n \".gm-style-iw{ overflow: hidden !important; }\";\r\n\r\n var style = document.createElement(\"style\");\r\n style.innerHTML = stopStyle;\r\n document.head.appendChild(style);\r\n };\r\n\r\n var _extend = function (base, defaults) {\r\n\r\n var extended = defaults;\r\n \r\n // Extend options with defaults\r\n for (var key in base) {\r\n if (base.hasOwnProperty(key)) {\r\n if (base[key] !== undefined) {\r\n extended[key] = base[key];\r\n }\r\n }\r\n }\r\n\r\n return extended;\r\n\r\n };\r\n\r\n // Expose it as a public\r\n if (typeof exports !== 'undefined') {\r\n if (typeof module !== 'undefined' && module.exports) {\r\n exports = module.exports = _travelMap;\r\n }\r\n exports.travelMap = _travelMap;\r\n } else {\r\n this.travelMap = _travelMap;\r\n }\r\n\r\n // AMD registration \r\n if (typeof define === 'function' && define.amd) {\r\n define('travelMap', [], function () {\r\n return _travelMap;\r\n });\r\n }\r\n\r\n}.call(this));"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/travelmap.min.js b/travelmap.min.js new file mode 100644 index 0000000..1ecdefa --- /dev/null +++ b/travelmap.min.js @@ -0,0 +1,6 @@ +//! travelmap.js +//! version : 0.01.0 +//! authors : Shawn Wildermuth +//! license : MIT +(function(){"use strict";var t={},o={stops:[],currentStop:0,selector:"#map",iconUrl:"http://wildermuth.com/",initialZoom:4,pastStroke:{color:"#190300",opacity:.5,weight:2},futureStroke:{color:"#D30000",opacity:.6,weight:2}};t.createMap=function(t){var e,i=a(t,o);if(!i.stops||0==i.stops.length)throw"You must supply stops when creating a map.";var l=i.stops.slice(0,i.currentStop+1),s=i.stops.slice(i.currentStop,i.stops.length),p=i.stops[i.currentStop];n(),"function"==typeof window.GMaps&&window.GMaps||console.log("GMaps (and Google Maps API) is required. Please register the following JavaScript library https://hpneo.github.io/gmaps/documentation.html"),e=new GMaps({div:i.selector,lat:p.lat,lng:p["long"],zoom:i.initialZoom}),e.map.setOptions({draggable:!0,scrollwheel:!1,disableDoubleClickZoom:!0,zoomControl:!0}),e.drawPolyline({path:r(l),strokeColor:i.pastStroke.color,strokeOpacity:i.pastStroke.opacity,strokeWeight:i.pastStroke.weight}),e.drawPolyline({path:r(s),strokeColor:i.futureStroke.color,strokeOpacity:i.futureStroke.opacity,strokeWeight:i.futureStroke.weight});for(var c=0;cCurrent Location
'+p.info+'
',verticalAlign:"top",horizontalAlign:"center",layer:"overlayImage"}),{map:e,settings:i,currentLocation:p}};var e=function(t){return[t.lat,t["long"]]},r=function(t){for(var o=[],r=0;r