mapbox-streets-v6-style.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. // Styles for the mapbox-streets-v6 vector tile data set. Loosely based on
  2. // http://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6.json
  3. function createMapboxStreetsV6Style() {
  4. var fill = new ol.style.Fill({
  5. color: ''
  6. });
  7. var stroke = new ol.style.Stroke({
  8. color: '',
  9. width: 1
  10. });
  11. var polygon = new ol.style.Style({
  12. fill: fill
  13. });
  14. var strokedPolygon = new ol.style.Style({
  15. fill: fill,
  16. stroke: stroke
  17. });
  18. var line = new ol.style.Style({
  19. stroke: stroke
  20. });
  21. var text = new ol.style.Style({
  22. text: new ol.style.Text({
  23. text: '',
  24. fill: fill,
  25. stroke: stroke
  26. })
  27. });
  28. var point = new ol.style.Style({
  29. image: new ol.style.Circle({
  30. radius: 5,
  31. fill: new ol.style.Fill({color: 'red'})
  32. })
  33. })
  34. var iconCache = {};
  35. function getIcon(iconName) {
  36. var icon = iconCache[iconName];
  37. if (!icon) {
  38. icon = new ol.style.Style({
  39. image: new ol.style.Icon({
  40. src: (iconName === 'marker' ? 'static/marker-15.svg' : 'https://cdn.rawgit.com/mapbox/maki/master/icons/' + iconName + '-15.svg'),
  41. imgSize: [15, 15]
  42. })
  43. });
  44. iconCache[iconName] = icon;
  45. }
  46. return icon;
  47. }
  48. var styles = [];
  49. return function (feature, resolution) {
  50. var length = 0;
  51. var layer = feature.get('layer');
  52. var cls = feature.get('class');
  53. var type = feature.get('type');
  54. var scalerank = feature.get('scalerank');
  55. var labelrank = feature.get('labelrank');
  56. var adminLevel = feature.get('admin_level');
  57. var maritime = feature.get('maritime');
  58. var disputed = feature.get('disputed');
  59. var maki = feature.get('maki');
  60. var geom = feature.getGeometry().getType();
  61. if (geom === 'Point') {
  62. layer = 'point'
  63. feature.properties_.name_en = feature.get('NAME_CHN')
  64. }else if(geom ==='Polygon'){
  65. layer = 'road'
  66. cls = 'path'
  67. feature.properties_.name_en = feature.get('NAME_CHN')
  68. }
  69. if (layer == 'landuse' && cls == 'park') {
  70. fill.setColor('#d8e8c8');
  71. styles[length++] = polygon;
  72. } else if (layer == 'landuse' && cls == 'cemetery') {
  73. fill.setColor('#e0e4dd');
  74. styles[length++] = polygon;
  75. } else if (layer == 'landuse' && cls == 'hospital') {
  76. fill.setColor('#fde');
  77. styles[length++] = polygon;
  78. } else if (layer == 'landuse' && cls == 'school') {
  79. fill.setColor('#f0e8f8');
  80. styles[length++] = polygon;
  81. } else if (layer == 'landuse' && cls == 'wood') {
  82. fill.setColor('rgb(233,238,223)');
  83. styles[length++] = polygon;
  84. } else if (layer == 'waterway' &&
  85. cls != 'river' && cls != 'stream' && cls != 'canal') {
  86. stroke.setColor('#a0c8f0');
  87. stroke.setWidth(1);
  88. styles[length++] = line;
  89. } else if (layer == 'waterway' && cls == 'river') {
  90. stroke.setColor('#a0c8f0');
  91. stroke.setWidth(1);
  92. styles[length++] = line;
  93. } else if (layer == 'waterway' && (cls == 'stream' ||
  94. cls == 'canal')) {
  95. stroke.setColor('#a0c8f0');
  96. stroke.setWidth(1);
  97. styles[length++] = line;
  98. } else if (layer == 'water') {
  99. fill.setColor('#a0c8f0');
  100. styles[length++] = polygon;
  101. } else if (layer == 'aeroway' && geom == 'Polygon') {
  102. fill.setColor('rgb(242,239,235)');
  103. styles[length++] = polygon;
  104. } else if (layer == 'aeroway' && geom == 'LineString' &&
  105. resolution <= 76.43702828517625) {
  106. stroke.setColor('#f0ede9');
  107. stroke.setWidth(1);
  108. styles[length++] = line;
  109. } else if (layer == 'building') {
  110. fill.setColor('#f2eae2');
  111. stroke.setColor('#dfdbd7');
  112. stroke.setWidth(1);
  113. styles[length++] = strokedPolygon;
  114. } else if (layer == 'tunnel' && cls == 'motorway_link') {
  115. stroke.setColor('#e9ac77');
  116. stroke.setWidth(1);
  117. styles[length++] = line;
  118. } else if (layer == 'tunnel' && cls == 'service') {
  119. stroke.setColor('#cfcdca');
  120. stroke.setWidth(1);
  121. styles[length++] = line;
  122. } else if (layer == 'tunnel' &&
  123. (cls == 'street' || cls == 'street_limited')) {
  124. stroke.setColor('#cfcdca');
  125. stroke.setWidth(1);
  126. styles[length++] = line;
  127. } else if (layer == 'tunnel' && cls == 'main' &&
  128. resolution <= 1222.99245256282) {
  129. stroke.setColor('#e9ac77');
  130. stroke.setWidth(1);
  131. styles[length++] = line;
  132. } else if (layer == 'tunnel' && cls == 'motorway') {
  133. stroke.setColor('#e9ac77');
  134. stroke.setWidth(1);
  135. styles[length++] = line;
  136. } else if (layer == 'tunnel' && cls == 'path') {
  137. stroke.setColor('#cba');
  138. stroke.setWidth(1);
  139. styles[length++] = line;
  140. } else if (layer == 'tunnel' && cls == 'major_rail') {
  141. stroke.setColor('#bbb');
  142. stroke.setWidth(2);
  143. styles[length++] = line;
  144. } else if (layer == 'road' && cls == 'motorway_link') {
  145. stroke.setColor('#e9ac77');
  146. stroke.setWidth(1);
  147. styles[length++] = line;
  148. } else if (layer == 'road' && (cls == 'street' ||
  149. cls == 'street_limited') && geom == 'LineString') {
  150. stroke.setColor('#cfcdca');
  151. stroke.setWidth(1);
  152. styles[length++] = line;
  153. } else if (layer == 'road' && cls == 'main' &&
  154. resolution <= 1222.99245256282) {
  155. stroke.setColor('#e9ac77');
  156. stroke.setWidth(1);
  157. styles[length++] = line;
  158. } else if (layer == 'road' && cls == 'motorway' &&
  159. resolution <= 4891.96981025128) {
  160. stroke.setColor('#e9ac77');
  161. stroke.setWidth(1);
  162. styles[length++] = line;
  163. } else if (layer == 'road' && cls == 'path') {
  164. //stroke.setColor('#cba');
  165. stroke.setColor('#f60');
  166. stroke.setWidth(1);
  167. styles[length++] = line;
  168. } else if (layer == 'road' && cls == 'major_rail') {
  169. stroke.setColor('#bbb');
  170. stroke.setWidth(2);
  171. styles[length++] = line;
  172. } else if (layer == 'bridge' && cls == 'motorway_link') {
  173. stroke.setColor('#e9ac77');
  174. stroke.setWidth(1);
  175. styles[length++] = line;
  176. } else if (layer == 'bridge' && cls == 'motorway') {
  177. stroke.setColor('#e9ac77');
  178. stroke.setWidth(1);
  179. styles[length++] = line;
  180. } else if (layer == 'bridge' && cls == 'service') {
  181. stroke.setColor('#cfcdca');
  182. stroke.setWidth(1);
  183. styles[length++] = line;
  184. } else if (layer == 'bridge' &&
  185. (cls == 'street' || cls == 'street_limited')) {
  186. stroke.setColor('#cfcdca');
  187. stroke.setWidth(1);
  188. styles[length++] = line;
  189. } else if (layer == 'bridge' && cls == 'main' &&
  190. resolution <= 1222.99245256282) {
  191. stroke.setColor('#e9ac77');
  192. stroke.setWidth(1);
  193. styles[length++] = line;
  194. } else if (layer == 'bridge' && cls == 'path') {
  195. stroke.setColor('#cba');
  196. stroke.setWidth(1);
  197. styles[length++] = line;
  198. } else if (layer == 'bridge' && cls == 'major_rail') {
  199. stroke.setColor('#bbb');
  200. stroke.setWidth(2);
  201. styles[length++] = line;
  202. } else if (layer == 'admin' && adminLevel >= 3 && maritime === 0) {
  203. stroke.setColor('#9e9cab');
  204. stroke.setWidth(1);
  205. styles[length++] = line;
  206. } else if (layer == 'admin' && adminLevel == 2 &&
  207. disputed === 0 && maritime === 0) {
  208. stroke.setColor('#9e9cab');
  209. stroke.setWidth(1);
  210. styles[length++] = line;
  211. } else if (layer == 'admin' && adminLevel == 2 &&
  212. disputed === 1 && maritime === 0) {
  213. stroke.setColor('#9e9cab');
  214. stroke.setWidth(1);
  215. styles[length++] = line;
  216. } else if (layer == 'admin' && adminLevel >= 3 && maritime === 1) {
  217. stroke.setColor('#a0c8f0');
  218. stroke.setWidth(1);
  219. styles[length++] = line;
  220. } else if (layer == 'admin' && adminLevel == 2 && maritime === 1) {
  221. stroke.setColor('#a0c8f0');
  222. stroke.setWidth(1);
  223. styles[length++] = line;
  224. } else if (layer == 'country_label' && scalerank === 1) {
  225. text.getText().setText(feature.get('name_en'));
  226. text.getText().setFont('bold 11px "Open Sans", "Arial Unicode MS"');
  227. fill.setColor('#334');
  228. stroke.setColor('rgba(255,255,255,0.8)');
  229. stroke.setWidth(2);
  230. styles[length++] = text;
  231. } else if (layer == 'country_label' && scalerank === 2 &&
  232. resolution <= 19567.87924100512) {
  233. text.getText().setText(feature.get('name_en'));
  234. text.getText().setFont('bold 10px "Open Sans", "Arial Unicode MS"');
  235. fill.setColor('#334');
  236. stroke.setColor('rgba(255,255,255,0.8)');
  237. stroke.setWidth(2);
  238. styles[length++] = text;
  239. } else if (layer == 'country_label' && scalerank === 3 &&
  240. resolution <= 9783.93962050256) {
  241. text.getText().setText(feature.get('name_en'));
  242. text.getText().setFont('bold 9px "Open Sans", "Arial Unicode MS"');
  243. fill.setColor('#334');
  244. stroke.setColor('rgba(255,255,255,0.8)');
  245. stroke.setWidth(2);
  246. styles[length++] = text;
  247. } else if (layer == 'country_label' && scalerank === 4 &&
  248. resolution <= 4891.96981025128) {
  249. text.getText().setText(feature.get('name_en'));
  250. text.getText().setFont('bold 8px "Open Sans", "Arial Unicode MS"');
  251. fill.setColor('#334');
  252. stroke.setColor('rgba(255,255,255,0.8)');
  253. stroke.setWidth(2);
  254. styles[length++] = text;
  255. } else if (layer == 'marine_label' && labelrank === 1 &&
  256. geom == 'Point') {
  257. text.getText().setText(feature.get('name_en'));
  258. text.getText().setFont(
  259. 'italic 11px "Open Sans", "Arial Unicode MS"');
  260. fill.setColor('#74aee9');
  261. stroke.setColor('rgba(255,255,255,0.8)');
  262. stroke.setWidth(1);
  263. styles[length++] = text;
  264. } else if (layer == 'marine_label' && labelrank === 2 &&
  265. geom == 'Point') {
  266. text.getText().setText(feature.get('name_en'));
  267. text.getText().setFont(
  268. 'italic 11px "Open Sans", "Arial Unicode MS"');
  269. fill.setColor('#74aee9');
  270. stroke.setColor('rgba(255,255,255,0.8)');
  271. stroke.setWidth(1);
  272. styles[length++] = text;
  273. } else if (layer == 'marine_label' && labelrank === 3 &&
  274. geom == 'Point') {
  275. text.getText().setText(feature.get('name_en'));
  276. text.getText().setFont(
  277. 'italic 10px "Open Sans", "Arial Unicode MS"');
  278. fill.setColor('#74aee9');
  279. stroke.setColor('rgba(255,255,255,0.8)');
  280. stroke.setWidth(1);
  281. styles[length++] = text;
  282. } else if (layer == 'marine_label' && labelrank === 4 &&
  283. geom == 'Point') {
  284. text.getText().setText(feature.get('name_en'));
  285. text.getText().setFont(
  286. 'italic 9px "Open Sans", "Arial Unicode MS"');
  287. fill.setColor('#74aee9');
  288. stroke.setColor('rgba(255,255,255,0.8)');
  289. stroke.setWidth(1);
  290. styles[length++] = text;
  291. } else if (layer == 'place_label' && type == 'city' &&
  292. resolution <= 1222.99245256282) {
  293. text.getText().setText(feature.get('name_en'));
  294. text.getText().setFont('11px "Open Sans", "Arial Unicode MS"');
  295. fill.setColor('#333');
  296. stroke.setColor('rgba(255,255,255,0.8)');
  297. stroke.setWidth(1);
  298. styles[length++] = text;
  299. } else if (layer == 'place_label' && type == 'town' &&
  300. resolution <= 305.748113140705) {
  301. text.getText().setText(feature.get('name_en'));
  302. text.getText().setFont('9px "Open Sans", "Arial Unicode MS"');
  303. fill.setColor('#333');
  304. stroke.setColor('rgba(255,255,255,0.8)');
  305. stroke.setWidth(1);
  306. styles[length++] = text;
  307. } else if (layer == 'place_label' && type == 'village' &&
  308. resolution <= 38.21851414258813) {
  309. text.getText().setText(feature.get('name_en'));
  310. text.getText().setFont('8px "Open Sans", "Arial Unicode MS"');
  311. fill.setColor('#333');
  312. stroke.setColor('rgba(255,255,255,0.8)');
  313. stroke.setWidth(1);
  314. styles[length++] = text;
  315. } else if (layer == 'place_label' &&
  316. resolution <= 19.109257071294063 && (type == 'hamlet' ||
  317. type == 'suburb' || type == 'neighbourhood')) {
  318. text.getText().setText(feature.get('name_en'));
  319. text.getText().setFont('bold 9px "Arial Narrow"');
  320. fill.setColor('#633');
  321. stroke.setColor('rgba(255,255,255,0.8)');
  322. stroke.setWidth(1);
  323. styles[length++] = text;
  324. } else if (layer == 'poi_label' && resolution <= 19.109257071294063 &&
  325. scalerank == 1 && maki !== 'marker') {
  326. styles[length++] = getIcon(maki);
  327. } else if (layer == 'poi_label' && resolution <= 9.554628535647032 &&
  328. scalerank == 2 && maki !== 'marker') {
  329. styles[length++] = getIcon(maki);
  330. } else if (layer == 'poi_label' && resolution <= 4.777314267823516 &&
  331. scalerank == 3 && maki !== 'marker') {
  332. styles[length++] = getIcon(maki);
  333. } else if (layer == 'poi_label' && resolution <= 2.388657133911758 &&
  334. scalerank == 4 && maki !== 'marker') {
  335. styles[length++] = getIcon(maki);
  336. } else if (layer == 'poi_label' && resolution <= 1.194328566955879 &&
  337. scalerank >= 5 && maki !== 'marker') {
  338. styles[length++] = getIcon(maki);
  339. } else if (layer == 'point' && geom == 'Point') {
  340. // text.getText().setText(feature.get('name_en'));
  341. // text.getText().setFont(
  342. // 'italic 11px "Open Sans", "Arial Unicode MS"');
  343. // fill.setColor('#74aee9');
  344. // stroke.setColor('rgba(255,255,255,0.8)');
  345. // stroke.setWidth(1);
  346. // styles[length++] = text;
  347. styles[length++] = point
  348. }
  349. styles.length = length;
  350. console.log(styles)
  351. return styles;
  352. };
  353. }