-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathMapExtend.js
More file actions
74 lines (69 loc) · 2.31 KB
/
MapExtend.js
File metadata and controls
74 lines (69 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
export var getDefaultVectorTileStyle = function (urlTemplate, options) {
options = options || {};
var defaultOptions = {};
defaultOptions.version = options.version || 8;
defaultOptions.layers = options.layers || [];
defaultOptions.light = options.light || {
"anchor": "viewport",
"color": "#fcf6ef",
"intensity": 0.5,
"position": [1.15, 201, 20]
};
var style = {
"version": defaultOptions.version,
"sources": {
"vector-tiles": {
"type": "vector",
"tiles": [urlTemplate]
}
},
"layers": defaultOptions.layers,
"light": defaultOptions.light
};
if (options.sprite != null) {
style.sprite = options.sprite;
}
if (options.glyphs != null) {
style.glyphs = options.glyphs;
}
return style;
};
export var setBackground = function (map, color) {
if (color && map) {
map.addLayer({
"id": "background",
"type": "background",
"paint": {
"background-color": color
}
}, "background");
}
};
export var setPaintProperty = function (map, layerIds, type, paint, source, sourceLayers) {
if (layerIds && map) {
if (Object.prototype.toString.call(layerIds) !== '[object Array]') {
layerIds = [layerIds];
}
for (var i = 0; i < layerIds.length; i++) {
var sourceLayer = sourceLayers ? sourceLayers[i] : null;
var layer = getLayer(layerIds[i], type, source, sourceLayer, paint);
map.addLayer(layer, layerIds[i]);
map.moveLayer(layerIds[i]);
}
}
};
function getLayer(id, type, source, sourceLayer, paint) {
var sourceType = source || "vector-tiles";
var sLayer = sourceLayer || id;
var layer = {
"id": id,
"type": type,
"source": sourceType,
"source-layer": sLayer,
"paint": paint
};
return layer;
}