diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e677eb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.build +.build* diff --git a/HISTORY.md b/HISTORY.md new file mode 100644 index 0000000..5c24be5 --- /dev/null +++ b/HISTORY.md @@ -0,0 +1,3 @@ +## 2.1.4 + +* First public version. diff --git a/README.md b/README.md new file mode 100644 index 0000000..96c467c --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# pauloborges:mapbox + +Mapbox.js for [Meteor](https://www.meteor.com/) apps. Current Mapbox version: `2.1.4`. + +## Install + + $ cd to/my/meteor/project + $ meteor add pauloborges:mapbox@2.1.4 + +or (if you want to modify the code): + + $ cd to/my/meteor/project + $ mkdir packages # ensure that packages folder exists + $ git clone https://github.com/pauloborges/meteor-mapbox.git packages/mapbox + $ meteor add mapbox + +## Supported plugins + +All plugins listed [here](https://www.mapbox.com/mapbox.js/plugins/) are +supported: + +* [directions](https://www.mapbox.com/mapbox.js/plugins/#mapbox-directions) +* [zoomslider](https://www.mapbox.com/mapbox.js/plugins/#leaflet-zoomslider) +* [pip](https://www.mapbox.com/mapbox.js/plugins/#point-in-polygon) +* [osm](https://www.mapbox.com/mapbox.js/plugins/#leaflet-osm) +* [omnivore](https://www.mapbox.com/mapbox.js/plugins/#leaflet-omnivore) +* [minimap](https://www.mapbox.com/mapbox.js/plugins/#leaflet-minimap) +* [markercluster](https://www.mapbox.com/mapbox.js/plugins/#leaflet-markercluster) +* [locate](https://www.mapbox.com/mapbox.js/plugins/#leaflet-locatecontrol) +* [label](https://www.mapbox.com/mapbox.js/plugins/#leaflet-label) +* [image](https://www.mapbox.com/mapbox.js/plugins/#leaflet-image) +* [heat](https://www.mapbox.com/mapbox.js/plugins/#leaflet-heat) +* [hash](https://www.mapbox.com/mapbox.js/plugins/#leaflet-hash) +* [geodesy](https://www.mapbox.com/mapbox.js/plugins/#leaflet-geodesy) +* [fullscreen](https://www.mapbox.com/mapbox.js/plugins/#leaflet-fullscreen) +* [draw](https://www.mapbox.com/mapbox.js/plugins/#leaflet-draw) +* [geojsonExtend](https://www.mapbox.com/mapbox.js/plugins/#static-map-from-geojson-with-geo-viewport) +* [geoViewport](https://www.mapbox.com/mapbox.js/plugins/#static-map-from-bounds-with-geo-viewport) +* [arc](https://www.mapbox.com/mapbox.js/plugins/#arcjs) + +## Usage + +Call `Mapbox.load(pluginList)` in your client code. Use `Mapbox.loaded()` to +check if it finished loading. This function is reactive. + +### Example + + Mapbox.load('minimap', 'markercluster'); + + Deps.autorun(function () { + if (Mapbox.loaded()) { + L.mapbox.accessToken = MY_ACCESS_TOKEN; + var map = L.mapbox.map('map', MY_MAP_ID); + } + }); diff --git a/mapbox.css b/mapbox.css new file mode 100644 index 0000000..89eca3d --- /dev/null +++ b/mapbox.css @@ -0,0 +1,32 @@ +/* Copyright (c) 2014 Paulo Sérgio Borges de Oliveira Filho + * + * 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. + */ + +body { + margin: 0; + padding: 0; +} + +#map.mapbox { + position: absolute; + top: 0; + bottom: 0; + width: 100%; +} diff --git a/mapbox.js b/mapbox.js new file mode 100644 index 0000000..6902a9e --- /dev/null +++ b/mapbox.js @@ -0,0 +1,221 @@ +/* Copyright (c) 2014 Paulo Sérgio Borges de Oliveira Filho + * + * 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. + */ + +var FILES = { + mapbox: { + js: ['https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.js'], + css: ['https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.css'], + }, + + directions: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/mapbox-directions.js/v0.0.1/mapbox.directions.js'], + css: ['https://api.tiles.mapbox.com/mapbox.js/plugins/mapbox-directions.js/v0.0.1/mapbox.directions.css'] + }, + + zoomslider: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-zoomslider/v0.7.0/L.Control.Zoomslider.js'], + css: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-zoomslider/v0.7.0/L.Control.Zoomslider.css'] + }, + + pip: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-pip/v0.0.2/leaflet-pip.js'], + css: [] + }, + + osm: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-osm/v0.1.0/leaflet-osm.js'], + css: [] + }, + + omnivore: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.2.0/leaflet-omnivore.min.js'], + css: [] + }, + + minimap: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-minimap/v1.0.0/Control.MiniMap.js'], + css: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-minimap/v1.0.0/Control.MiniMap.css'] + }, + + markercluster: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/leaflet.markercluster.js'], + css: [ + 'https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.css', + 'https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.Default.css' + ], + }, + + // FIXME: Doesn't support IE<9 + // https://www.mapbox.com/mapbox.js/example/v1.0.0/leaflet-locatecontrol/ + locate: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-locatecontrol/v0.24.0/L.Control.Locate.js'], + css: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-locatecontrol/v0.24.0/L.Control.Locate.css'] + }, + + label: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-label/v0.2.1/leaflet.label.js'], + css: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-label/v0.2.1/leaflet.label.css'] + }, + + image: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-image/v0.0.4/leaflet-image.js'], + css: [] + }, + + heat: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-heat/v0.1.0/leaflet-heat.js'], + css: [] + }, + + hash: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-hash/v0.2.1/leaflet-hash.js'], + css: [] + }, + + geodesy: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-geodesy/v0.1.0/leaflet-geodesy.js'], + css: [] + }, + + fullscreen: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v0.0.3/Leaflet.fullscreen.min.js'], + css: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v0.0.3/leaflet.fullscreen.css'] + }, + + draw: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-draw/v0.2.2/leaflet.draw.js'], + css: ['https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-draw/v0.2.2/leaflet.draw.css'] + }, + + geojsonExtend: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/geojson-extent/v0.0.1/geojson-extent.js'], + css: [] + }, + + geoViewport: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/geo-viewport/v0.1.1/geo-viewport.js'], + css: [] + }, + + arc: { + js: ['https://api.tiles.mapbox.com/mapbox.js/plugins/arc.js/v0.1.0/arc.js'], + css: [] + } +}; + +var deps = new Deps.Dependency; +var loaded = false; + +var loadCount = 0; +var loadCallback = null; + +var pluginCount = 0; +var plugins = null; + +var onLoaded = function () { + loaded = true; + deps.changed(); +}; + +var onPluginLoaded = function () { + pluginCount--; + + if (pluginCount == 0) + onLoaded(); +}; + +var onMapboxLoaded = function () { + pluginCount = _.size(plugins); + + if (pluginCount == 0) { + onLoaded(); + return; + } + + _.each(plugins, function (pluginName) { + var plugin = FILES[pluginName]; + + if (plugin) + loadFiles(plugin, onPluginLoaded); + else + console.log('Invalid MapBox plugin: "' + pluginName + '"'); + }); +}; + +var onLoadedFile = function (url) { + if (Mapbox.debug) + console.log('Loaded "' + url + '"'); + + loadCount--; + + if (loadCount == 0) + loadCallback(); +}; + +var loadScript = function (src) { + var elem = document.createElement('script'); + elem.type = 'text/javascript'; + elem.src = src; + elem.defer = true; + + elem.addEventListener('load', _.partial(onLoadedFile, src), false); + + var head = document.getElementsByTagName('head')[0]; + head.appendChild(elem); +}; + +var loadCss = function (href) { + var elem = document.createElement('link'); + elem.rel = 'stylesheet'; + elem.href = href; + + elem.addEventListener('load', _.partial(onLoadedFile, href), false); + + var head = document.getElementsByTagName('head')[0]; + head.appendChild(elem); +}; + +var loadFiles = function (files, cb) { + loadCount = _.size(files.js) + _.size(files.css); + loadCallback = cb; + + _.each(files.js, function (url) { + loadScript(url); + }); + + _.each(files.css, function (url) { + loadCss(url); + }); +}; + +Mapbox = { + debug: false, + + load: function () { + plugins = _.values(arguments); + loadFiles(FILES.mapbox, onMapboxLoaded); + }, + + loaded: function () { + deps.depend(); + return loaded; + } +}; diff --git a/package.js b/package.js new file mode 100644 index 0000000..f1d3eff --- /dev/null +++ b/package.js @@ -0,0 +1,36 @@ +/* Copyright (c) 2014 Paulo Sérgio Borges de Oliveira Filho + * + * 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. + */ + +Package.describe({ + name: 'pauloborges:mapbox', + summary: 'Mapbox.js for Meteor apps', + version: '2.1.4', + git: 'https://github.com/pauloborges/meteor-mapbox.git' +}); + +Package.onUse(function (api) { + api.versionsFrom('METEOR@1.0'); + api.use(['deps', 'underscore'], ['client']); + + api.addFiles(['mapbox.js', 'mapbox.css'], ['client']); + + api.export('Mapbox', ['client']); +}); diff --git a/versions.json b/versions.json new file mode 100644 index 0000000..68d89cd --- /dev/null +++ b/versions.json @@ -0,0 +1,23 @@ +{ + "dependencies": [ + [ + "deps", + "1.0.5" + ], + [ + "meteor", + "1.1.3" + ], + [ + "tracker", + "1.0.3" + ], + [ + "underscore", + "1.0.1" + ] + ], + "pluginDependencies": [], + "toolVersion": "meteor-tool@1.0.35", + "format": "1.0" +} \ No newline at end of file