Skip to content

Commit

Permalink
commonjs support
Browse files Browse the repository at this point in the history
  • Loading branch information
zverev committed Nov 9, 2015
1 parent b2cab55 commit f7bfcf0
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 99 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bower_components
*.sublime-project
*.sublime-workspace
dist
*_bundle.js
19 changes: 19 additions & 0 deletions examples/browserify.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Leflet-IconLayers demo</title>
<script src="browserify_bundle.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css">
<link rel="stylesheet" href="../src/iconLayers.css">
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
</body>
</html>
22 changes: 22 additions & 0 deletions examples/browserify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var L = require('leaflet');
var providers = require('./providers');
var iconLayers = require('../src/iconLayers');

window.addEventListener('load', function() {
var map = L.map(document.body).setView([38.14, 19.33], 7);

var layers = [];
for (var providerId in providers) {
layers.push(providers[providerId]);
}

layers.push({
layer: {
onAdd: function() {},
onRemove: function() {}
},
title: 'empty'
})

var ctrl = iconLayers(layers).addTo(map);
});
194 changes: 102 additions & 92 deletions examples/providers.js
Original file line number Diff line number Diff line change
@@ -1,101 +1,111 @@
var providers = {};
(function(factory) {
if (typeof module !== 'undefined' && module.exports) {
module.exports = factory(require('leaflet'));
} else {
window.providers = factory(window.L);
}
})(function(L) {
var providers = {};

providers['OpenStreetMap_Mapnik'] = {
title: 'osm',
icon: 'icons/openstreetmap_mapnik.png',
layer: L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
})
};
providers['OpenStreetMap_Mapnik'] = {
title: 'osm',
icon: 'icons/openstreetmap_mapnik.png',
layer: L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
})
};

providers['OpenStreetMap_BlackAndWhite'] = {
title: 'osm bw',
icon: 'icons/openstreetmap_blackandwhite.png',
layer: L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
})
};
providers['OpenStreetMap_BlackAndWhite'] = {
title: 'osm bw',
icon: 'icons/openstreetmap_blackandwhite.png',
layer: L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
})
};

providers['OpenStreetMap_DE'] = {
title: 'osm de',
icon: 'icons/openstreetmap_de.png',
layer: L.tileLayer('http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
})
}
providers['OpenStreetMap_DE'] = {
title: 'osm de',
icon: 'icons/openstreetmap_de.png',
layer: L.tileLayer('http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
})
}

providers['Stamen_Toner'] = {
title: 'toner',
icon: 'icons/stamen_toner.png',
layer: L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.png', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: 'abcd',
minZoom: 0,
maxZoom: 20,
ext: 'png'
})
};
providers['Stamen_Toner'] = {
title: 'toner',
icon: 'icons/stamen_toner.png',
layer: L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.png', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: 'abcd',
minZoom: 0,
maxZoom: 20,
ext: 'png'
})
};

providers['Esri_OceanBasemap'] = {
title: 'esri ocean',
icon: 'icons/esri_oceanbasemap.png',
layer: L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles &copy; Esri &mdash; Sources: GEBCO, NOAA, CHS, OSU, UNH, CSUMB, National Geographic, DeLorme, NAVTEQ, and Esri',
maxZoom: 13
})
};
providers['Esri_OceanBasemap'] = {
title: 'esri ocean',
icon: 'icons/esri_oceanbasemap.png',
layer: L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles &copy; Esri &mdash; Sources: GEBCO, NOAA, CHS, OSU, UNH, CSUMB, National Geographic, DeLorme, NAVTEQ, and Esri',
maxZoom: 13
})
};

providers['HERE_normalDay'] = {
title: 'normalday',
icon: 'icons/here_normalday.png',
layer: L.tileLayer('http://{s}.{base}.maps.cit.api.here.com/maptile/2.1/maptile/{mapID}/normal.day/{z}/{x}/{y}/256/png8?app_id={app_id}&app_code={app_code}', {
attribution: 'Map &copy; 1987-2014 <a href="http://developer.here.com">HERE</a>',
subdomains: '1234',
mapID: 'newest',
app_id: 'Y8m9dK2brESDPGJPdrvs',
app_code: 'dq2MYIvjAotR8tHvY8Q_Dg',
base: 'base',
maxZoom: 20
})
};
providers['HERE_normalDay'] = {
title: 'normalday',
icon: 'icons/here_normalday.png',
layer: L.tileLayer('http://{s}.{base}.maps.cit.api.here.com/maptile/2.1/maptile/{mapID}/normal.day/{z}/{x}/{y}/256/png8?app_id={app_id}&app_code={app_code}', {
attribution: 'Map &copy; 1987-2014 <a href="http://developer.here.com">HERE</a>',
subdomains: '1234',
mapID: 'newest',
app_id: 'Y8m9dK2brESDPGJPdrvs',
app_code: 'dq2MYIvjAotR8tHvY8Q_Dg',
base: 'base',
maxZoom: 20
})
};

