forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcartoCSS_darkBlue.html
More file actions
129 lines (115 loc) · 4.31 KB
/
cartoCSS_darkBlue.html
File metadata and controls
129 lines (115 loc) · 4.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>深夜蓝黑风格</title>
<script type="text/javascript" src="../../dist/include-openlayers.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%">
<div id="map" style="margin:0 auto;width: 100%;height: 100%;border: 1px solid #dddddd"></div>
<script type="text" id="cartoCssStr">
/*此处定义不同的颜色变量,在后面可以重复用这些颜色值*/
@waterColor:rgb(2,16,25);
@roadColora:rgb(18,117,142);
@roadColorb:rgb(0,0,0);
@railwayColora:rgb(0,0,0);
@railwayColorb:rgb(0,0,0);
@vegetationColor:rgb(2,16,25);
@continentColor:rgb(8,48,75);
@provinceLineColor:rgb(30,30,30);
/*中国除外的其他国家的图层*/
#World_Continent_pl___China{
polygon-fill:@continentColor;
line-width:1;
line-color:@continentColor;
}
#China_Province_pl___China{
polygon-fill:@continentColor;
line-color:rgba(0,0,0,0);
}
#Arterial_Road_ln___China::one{
line-color:@roadColora;
line-width:2;}
#Arterial_Road_ln___China::two{
line-color:@roadColorb;
line-width:1;}
#Arterial_Road_ln___China___1::one{
line-color:@roadColora;
line-width:2;}
#Arterial_Road_ln___China___1::two{
line-color:@roadColorb;
line-width:1;}
#Arterial_Road_ln___China___1___1::one{
line-color:@roadColora;
line-width:2;}
#Arterial_Road_ln___China___1___1::two{
line-color:@roadColorb;
line-width:1;}
#Main_Road_L___China::one{
line-color:@roadColora;
line-width:2;}
#Main_Road_L___China::two{
line-color:@roadColorb;
line-width:1;}
#Main_Road_L___China___1::one{
line-color:@roadColora;
line-width:2;}
#Main_Road_L___China___1::two{
line-color:@roadColorb;
line-width:1;}
#Main_Road_L___China___1___1::a{
line-color:@roadColora;
line-width:2;}
#Main_Road_L___China___1___1::b{
line-color:@roadColorb;
line-width:1;}
#Hydside_Area_pl___Hydside{
polygon-fill:@waterColor;
line-color:@waterColor;
}
#China_Provinces_L___China400{
line-dasharray:10,10;
line-color:@provinceLineColor;
line-width:1;
}
</script>
<script type="text/javascript">
var url = (window.isLocal ? document.location.protocol + "//" + document.location.host : "http://support.supermap.com.cn:8090")+"/iserver/services/map-china400/rest/maps/China";
new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
var map = new ol.Map({
target: 'map',
controls: ol.control.defaults({attributionOptions: {collapsed: false}})
.extend([new ol.supermap.control.Logo()]),
view: new ol.View({
center: [12957388, 4853991],
zoom: 11
})
});
var stylesOptions = {
url: url,
view: map.getView(),
donotNeedServerCartoCss: true,
cartoCss: document.getElementById("cartoCssStr").text
}
var vectorTileStyles = new ol.supermap.VectorTileStyles(stylesOptions);
var vectorTileOptions = ol.source.VectorTileSuperMapRest.optionsFromMapJSON(url, serviceResult.result);
vectorTileOptions.returnAttributes = false;
var vectorLayer = new ol.layer.VectorTile({
source: new ol.source.VectorTileSuperMapRest(vectorTileOptions),
style: vectorTileStyles.getFeatureStyle
});
map.addLayer(vectorLayer);
map.on('click', function (e) {
map.forEachFeatureAtPixel(e.pixel, function (feature) {
vectorTileStyles.dispatchEvent({type: 'featureSelected',
selectedId: feature.getProperties().id,
layerName: feature.getProperties().layerName
});
return true;
}, {hitTolerance: 5});
vectorLayer.changed();
})
});
</script>
</body>
</html>