Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit 59206fc

Browse files
committed
feat(layers): add suport for multiples services
Added suport for follow services: - Here maps - Mapbox - Esri (ArcGIS)
1 parent e4ab309 commit 59206fc

File tree

9 files changed

+495
-94
lines changed

9 files changed

+495
-94
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"globals": {
2727
"angular": true,
28-
"L": true
28+
"L": true,
29+
"lvector": true
2930
}
3031
}

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ Angular UI Leaflet Layers Plugin, it extend layer capabilities for [ui-leaflet](
44

55
### Supported Layers:
66

7-
* Google Maps
8-
* Bing
9-
* Yandex
7+
* [Bing](https://www.bingmapsportal.com/)
108
* China
9+
* [esri-leaflet](http://esri.github.io/esri-leaflet/)
10+
* [Google Maps](https://developers.google.com/maps/)
1111
* HeatLayer
12+
* [Here Maps](https://developer.here.com/lp/mapAPIs)
13+
* [MapboxGL](https://github.com/mapbox/mapbox-gl-leaflet)
14+
* [Mapbox](http://mapbox.com/)
15+
* MarkerCluster
16+
* Yandex
1217
* WebGLHeatMapLayer
13-
* WFS
1418
* UTFGrid
15-
* [MapboxGL](https://github.com/mapbox/mapbox-gl-leaflet)
19+
* WFS
1620

1721
### Coming Soon:
1822

19-
* [Mapbox](http://mapbox.com/)
2023
* [CartoDB](http://cartodb.com/)
21-
* [esri-leaflet](http://esri.github.io/esri-leaflet/)
2224

2325
### MapboxGL Example
2426

dist/ui-leaflet-layers.js

Lines changed: 233 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @version: 0.1.1
55
* @author: Michael Salgado <[email protected]>
6-
* @date: Fri Sep 23 2016 19:01:59 GMT-0500 (COT)
6+
* @date: Tue Sep 27 2016 11:41:57 GMT-0500 (COT)
77
* @license: MIT
88
*/
99
(function (window, angular){
@@ -26,23 +26,62 @@
2626
};
2727
};
2828

29-
angular.extend($delegate, {
30-
GoogleLayerPlugin: basicFunction(L.Google),
31-
MapboxGL: basicFunction(L.mapboxGL),
29+
var plugins = {
30+
// Please keep keys order by alphabetical sort.
3231
BingLayerPlugin: basicFunction(L.BingLayer),
33-
WFSLayerPlugin: basicFunction(L.GeoJSON.WFS),
3432
ChinaLayerPlugin: basicFunction(L.tileLayer.chinaProvider),
33+
GoogleLayerPlugin: basicFunction(L.Google),
3534
HeatLayerPlugin: basicFunction(L.heatLayer),
35+
LeafletProviderPlugin: basicFunction(L.TileLayer.Provider),
36+
MapboxGL: basicFunction(L.mapboxGL),
37+
MarkerClusterPlugin: basicFunction(L.MarkerClusterGroup),
38+
UTFGridPlugin: basicFunction(L.UtfGrid),
3639
WebGLHeatMapLayerPlugin: basicFunction(L.TileLayer.WebGLHeatMap),
37-
YandexLayerPlugin: basicFunction(L.Yandex),
38-
UTFGridPlugin: basicFunction(L.UtfGrid)
39-
});
40+
WFSLayerPlugin: basicFunction(L.GeoJSON.WFS),
41+
YandexLayerPlugin: basicFunction(L.Yandex)
42+
};
43+
44+
if (angular.isDefined(L.esri)) {
45+
angular.extend(plugins, {
46+
AGSBaseLayerPlugin: basicFunction(L.esri.basemapLayer),
47+
AGSClusteredLayerPlugin: basicFunction(L.esri.clusteredFeatureLayer),
48+
AGSDynamicMapLayerPlugin: basicFunction(L.esri.dynamicMapLayer),
49+
AGSFeatureLayerPlugin: basicFunction(L.esri.featureLayer),
50+
AGSImageMapLayerPlugin: basicFunction(L.esri.imageMapLayer),
51+
AGSHeatmapLayerPlugin: basicFunction(L.esri.heatmapFeatureLayer),
52+
AGSTiledMapLayerPlugin: basicFunction(L.esri.tiledMapLayer)
53+
});
54+
} else {
55+
angular.extend(plugins, {
56+
AGSBaseLayerPlugin: basicFunction(),
57+
AGSClusteredLayerPlugin: basicFunction(),
58+
AGSDynamicMapLayerPlugin: basicFunction(),
59+
AGSFeatureLayerPlugin: basicFunction(),
60+
AGSImageMapLayerPlugin: basicFunction(),
61+
AGSHeatmapLayerPlugin: basicFunction(),
62+
AGSTiledMapLayerPlugin: basicFunction()
63+
});
64+
}
65+
66+
if (angular.isDefined(window.lvector)) {
67+
angular.extend(plugins, {
68+
AGSLayerPlugin: basicFunction(window.lvector.AGS)
69+
});
70+
} else {
71+
angular.extend(plugins, {
72+
AGSLayerPlugin: basicFunction()
73+
});
74+
}
75+
76+
angular.extend($delegate, plugins);
77+
78+
$log.info('[ui-leaflet-layers] - Layers plugin is loaded');
4079

4180
return $delegate;
4281
});
4382
});
4483
angular.module('ui-leaflet').config(function ($provide) {
45-
return $provide.decorator('leafletLayerHelpers', function ($delegate, $rootScope, leafletHelpers, leafletLayersLogger) {
84+
return $provide.decorator('leafletLayerHelpers', function ($delegate, $rootScope, $q, leafletHelpers, leafletLayersLogger) {
4685
var $log = leafletLayersLogger;
4786
var isArray = leafletHelpers.isArray;
4887
var isObject = leafletHelpers.isObject;
@@ -77,52 +116,137 @@ angular.module('ui-leaflet').config(function ($provide) {
77116
};
78117

79118
angular.extend($delegate.layerTypes, {
80-
google: {
81-
mustHaveUrl: false,
119+
ags: {
120+
mustHaveUrl: true,
82121
createLayer: function createLayer(params) {
83-
var type = params.type || 'SATELLITE';
84-
if (!leafletHelpers.GoogleLayerPlugin.isLoaded()) {
85-
$log.error(errorHeader + ' The GoogleLayer plugin is not loaded.');
122+
if (!leafletHelpers.AGSLayerPlugin.isLoaded()) {
86123
return;
87124
}
88-
return new L.Google(type, params.options);
125+
126+
var options = angular.copy(params.options);
127+
angular.extend(options, {
128+
url: params.url
129+
});
130+
var layer = new lvector.AGS(options);
131+
layer.onAdd = function (map) {
132+
this.setMap(map);
133+
};
134+
layer.onRemove = function () {
135+
this.setMap(null);
136+
};
137+
return layer;
138+
}
139+
},
140+
agsBase: {
141+
mustHaveLayer: true,
142+
createLayer: function createLayer(params) {
143+
if (!leafletHelpers.AGSBaseLayerPlugin.isLoaded()) {
144+
return;
145+
}
146+
return L.esri.basemapLayer(params.layer, params.options);
89147
}
90148
},
149+
agsClustered: {
150+
mustHaveUrl: true,
151+
createLayer: function createLayer(params) {
152+
if (!leafletHelpers.AGSClusteredLayerPlugin.isLoaded()) {
153+
$log.warn(errorHeader + ' The esri clustered layer plugin is not loaded.');
154+
return;
155+
}
91156

92-
mapboxGL: {
157+
if (!leafletHelpers.MarkerClusterPlugin.isLoaded()) {
158+
$log.warn(errorHeader + ' The markercluster plugin is not loaded.');
159+
return;
160+
}
161+
return L.esri.clusteredFeatureLayer(params.url, params.options);
162+
}
163+
},
164+
agsDynamic: {
165+
mustHaveUrl: true,
93166
createLayer: function createLayer(params) {
94-
if (!leafletHelpers.MapboxGL.isLoaded()) {
95-
$log.error(errorHeader + ' The MapboxGL plugin is not loaded.');
167+
if (!leafletHelpers.AGSDynamicMapLayerPlugin.isLoaded()) {
168+
$log.warn(errorHeader + ' The esri plugin is not loaded.');
96169
return;
97170
}
98-
return new L.mapboxGL(params.options);
171+
172+
params.options.url = params.url;
173+
174+
return L.esri.dynamicMapLayer(params.options);
99175
}
100176
},
177+
agsFeature: {
178+
mustHaveUrl: true,
179+
createLayer: function createLayer(params) {
180+
if (!leafletHelpers.AGSFeatureLayerPlugin.isLoaded()) {
181+
$log.warn(errorHeader + ' The esri plugin is not loaded.');
182+
return;
183+
}
101184

102-
bing: {
103-
mustHaveUrl: false,
185+
params.options.url = params.url;
186+
187+
var layer = L.esri.featureLayer(params.options);
188+
var load = function load() {
189+
if (isDefined(params.options.loadedDefer)) {
190+
params.options.loadedDefer.resolve();
191+
}
192+
};
193+
layer.on('loading', function () {
194+
params.options.loadedDefer = $q.defer();
195+
layer.off('load', load);
196+
layer.on('load', load);
197+
});
198+
199+
return layer;
200+
}
201+
},
202+
agsHeatmap: {
203+
mustHaveUrl: true,
104204
createLayer: function createLayer(params) {
105-
if (!leafletHelpers.BingLayerPlugin.isLoaded()) {
106-
$log.error(errorHeader + ' The Bing plugin is not loaded.');
205+
if (!leafletHelpers.AGSHeatmapLayerPlugin.isLoaded()) {
206+
$log.warn(errorHeader + ' The esri heatmap layer plugin is not loaded.');
107207
return;
108208
}
109-
return new L.BingLayer(params.key, params.options);
209+
210+
if (!leafletHelpers.HeatLayerPlugin.isLoaded()) {
211+
$log.warn(errorHeader + ' The heatlayer plugin is not loaded.');
212+
return;
213+
}
214+
return L.esri.heatmapFeatureLayer(params.url, params.options);
110215
}
111216
},
217+
agsImage: {
218+
mustHaveUrl: true,
219+
createLayer: function createLayer(params) {
220+
if (!leafletHelpers.AGSImageMapLayerPlugin.isLoaded()) {
221+
$log.warn(errorHeader + ' The esri plugin is not loaded.');
222+
return;
223+
}
224+
params.options.url = params.url;
112225

113-
wfs: {
226+
return L.esri.imageMapLayer(params.options);
227+
}
228+
},
229+
agsTiled: {
114230
mustHaveUrl: true,
115-
mustHaveLayer: true,
116231
createLayer: function createLayer(params) {
117-
if (!leafletHelpers.WFSLayerPlugin.isLoaded()) {
118-
$log.error(errorHeader + ' The WFSLayer plugin is not loaded.');
232+
if (!leafletHelpers.AGSTiledMapLayerPlugin.isLoaded()) {
233+
$log.warn(errorHeader + ' The esri plugin is not loaded.');
119234
return;
120235
}
121-
var options = angular.copy(params.options);
122-
if (options.crs && 'string' === typeof options.crs) {
123-
options.crs = eval(options.crs);
236+
237+
params.options.url = params.url;
238+
239+
return L.esri.tiledMapLayer(params.options);
240+
}
241+
},
242+
bing: {
243+
mustHaveUrl: false,
244+
createLayer: function createLayer(params) {
245+
if (!leafletHelpers.BingLayerPlugin.isLoaded()) {
246+
$log.error(errorHeader + ' The Bing plugin is not loaded.');
247+
return;
124248
}
125-
return new L.GeoJSON.WFS(params.url, params.layer, options);
249+
return new L.BingLayer(params.key, params.options);
126250
}
127251
},
128252

@@ -138,6 +262,18 @@ angular.module('ui-leaflet').config(function ($provide) {
138262
}
139263
},
140264

265+
google: {
266+
mustHaveUrl: false,
267+
createLayer: function createLayer(params) {
268+
var type = params.type || 'SATELLITE';
269+
if (!leafletHelpers.GoogleLayerPlugin.isLoaded()) {
270+
$log.error(errorHeader + ' The GoogleLayer plugin is not loaded.');
271+
return;
272+
}
273+
return new L.Google(type, params.options);
274+
}
275+
},
276+
141277
heat: {
142278
mustHaveUrl: false,
143279
mustHaveData: true,
@@ -157,6 +293,55 @@ angular.module('ui-leaflet').config(function ($provide) {
157293
}
158294
},
159295

296+
here: {
297+
mustHaveUrl: false,
298+
createLayer: function createLayer(params) {
299+
var provider = params.provider || 'HERE.terrainDay';
300+
if (!leafletHelpers.LeafletProviderPlugin.isLoaded()) {
301+
return;
302+
}
303+
return new L.TileLayer.Provider(provider, params.options);
304+
}
305+
},
306+
307+
mapbox: {
308+
mustHaveKey: true,
309+
createLayer: function createLayer(params) {
310+
var version = 3;
311+
if (isDefined(params.options.version) && params.options.version === 4) {
312+
version = params.options.version;
313+
}
314+
var url = version === 3 ? '//{s}.tiles.mapbox.com/v3/' + params.key + '/{z}/{x}/{y}.png' : '//api.tiles.mapbox.com/v4/' + params.key + '/{z}/{x}/{y}.png?access_token=' + params.apiKey;
315+
return L.tileLayer(url, params.options);
316+
}
317+
},
318+
319+
mapboxGL: {
320+
createLayer: function createLayer(params) {
321+
if (!leafletHelpers.MapboxGL.isLoaded()) {
322+
$log.error(errorHeader + ' The MapboxGL plugin is not loaded.');
323+
return;
324+
}
325+
return new L.mapboxGL(params.options);
326+
}
327+
},
328+
329+
markercluster: {
330+
mustHaveUrl: false,
331+
createLayer: function createLayer(params) {
332+
if (!leafletHelpers.MarkerClusterPlugin.isLoaded()) {
333+
$log.warn(errorHeader + ' The markercluster plugin is not loaded.');
334+
return;
335+
}
336+
return new L.MarkerClusterGroup(params.options);
337+
}
338+
},
339+
340+
utfGrid: {
341+
mustHaveUrl: true,
342+
createLayer: utfGridCreateLayer
343+
},
344+
160345
webGLHeatmap: {
161346
mustHaveUrl: false,
162347
mustHaveData: true,
@@ -173,6 +358,22 @@ angular.module('ui-leaflet').config(function ($provide) {
173358
}
174359
},
175360

361+
wfs: {
362+
mustHaveUrl: true,
363+
mustHaveLayer: true,
364+
createLayer: function createLayer(params) {
365+
if (!leafletHelpers.WFSLayerPlugin.isLoaded()) {
366+
$log.error(errorHeader + ' The WFSLayer plugin is not loaded.');
367+
return;
368+
}
369+
var options = angular.copy(params.options);
370+
if (options.crs && 'string' === typeof options.crs) {
371+
options.crs = eval(options.crs);
372+
}
373+
return new L.GeoJSON.WFS(params.url, params.layer, options);
374+
}
375+
},
376+
176377
yandex: {
177378
mustHaveUrl: false,
178379
createLayer: function createLayer(params) {
@@ -183,11 +384,6 @@ angular.module('ui-leaflet').config(function ($provide) {
183384
}
184385
return new L.Yandex(type, params.options);
185386
}
186-
},
187-
188-
utfGrid: {
189-
mustHaveUrl: true,
190-
createLayer: utfGridCreateLayer
191387
}
192388
});
193389

0 commit comments

Comments
 (0)