providers['HERE_normalDayGrey'] = {
title: 'normalday grey',
icon: 'icons/here_normaldaygrey.png',
layer: L.tileLayer('http://{s}.{base}.maps.cit.api.here.com/maptile/2.1/maptile/{mapID}/normal.day.grey/{z}/{x}/{y}/256/png8?app_id={app_id}&app_code={app_code}', {
attribution: 'Map &copy; 1987-2014 <a href="http://developer.here.com">HERE</a>',
subdomains: '1234',
mapID: 'newest',
app_id: 'Y8m9dK2brESDPGJPdrvs',
app_code: 'dq2MYIvjAotR8tHvY8Q_Dg',
base: 'base',
maxZoom: 20
})
};
providers['HERE_normalDayGrey'] = {
title: 'normalday grey',
icon: 'icons/here_normaldaygrey.png',
layer: L.tileLayer('http://{s}.{base}.maps.cit.api.here.com/maptile/2.1/maptile/{mapID}/normal.day.grey/{z}/{x}/{y}/256/png8?app_id={app_id}&app_code={app_code}', {
attribution: 'Map &copy; 1987-2014 <a href="http://developer.here.com">HERE</a>',
subdomains: '1234',
mapID: 'newest',
app_id: 'Y8m9dK2brESDPGJPdrvs',
app_code: 'dq2MYIvjAotR8tHvY8Q_Dg',
base: 'base',
maxZoom: 20
})
};

providers['HERE_satelliteDay'] = {
title: 'satellite',
icon: 'icons/here_satelliteday.png',
layer: L.tileLayer('http://{s}.{base}.maps.cit.api.here.com/maptile/2.1/maptile/{mapID}/satellite.day/{z}/{x}/{y}/256/png8?app_id={app_id}&app_code={app_code}', {
attribution: 'Map &copy; 1987-2014 <a href="http://developer.here.com">HERE</a>',
subdomains: '1234',
mapID: 'newest',
app_id: 'Y8m9dK2brESDPGJPdrvs',
app_code: 'dq2MYIvjAotR8tHvY8Q_Dg',
base: 'aerial',
maxZoom: 20
})
};
providers['HERE_satelliteDay'] = {
title: 'satellite',
icon: 'icons/here_satelliteday.png',
layer: L.tileLayer('http://{s}.{base}.maps.cit.api.here.com/maptile/2.1/maptile/{mapID}/satellite.day/{z}/{x}/{y}/256/png8?app_id={app_id}&app_code={app_code}', {
attribution: 'Map &copy; 1987-2014 <a href="http://developer.here.com">HERE</a>',
subdomains: '1234',
mapID: 'newest',
app_id: 'Y8m9dK2brESDPGJPdrvs',
app_code: 'dq2MYIvjAotR8tHvY8Q_Dg',
base: 'aerial',
maxZoom: 20
})
};

providers['CartoDB_Positron'] = {
title: 'positron',
icon: 'icons/cartodb_positron.png',
layer: L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="http://cartodb.com/attributions">CartoDB</a>',
subdomains: 'abcd',
maxZoom: 19
})
};
providers['CartoDB_Positron'] = {
title: 'positron',
icon: 'icons/cartodb_positron.png',
layer: L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="http://cartodb.com/attributions">CartoDB</a>',
subdomains: 'abcd',
maxZoom: 19
})
};

return providers;
});
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "leaflet-iconlayers",
"version": "0.1.2",
"version": "0.2.0",
"description": "Leaflet control that displays base layers as small icons.",
"main": "src/iconLayers.js",
"directories": {
"example": "examples"
},
"scripts": {
"examples": "browserify -v examples/browserify.js > examples/browserify_bundle.js"
},
"repository": {
"type": "git",
"url": "https://github.com/ScanEx/Leaflet-IconLayers.git"
Expand All @@ -27,6 +30,7 @@
"leaflet": "^0.7.3"
},
"devDependencies": {
"browserify": "^12.0.1",
"gulp": "^3.9.0",
"gulp-eslint": "^1.0.0"
}
Expand Down
24 changes: 18 additions & 6 deletions src/iconLayers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
(function() {
(function(factory) {
if (typeof module !== 'undefined' && module.exports) {
module.exports = factory(require('leaflet'));
} else {
window.L.control.iconLayers = factory(window.L);
window.L.Control.IconLayers = window.L.control.iconLayers.Constructor;
}
})(function(L) {
function each(o, cb) {
for (var p in o) {
if (o.hasOwnProperty(p)) {
Expand Down Expand Up @@ -48,7 +55,8 @@
parent.appendChild(el);
}
}
L.Control.IconLayers = L.Control.extend({

var IconLayers = L.Control.extend({
includes: L.Mixin.Events,
_getActiveLayer: function() {
if (this._activeLayerId) {
Expand Down Expand Up @@ -290,8 +298,12 @@
}.bind(this));
}
});
})();

L.control.iconLayers = function(layers, options) {
return new L.Control.IconLayers(layers, options);
};
var iconLayers = function(layers, options) {
return new IconLayers(layers, options);
};

iconLayers.Constructor = IconLayers;

return iconLayers;
});

0 comments on commit f7bfcf0

Please sign in to comment.