2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
51 |
52 |
53 |
54 | Google maps example
55 | Use the Layer Switch Control on the top rigth of the map to select another Google Maps Layer.
56 |
57 |
58 |
--------------------------------------------------------------------------------
/examples/0102-layers-googlemaps-lf1-example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
51 |
52 |
53 |
54 | Google maps example
55 | Use the Layer Switch Control on the top rigth of the map to select another Google Maps Layer.
56 |
57 |
58 |
--------------------------------------------------------------------------------
/examples/0201-mapboxgl-example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Mapbox WebGL Example
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | Mapbox GL Example
78 |
79 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/examples/0202-mapbox-basic-example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Mapbox Basic Example
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
46 |
47 |
48 |
49 | Mapbox Basic Example
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/examples/0301-layers-bingmaps-example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
61 |
62 |
63 |
64 | Bing maps
65 | Use the Layer Switch Control on the top rigth of the map to select another Bing Maps Layer.
66 |
67 |
68 |
--------------------------------------------------------------------------------
/examples/0401-layers-yandexmaps-example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
50 |
51 |
52 |
53 | Yandex maps example
54 | Use the Layer Switch Control on the top rigth of the map to select another Yandex Maps Layer.
55 |
56 |
57 |
--------------------------------------------------------------------------------
/gulp/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "node": true,
4 | "es6": true
5 | },
6 | "rules": {
7 | "quotes": ["error", "single", { "allowTemplateLiterals": true }]
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/gulp/.githubreleaser.json.example:
--------------------------------------------------------------------------------
1 | {
2 | "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
3 | }
4 |
--------------------------------------------------------------------------------
/gulp/index.js:
--------------------------------------------------------------------------------
1 | require('./tasks/');
2 | const gulp = require('gulp');
3 |
4 | gulp.task('build-release', gulp.series('build', 'test', 'min'));
5 | gulp.task('default', gulp.series('build-release', 'browser-sync'));
6 |
--------------------------------------------------------------------------------
/gulp/tasks/browser-sync.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const gulp = require('gulp');
4 | let browserSync = require('browser-sync').create();
5 |
6 | gulp.task('browser-sync', function() {
7 | browserSync.init({
8 | open: false,
9 | server: {
10 | baseDir: './',
11 | directory: true
12 | }
13 | });
14 |
15 | const reload = (done) => {
16 | browserSync.reload();
17 | done();
18 | };
19 |
20 | gulp.watch('./src/**/*.es6', gulp.series('build-release'));
21 | gulp.watch('./test/**/*.spec.js', gulp.series('test'));
22 | gulp.watch('./dist/**/*.min.js', reload);
23 | gulp.watch('./examples/**/*.html', reload);
24 | });
25 |
--------------------------------------------------------------------------------
/gulp/tasks/build.js:
--------------------------------------------------------------------------------
1 | const gulp = require('gulp');
2 | const concat = require('gulp-concat');
3 | const insert = require('gulp-insert');
4 | const babel = require('gulp-babel');
5 | const sourcemaps = require('gulp-sourcemaps');
6 | const jf = require('jsonfile');
7 | const wrap = require('gulp-wrap');
8 | require('./clean.js');
9 |
10 | let date = new Date();
11 |
12 | let pkgFn = () => jf.readFileSync('package.json');
13 |
14 | let header = () => {
15 | let ourPackage = pkgFn();
16 | return `/**
17 | * ${ourPackage.name}
18 | *
19 | * @version: ${ourPackage.version}
20 | * @author: ${ourPackage.author}
21 | * @date: ${date.toString()}
22 | * @license: ${ourPackage.license}
23 | */\n`;
24 | };
25 |
26 | let build = (source, out = 'index.js') => {
27 | return gulp.src(source)
28 | .pipe(sourcemaps.init())
29 | .pipe(babel({
30 | presets: ['es2015'],
31 | compact: false,
32 | plugins: ['transform-remove-strict-mode']
33 | }))
34 | .pipe(concat(out))
35 | .pipe(sourcemaps.write('.'))
36 | .pipe(wrap({src: 'src/wrap/dist.js'}))
37 | .pipe(insert.prepend(header()))
38 | .pipe(gulp.dest('dist'));
39 | };
40 |
41 | gulp.task('build', () =>
42 | build([
43 | 'src/services/leafletHelpers.es6',
44 | 'src/services/leafletLayerHelpers.es6',
45 | 'src/services/logger.es6'
46 | ], 'ui-leaflet-layers.js')
47 | );
48 |
--------------------------------------------------------------------------------
/gulp/tasks/clean.js:
--------------------------------------------------------------------------------
1 | const gulp = require('gulp');
2 | const del = require('del');
3 |
4 | gulp.task('clean', done => del(['tmp', 'dist', '*.log'], done));
5 |
6 | gulp.task('cleanTmp', done => del(['tmp'], done));
7 |
--------------------------------------------------------------------------------
/gulp/tasks/index.js:
--------------------------------------------------------------------------------
1 | const requireDirectory = require('require-directory');
2 | module.exports = requireDirectory(module);
3 |
--------------------------------------------------------------------------------
/gulp/tasks/release.js:
--------------------------------------------------------------------------------
1 | const gulp = require('gulp');
2 | const conventionalChangelog = require('gulp-conventional-changelog');
3 | const conventionalGithubReleaser = require('conventional-github-releaser');
4 | const bump = require('gulp-bump');
5 | const gutil = require('gulp-util');
6 | const git = require('gulp-git');
7 | const fs = require('fs');
8 |
9 | gulp.task('changelog', () => {
10 | return gulp.src('CHANGELOG.md', {
11 | buffer: true
12 | })
13 | .pipe(conventionalChangelog({
14 | preset: 'angular' // Or to any other commit message convention you use.
15 | }))
16 | .pipe(gulp.dest('./'));
17 | });
18 |
19 | gulp.task('github-release', done => {
20 | const token = JSON.parse(fs.readFileSync('./gulp/.githubreleaser.json', 'utf8')).token;
21 | conventionalGithubReleaser({
22 | type: 'oauth',
23 | token: token
24 | }, {
25 | preset: 'angular' // Or to any other commit message convention you use.
26 | }, done);
27 | });
28 |
29 | gulp.task('bump-version', () => {
30 | // We hardcode the version change type to 'patch' but it may be a good idea to
31 | // use minimist (https://www.npmjs.com/package/minimist) to determine with a
32 | // command argument whether you are doing a 'major', 'minor' or a 'patch' change.
33 | return gulp.src(['./bower.json', './package.json'])
34 | .pipe(bump({type: 'patch'}).on('error', gutil.log))
35 | .pipe(gulp.dest('./'));
36 | });
37 |
38 | gulp.task('commit-changes', () => {
39 | return gulp.src('.')
40 | .pipe(git.add())
41 | .pipe(git.commit('[Prerelease] Bumped version number'));
42 | });
43 |
44 | gulp.task('push-changes', (cb) => {
45 | git.push('origin', 'master', cb);
46 | });
47 |
48 | gulp.task('create-new-tag', (cb) => {
49 | const getPackageJsonVersion = () => {
50 | // We parse the json file instead of using require because require caches
51 | // multiple calls so the version number won't be updated
52 | return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
53 | };
54 | const version = getPackageJsonVersion();
55 |
56 | git.tag(version, 'Created Tag for version: ' + version, error => {
57 | if (error) {
58 | return cb(error);
59 | }
60 | git.push('origin', 'master', {args: '--tags'}, cb);
61 | });
62 | });
63 |
64 | gulp.task('release', gulp.series(
65 | 'bump-version',
66 | 'changelog',
67 | 'commit-changes',
68 | 'push-changes',
69 | 'create-new-tag',
70 | 'github-release'
71 | ));
72 |
--------------------------------------------------------------------------------
/gulp/tasks/test.js:
--------------------------------------------------------------------------------
1 | const gulp = require('gulp');
2 | const Karma = require('karma').Server;
3 | const open = require('open');
4 | const { log } = require('gulp-util');
5 |
6 | let karmaRunner = (done) => {
7 | log('-- Karma Setup --');
8 | const karmaConf = require.resolve('../../test/karma.conf.js');
9 | try {
10 | new Karma({
11 | configFile: karmaConf,
12 | singleRun: true
13 | }, (code) => {
14 | log(`Karma Callback Code: ${code}`);
15 | done();
16 | }).start();
17 | } catch(e) {
18 | log(`KARMA ERROR: ${e}`);
19 | done(e);
20 | }
21 | };
22 |
23 | gulp.task('karma', done => karmaRunner(done));
24 |
25 | gulp.task('test', gulp.parallel('karma'));
26 |
27 | let doOpen = (name = '') => done => open(`dist/coverage/lib${name}/index.html`, 'Google Chrome', done) ;
28 | gulp.task('coverage', doOpen());
29 |
--------------------------------------------------------------------------------
/gulp/tasks/uglify.js:
--------------------------------------------------------------------------------
1 | const gulp = require('gulp');
2 | const concat = require('gulp-concat');
3 | const uglify = require('gulp-uglify');
4 |
5 | gulp.task('min', () => {
6 | return gulp.src('./dist/ui-leaflet-layers.js')
7 | .pipe(uglify({mangle: false}))
8 | .pipe(concat('ui-leaflet-layers.min.js'))
9 | .pipe(gulp.dest('./dist'));
10 | });
11 |
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | /*
2 | gulpfile.js
3 | ===========
4 | Rather than manage one giant configuration file responsible
5 | for creating multiple tasks, each task has been broken out into
6 | its own file in gulp/tasks. Any file in that folder gets automatically
7 | required by the loop in ./gulp/index.js (required below).
8 | To add a new task, simply add a new task file to gulp/tasks.
9 | */
10 | require('./gulp');
11 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ui-leaflet-layers",
3 | "version": "0.1.3",
4 | "description": "Angular UI Leaflet Layers Plugin",
5 | "main": "dist/ui-leaflet-layers.js",
6 | "scripts": {
7 | "start": "node_modules/gulp/bin/gulp.js",
8 | "test": "node_modules/gulp/bin/gulp.js test"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "https://github.com/elesdoar/ui-leaflet-layers.git"
13 | },
14 | "keywords": [
15 | "ui-leaflet",
16 | "leaflet",
17 | "maps",
18 | "gis",
19 | "mapbox",
20 | "esri",
21 | "cartodb",
22 | "wms"
23 | ],
24 | "author": "Michael Salgado ",
25 | "license": "MIT",
26 | "bugs": {
27 | "url": "https://github.com/elesdoar/ui-leaflet-layers/issues"
28 | },
29 | "homepage": "https://github.com/elesdoar/ui-leaflet-layers",
30 | "devDependencies": {
31 | "angular-mocks": "^1.4.7",
32 | "babel-plugin-transform-remove-strict-mode": "0.0.2",
33 | "babel-preset-es2015": "^6.14.0",
34 | "browser-sync": "^2.16.0",
35 | "conventional-github-releaser": "^1.1.3",
36 | "del": "^2.0.2",
37 | "gulp": "git://github.com/gulpjs/gulp.git#4.0",
38 | "gulp-babel": "^6.1.2",
39 | "gulp-bump": "^2.4.0",
40 | "gulp-concat": "^2.6.0",
41 | "gulp-conventional-changelog": "^1.1.0",
42 | "gulp-git": "^1.6.0",
43 | "gulp-if": "^2.0.0",
44 | "gulp-insert": "^0.5.0",
45 | "gulp-replace": "^0.5.4",
46 | "gulp-sourcemaps": "^1.6.0",
47 | "gulp-uglify": "^2.0.0",
48 | "gulp-util": "^3.0.7",
49 | "gulp-wrap": "~0.13.0",
50 | "jasmine-core": "2.x",
51 | "jsonfile": "^2.2.3",
52 | "karma": "^1.3.x",
53 | "karma-babel-preprocessor": "^6.0.1",
54 | "karma-chrome-launcher": "~2.x",
55 | "karma-coverage": "~1.1.x",
56 | "karma-jasmine": "~1.0.x",
57 | "karma-mocha-reporter": "~2.x",
58 | "karma-phantomjs-launcher": "~1.0.x",
59 | "open": "0.0.5",
60 | "phantomjs": "^2.1.7",
61 | "require-directory": "^2.x"
62 | },
63 | "dependencies": {
64 | "angular": "^1.5.x",
65 | "leaflet": "^0.7.7",
66 | "ui-leaflet": "^1.0.2"
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/services/leafletHelpers.es6:
--------------------------------------------------------------------------------
1 | angular.module('ui-leaflet')
2 | .config(['$provide', $provide =>
3 | $provide.decorator('leafletHelpers', ['$delegate', 'leafletLayersLogger', ($delegate, leafletLayersLogger) => {
4 | const $log = leafletLayersLogger;
5 |
6 | const _versionCompare = (left, right) => {
7 | if(typeof left + typeof right !== 'stringstring') {
8 | return false;
9 | }
10 |
11 | let a = left.split('.');
12 | let b = right.split('.');
13 | let i = 0, len = Math.max(a.length, b.length);
14 |
15 | for (; i < len; i++) {
16 | if ((a[i] && !b[i] && parseInt(a[i]) > 0) || (parseInt(a[i]) > parseInt(b[i]))) {
17 | return 1;
18 | } else if ((b[i] && !a[i] && parseInt(b[i]) > 0) || (parseInt(a[i]) < parseInt(b[i]))) {
19 | return -1;
20 | }
21 | }
22 |
23 | return 0;
24 | };
25 |
26 | const basicFunction = layerType =>
27 | ({
28 | isLoaded() {
29 | return angular.isDefined(layerType);
30 | },
31 | is(layer) {
32 | if (this.isLoaded()) {
33 | return layer instanceof layerType;
34 | }
35 | return false;
36 | }
37 | });
38 |
39 | const plugins = {
40 | // Please keep keys order by alphabetical sort.
41 | BingLayerPlugin: basicFunction(L.BingLayer),
42 | ChinaLayerPlugin: basicFunction(L.tileLayer.chinaProvider),
43 | HeatLayerPlugin: basicFunction(L.heatLayer),
44 | LeafletProviderPlugin: basicFunction(L.TileLayer.Provider),
45 | MapboxGL: basicFunction(L.mapboxGL),
46 | UTFGridPlugin: basicFunction(L.UtfGrid),
47 | WebGLHeatMapLayerPlugin: basicFunction(L.TileLayer.WebGLHeatMap),
48 | WFSLayerPlugin: basicFunction(L.GeoJSON.WFS),
49 | YandexLayerPlugin: basicFunction(L.Yandex)
50 | };
51 |
52 | if(_versionCompare(L.version, '1.0.0') === -1) {
53 | plugins.GoogleLayerPlugin = basicFunction(L.Google);
54 | } else {
55 | plugins.GoogleLayerPlugin = basicFunction(L.GridLayer.GoogleMutant);
56 | }
57 | plugins.versionCompare = _versionCompare;
58 |
59 | if(angular.isDefined(L.esri)) {
60 | angular.extend(plugins, {
61 | AGSBaseLayerPlugin: basicFunction(L.esri.basemapLayer),
62 | AGSClusteredLayerPlugin: basicFunction(L.esri.clusteredFeatureLayer),
63 | AGSDynamicMapLayerPlugin: basicFunction(L.esri.dynamicMapLayer),
64 | AGSFeatureLayerPlugin: basicFunction(L.esri.featureLayer),
65 | AGSImageMapLayerPlugin: basicFunction(L.esri.imageMapLayer),
66 | AGSHeatmapLayerPlugin: basicFunction(L.esri.heatmapFeatureLayer),
67 | AGSTiledMapLayerPlugin: basicFunction(L.esri.tiledMapLayer)
68 | });
69 | } else {
70 | angular.extend(plugins, {
71 | AGSBaseLayerPlugin: basicFunction(),
72 | AGSClusteredLayerPlugin: basicFunction(),
73 | AGSDynamicMapLayerPlugin: basicFunction(),
74 | AGSFeatureLayerPlugin: basicFunction(),
75 | AGSImageMapLayerPlugin: basicFunction(),
76 | AGSHeatmapLayerPlugin: basicFunction(),
77 | AGSTiledMapLayerPlugin: basicFunction()
78 | });
79 | }
80 |
81 | if(angular.isDefined(window.lvector)) {
82 | angular.extend(plugins, {
83 | AGSLayerPlugin: basicFunction(window.lvector.AGS)
84 | });
85 | } else {
86 | angular.extend(plugins, {
87 | AGSLayerPlugin: basicFunction()
88 | });
89 | }
90 |
91 | angular.extend($delegate, plugins);
92 |
93 | $log.info('[ui-leaflet-layers] - Layers plugin is loaded');
94 |
95 | return $delegate;
96 | }])
97 | ]);
98 |
--------------------------------------------------------------------------------
/src/services/leafletLayerHelpers.es6:
--------------------------------------------------------------------------------
1 | angular.module('ui-leaflet')
2 | .config(['$provide', $provide =>
3 | $provide.decorator('leafletLayerHelpers',
4 | ['$delegate', '$rootScope', '$q', 'leafletHelpers', 'leafletLayersLogger',
5 | ($delegate, $rootScope, $q, leafletHelpers, leafletLayersLogger) => {
6 | let $log = leafletLayersLogger;
7 | let { isArray } = leafletHelpers;
8 | let { isObject } = leafletHelpers;
9 | let { isDefined } = leafletHelpers;
10 | let { errorHeader } = leafletHelpers;
11 | let utfGridCreateLayer = params => {
12 | if (!leafletHelpers.UTFGridPlugin.isLoaded()) {
13 | $log.error(errorHeader + ' The UTFGrid plugin is not loaded.');
14 | return;
15 | }
16 |
17 | let utfgrid = new L.UtfGrid(params.url, params.pluginOptions);
18 |
19 | utfgrid.on('mouseover', function(e) {
20 | $rootScope.$broadcast('leafletDirectiveMap.utfgridMouseover', e);
21 | });
22 |
23 | utfgrid.on('mouseout', function(e) {
24 | $rootScope.$broadcast('leafletDirectiveMap.utfgridMouseout', e);
25 | });
26 |
27 | utfgrid.on('click', function(e) {
28 | $rootScope.$broadcast('leafletDirectiveMap.utfgridClick', e);
29 | });
30 |
31 | utfgrid.on('mousemove', function(e) {
32 | $rootScope.$broadcast('leafletDirectiveMap.utfgridMousemove', e);
33 | });
34 |
35 | return utfgrid;
36 | };
37 |
38 | angular.extend($delegate.layerTypes, {
39 | ags: {
40 | mustHaveUrl: true,
41 | createLayer: function(params) {
42 | if (!leafletHelpers.AGSLayerPlugin.isLoaded()) {
43 | return;
44 | }
45 |
46 | var options = angular.copy(params.options);
47 | angular.extend(options, {
48 | url: params.url
49 | });
50 | var layer = new lvector.AGS(options);
51 | layer.onAdd = function(map) {
52 | this.setMap(map);
53 | };
54 | layer.onRemove = function() {
55 | this.setMap(null);
56 | };
57 | return layer;
58 | }
59 | },
60 | agsBase: {
61 | mustHaveLayer : true,
62 | createLayer: function (params) {
63 | if (!leafletHelpers.AGSBaseLayerPlugin.isLoaded()) {
64 | return;
65 | }
66 | return L.esri.basemapLayer(params.layer, params.options);
67 | }
68 | },
69 | agsClustered: {
70 | mustHaveUrl: true,
71 | createLayer: function(params) {
72 | if (!leafletHelpers.AGSClusteredLayerPlugin.isLoaded()) {
73 | $log.warn(errorHeader + ' The esri clustered layer plugin is not loaded.');
74 | return;
75 | }
76 |
77 | if(!leafletHelpers.MarkerClusterPlugin.isLoaded()) {
78 | $log.warn(errorHeader + ' The markercluster plugin is not loaded.');
79 | return;
80 | }
81 | return L.esri.clusteredFeatureLayer(params.url, params.options);
82 | }
83 | },
84 | agsDynamic: {
85 | mustHaveUrl: true,
86 | createLayer: function(params) {
87 | if (!leafletHelpers.AGSDynamicMapLayerPlugin.isLoaded()) {
88 | $log.warn(errorHeader + ' The esri plugin is not loaded.');
89 | return;
90 | }
91 |
92 | params.options.url = params.url;
93 |
94 | return L.esri.dynamicMapLayer(params.options);
95 | }
96 | },
97 | agsFeature: {
98 | mustHaveUrl: true,
99 | createLayer: function(params) {
100 | if (!leafletHelpers.AGSFeatureLayerPlugin.isLoaded()) {
101 | $log.warn(errorHeader + ' The esri plugin is not loaded.');
102 | return;
103 | }
104 |
105 | params.options.url = params.url;
106 |
107 | var layer = L.esri.featureLayer(params.options);
108 | var load = function() {
109 | if(isDefined(params.options.loadedDefer)) {
110 | params.options.loadedDefer.resolve();
111 | }
112 | };
113 | layer.on('loading', function() {
114 | params.options.loadedDefer = $q.defer();
115 | layer.off('load', load);
116 | layer.on('load', load);
117 | });
118 |
119 | return layer;
120 | }
121 | },
122 | agsHeatmap: {
123 | mustHaveUrl: true,
124 | createLayer: function(params) {
125 | if (!leafletHelpers.AGSHeatmapLayerPlugin.isLoaded()) {
126 | $log.warn(errorHeader + ' The esri heatmap layer plugin is not loaded.');
127 | return;
128 | }
129 |
130 | if(!leafletHelpers.HeatLayerPlugin.isLoaded()) {
131 | $log.warn(errorHeader + ' The heatlayer plugin is not loaded.');
132 | return;
133 | }
134 | return L.esri.heatmapFeatureLayer(params.url, params.options);
135 | }
136 | },
137 | agsImage: {
138 | mustHaveUrl: true,
139 | createLayer: function(params) {
140 | if (!leafletHelpers.AGSImageMapLayerPlugin.isLoaded()) {
141 | $log.warn(errorHeader + ' The esri plugin is not loaded.');
142 | return;
143 | }
144 | params.options.url = params.url;
145 |
146 | return L.esri.imageMapLayer(params.options);
147 | }
148 | },
149 | agsTiled: {
150 | mustHaveUrl: true,
151 | createLayer: function(params) {
152 | if (!leafletHelpers.AGSTiledMapLayerPlugin.isLoaded()) {
153 | $log.warn(errorHeader + ' The esri plugin is not loaded.');
154 | return;
155 | }
156 |
157 | params.options.url = params.url;
158 |
159 | return L.esri.tiledMapLayer(params.options);
160 | }
161 | },
162 | bing: {
163 | mustHaveUrl: false,
164 | createLayer(params) {
165 | if (!leafletHelpers.BingLayerPlugin.isLoaded()) {
166 | $log.error(errorHeader + ' The Bing plugin is not loaded.');
167 | return;
168 | }
169 | return new L.BingLayer(params.key, params.options);
170 | }
171 | },
172 |
173 | china: {
174 | mustHaveUrl:false,
175 | createLayer(params) {
176 | let type = params.type || '';
177 | if (!leafletHelpers.ChinaLayerPlugin.isLoaded()) {
178 | $log.error(errorHeader + ' The ChinaLayer plugin is not loaded.');
179 | return;
180 | }
181 | return L.tileLayer.chinaProvider(type, params.options);
182 | }
183 | },
184 |
185 | google: {
186 | mustHaveUrl: false,
187 | createLayer(params) {
188 | let type = params.type || 'SATELLITE';
189 | if (!leafletHelpers.GoogleLayerPlugin.isLoaded()) {
190 | $log.error(errorHeader + ' The GoogleLayer plugin is not loaded.');
191 | return;
192 | }
193 | let layer = null;
194 |
195 | if(leafletHelpers.versionCompare(L.version, '1.0.0') === -1) {
196 | layer = new L.Google(type.toUpperCase(), params.options);
197 | } else {
198 | layer = new L.GridLayer.GoogleMutant({
199 | type: type.toLowerCase()
200 | });
201 | }
202 | return layer;
203 | }
204 | },
205 |
206 | heat: {
207 | mustHaveUrl: false,
208 | mustHaveData: true,
209 | createLayer(params) {
210 | if (!leafletHelpers.HeatLayerPlugin.isLoaded()) {
211 | $log.error(errorHeader + ' The HeatMapLayer plugin is not loaded.');
212 | return;
213 | }
214 | let layer = new L.heatLayer();
215 | if (isArray(params.data)) {
216 | layer.setLatLngs(params.data);
217 | }
218 | if (isObject(params.options)) {
219 | layer.setOptions(params.options);
220 | }
221 | return layer;
222 | }
223 | },
224 |
225 | here: {
226 | mustHaveUrl: false,
227 | createLayer: function(params) {
228 | var provider = params.provider || 'HERE.terrainDay';
229 | if (!leafletHelpers.LeafletProviderPlugin.isLoaded()) {
230 | return;
231 | }
232 | return new L.TileLayer.Provider(provider, params.options);
233 | }
234 | },
235 |
236 | mapbox: {
237 | mustHaveKey: true,
238 | createLayer(params) {
239 | let url = '//api.mapbox.com/styles/v1/{user}/{mapId}/tiles/256/{z}/{x}/{y}?access_token={apiKey}';
240 | return L.tileLayer(url, angular.extend(params.options, {
241 | mapId: params.key,
242 | user: params.user,
243 | apiKey: params.apiKey
244 | }));
245 | }
246 | },
247 |
248 | mapboxGL: {
249 | createLayer(params) {
250 | if (!leafletHelpers.MapboxGL.isLoaded()) {
251 | $log.error(errorHeader + ' The MapboxGL plugin is not loaded.');
252 | return;
253 | }
254 | return new L.mapboxGL(params.options);
255 | }
256 | },
257 |
258 | utfGrid: {
259 | mustHaveUrl: true,
260 | createLayer: utfGridCreateLayer
261 | },
262 |
263 | webGLHeatmap: {
264 | mustHaveUrl: false,
265 | mustHaveData: true,
266 | createLayer(params) {
267 | if (!leafletHelpers.WebGLHeatMapLayerPlugin.isLoaded()) {
268 | $log.error(errorHeader + ' The WebGLHeatMapLayer plugin is not loaded.');
269 | return;
270 | }
271 | let layer = new L.TileLayer.WebGLHeatMap(params.options);
272 | if (isDefined(params.data)) {
273 | layer.setData(params.data);
274 | }
275 | return layer;
276 | }
277 | },
278 |
279 | wfs: {
280 | mustHaveUrl: true,
281 | mustHaveLayer: true,
282 | createLayer(params) {
283 | if (!leafletHelpers.WFSLayerPlugin.isLoaded()) {
284 | $log.error(errorHeader + ' The WFSLayer plugin is not loaded.');
285 | return;
286 | }
287 | let options = angular.copy(params.options);
288 | if (options.crs && 'string' === typeof options.crs) {
289 | options.crs = eval(options.crs);
290 | }
291 | return new L.GeoJSON.WFS(params.url, params.layer, options);
292 | }
293 | },
294 |
295 | yandex: {
296 | mustHaveUrl: false,
297 | createLayer(params) {
298 | let type = params.type || 'map';
299 | if (!leafletHelpers.YandexLayerPlugin.isLoaded()) {
300 | $log.error(errorHeader + ' The YandexLayer plugin is not loaded.');
301 | return;
302 | }
303 | return new L.Yandex(type, params.options);
304 | }
305 | }
306 | });
307 |
308 | return $delegate;
309 | }])
310 | ]);
311 |
--------------------------------------------------------------------------------
/src/services/logger.es6:
--------------------------------------------------------------------------------
1 | angular.module('ui-leaflet')
2 | .service('leafletLayersLogger', ['nemSimpleLogger', nemSimpleLogger => nemSimpleLogger.spawn()]);
3 |
--------------------------------------------------------------------------------
/src/wrap/dist.js:
--------------------------------------------------------------------------------
1 | (function (window, angular){
2 | 'use strict';
3 | <%= contents %>
4 | })(window, angular);
5 |
--------------------------------------------------------------------------------
/test/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "node": true,
4 | "es6": true
5 | },
6 | "rules": {
7 | "quotes": ["error", "single", { "allowTemplateLiterals": true }]
8 | },
9 | "globals": {
10 | "inject": true,
11 | "expect": true
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/test/karma.conf.js:
--------------------------------------------------------------------------------
1 | module.exports = (config) => {
2 | return config.set({
3 | basePath: './',
4 | frameworks: ['jasmine'],
5 | preprocessors: {
6 | '../test/**/*.js': ['babel'],
7 | '../dist/ui-leaflet-layers.js': ['coverage']
8 | },
9 | babelPreprocessor: {
10 | options: {
11 | presets: ['es2015'],
12 | sourceMap: 'inline'
13 | },
14 | filename: function (file) {
15 | return file.originalPath.replace(/\.js$/, '.es5.js');
16 | },
17 | sourceFileName: function (file) {
18 | return file.originalPath;
19 | }
20 | },
21 | coverageReporter: {
22 | reporters: [
23 | {
24 | type: 'html',
25 | dir: 'dist/coverage/',
26 | subdir: 'lib'
27 | }, {
28 | type: 'cobertura',
29 | dir: 'dist/coverage/',
30 | subdir: 'lib'
31 | }
32 | ]
33 | },
34 | files: [
35 | '../bower_components/leaflet/dist/leaflet.js',
36 | '../bower_components/angular/angular.js',
37 | '../bower_components/angular-mocks/angular-mocks.js',
38 | '../bower_components/angular-simple-logger/dist/angular-simple-logger.js',
39 | 'http://maps.google.com/maps/api/js?key=AIzaSyBazU_OOTAZRmxQfaiirM1EDPLCiUSTlrY',
40 | 'http://api-maps.yandex.ru/2.1/?lang=en_US',
41 | '../bower_components/leaflet-plugins/layer/tile/Google.js',
42 | '../bower_components/leaflet-plugins/layer/tile/Yandex.js',
43 | '../bower_components/ui-leaflet/dist/ui-leaflet.js',
44 | '../dist/ui-leaflet-layers.js',
45 | 'unit/*.spec.js'
46 | ],
47 | exclude: [],
48 | reporters: ['mocha', 'coverage'],
49 | port: 9876,
50 | colors: true,
51 | logLevel: config.LOG_INFO,
52 | autoWatch: false,
53 | browsers: ['PhantomJS'],
54 | captureTimeout: 60000,
55 | singleRun: false
56 | });
57 | };
58 |
--------------------------------------------------------------------------------
/test/unit/layersDirective.google.spec.js:
--------------------------------------------------------------------------------
1 | describe('layersDirective', () => {
2 | let leafletData, $rootScope, $compile, scope;
3 | beforeEach(() => {
4 | module('ui-leaflet');
5 | inject(function(_$compile_, _$rootScope_, _leafletData_) {
6 | $compile = _$compile_;
7 | $rootScope = _$rootScope_;
8 | scope = $rootScope.$new();
9 | leafletData = _leafletData_;
10 | });
11 | });
12 |
13 | afterEach(inject(function ($rootScope) {
14 | $rootScope.$apply();
15 | }));
16 |
17 | it('should create google layers if correctly configured', function () {
18 | angular.extend(scope, {
19 | layers: {
20 | baselayers: {
21 | googleTerrain: {
22 | name: 'Google Terrain',
23 | layerType: 'TERRAIN',
24 | type: 'google'
25 | }
26 | },
27 | overlays: {
28 | googleHybrid: {
29 | name: 'Google Hybrid',
30 | layerType: 'HYBRID',
31 | type: 'google',
32 | visible: true
33 | },
34 | googleRoadmap: {
35 | name: 'Google Streets',
36 | layerType: 'ROADMAP',
37 | type: 'google',
38 | visible: true
39 | }
40 | }
41 | }
42 | });
43 | var element = angular.element('');
44 | element = $compile(element)(scope);
45 | var map;
46 | leafletData.getMap().then(function (leafletMap) {
47 | map = leafletMap;
48 | });
49 | scope.$digest();
50 | leafletData.getLayers().then(function (layers) {
51 | expect(map.hasLayer(layers.baselayers.googleTerrain)).toBe(true);
52 | expect(map.hasLayer(layers.overlays.googleHybrid)).toBe(true);
53 | expect(map.hasLayer(layers.overlays.googleRoadmap)).toBe(true);
54 | });
55 | });
56 | });
57 |
--------------------------------------------------------------------------------
/test/unit/layersDirective.mapbox.spec.js:
--------------------------------------------------------------------------------
1 | describe('layersDirective', () => {
2 | let leafletData, $rootScope, $compile, scope;
3 | beforeEach(() => {
4 | module('ui-leaflet');
5 | inject(function(_$compile_, _$rootScope_, _leafletData_) {
6 | $compile = _$compile_;
7 | $rootScope = _$rootScope_;
8 | scope = $rootScope.$new();
9 | leafletData = _leafletData_;
10 | });
11 | });
12 |
13 | afterEach(inject(function ($rootScope) {
14 | $rootScope.$apply();
15 | }));
16 |
17 | it('should create mapbox layers if correctly configured', function () {
18 | angular.extend(scope, {
19 | layers: {
20 | baselayers: {
21 | mapboxBasic: {
22 | name: 'Mapbox Basic',
23 | type: 'mapbox',
24 | key: 'citng102800332hphzmbjudn7',
25 | user: 'elesdoar',
26 | apiKey: 'pk.eyJ1IjoiZWxlc2RvYXIiLCJhIjoiY2l0bmcwaDNpMDQzMTJvbDRpaTltN2dlbiJ9.KDnhRVh9St6vpQovMI7iLg'
27 | }
28 | },
29 | overlays: {
30 | mapboxOutdoors: {
31 | name: 'Mapbox Outdoors',
32 | type: 'mapbox',
33 | key: 'citng3g0g003s2it88y9lg769',
34 | user: 'elesdoar',
35 | apiKey: 'pk.eyJ1IjoiZWxlc2RvYXIiLCJhIjoiY2l0bmcwaDNpMDQzMTJvbDRpaTltN2dlbiJ9.KDnhRVh9St6vpQovMI7iLg',
36 | visible: true
37 | }
38 | }
39 | }
40 | });
41 | var element = angular.element('');
42 | element = $compile(element)(scope);
43 | var map;
44 | leafletData.getMap().then(function (leafletMap) {
45 | map = leafletMap;
46 | });
47 | scope.$digest();
48 | leafletData.getLayers().then(function (layers) {
49 | expect(map.hasLayer(layers.baselayers.mapboxBasic)).toBe(true);
50 | expect(map.hasLayer(layers.overlays.mapboxOutdoors)).toBe(true);
51 | });
52 | });
53 | });
54 |
--------------------------------------------------------------------------------
/test/unit/layersDirective.yandex.spec.js:
--------------------------------------------------------------------------------
1 | describe('layersDirective', () => {
2 | let leafletData, $rootScope, $compile, scope;
3 | beforeEach(() => {
4 | module('ui-leaflet');
5 | inject(function(_$compile_, _$rootScope_, _leafletData_) {
6 | $compile = _$compile_;
7 | $rootScope = _$rootScope_;
8 | scope = $rootScope.$new();
9 | leafletData = _leafletData_;
10 | });
11 | });
12 |
13 | afterEach(inject(function ($rootScope) {
14 | $rootScope.$apply();
15 | }));
16 |
17 | it('should create yandex layers if correctly configured', function () {
18 | angular.extend(scope, {
19 | layers: {
20 | baselayers: {
21 | yandexBasic: {
22 | name: 'Yandex Basic',
23 | type: 'yandex'
24 | }
25 | },
26 | overlays: {
27 | yandexHybrid: {
28 | name: 'Yandex Hybrid',
29 | layerType: 'hybrid',
30 | type: 'yandex',
31 | visible: true
32 | },
33 | yandexRoadmap: {
34 | name: 'Yandex Satellite',
35 | layerType: 'satellite',
36 | type: 'yandex',
37 | visible: true
38 | }
39 | }
40 | }
41 | });
42 | var element = angular.element('');
43 | element = $compile(element)(scope);
44 | var map;
45 | leafletData.getMap().then(function (leafletMap) {
46 | map = leafletMap;
47 | });
48 | scope.$digest();
49 | leafletData.getLayers().then(function (layers) {
50 | expect(map.hasLayer(layers.baselayers.yandexBasic)).toBe(true);
51 | expect(map.hasLayer(layers.overlays.yandexHybrid)).toBe(true);
52 | expect(map.hasLayer(layers.overlays.yandexRoadmap)).toBe(true);
53 | });
54 | });
55 | });
56 |
--------------------------------------------------------------------------------
/test/unit/leafletHelper.spec.js:
--------------------------------------------------------------------------------
1 | describe('leafletHelpers', () => {
2 | let leafletHelpers;
3 | beforeEach(() => {
4 | module('ui-leaflet');
5 | inject(function(_leafletHelpers_) {
6 | leafletHelpers = _leafletHelpers_;
7 | });
8 | });
9 |
10 | describe('versionCompare', () => {
11 | let versionCompare;
12 | beforeEach(() => {
13 | versionCompare = leafletHelpers.versionCompare;
14 | });
15 |
16 | describe('is greater than', () => {
17 | it('1.0.0 > 0.7.7', () => {
18 | expect(versionCompare('1.0.0', '0.7.7')).toBe(1);
19 | });
20 | });
21 |
22 | describe('is equal', () => {
23 | it('1.0.0 = 1.0.0', () => {
24 | expect(versionCompare('1.0.0', '1.0.0')).toBe(0);
25 | });
26 | });
27 |
28 | describe('is less than', () => {
29 | it('0.7.7 < 1.0.0', () => {
30 | expect(versionCompare('0.7.7', '1.0.0')).toBe(-1);
31 | });
32 | });
33 | });
34 | });
35 |
--------------------------------------------------------------------------------