Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 KB | None | 0 0
  1. var map;
  2. var google_api_key = "ljkjGcnvIaN-4HXq45A7Q-HD"
  3. function main() {
  4. //var google_api_key = "ljkjGcnvIaN-4HXq45A7Q-HD"
  5.  
  6. // Map center
  7. var myLatlng = new google.maps.LatLng(42.358, -71.07);
  8. var myOptions = {
  9. zoom: 14,
  10. center: myLatlng,
  11. disableDefaultUI: true,
  12. zoomControl: true,
  13. mapTypeId: google.maps.MapTypeId.ROADMAP
  14. }
  15. // Render basemap
  16. map = new google.maps.Map(document.getElementById("map"), myOptions);
  17.  
  18. map.set('styles', [
  19. {
  20. featureType: "road",
  21. elementType: "geometry",
  22. stylers: [
  23. { visibility: "on" }
  24. ]
  25. },
  26. {
  27. featureType: "road.highway",
  28. elementType: "geometry",
  29. stylers: [
  30. { lightness: 100 },
  31. ]
  32. },
  33. {
  34. featureType: "road",
  35. elementType: "labels",
  36. stylers: [
  37. { lightness: 20},
  38. {visibility: "off" }
  39.  
  40. ]
  41. },
  42. {
  43. featureType: "road.highway",
  44. elementType: "labels",
  45. stylers: [
  46. { visibility: "off" }
  47. ]
  48. },
  49.  
  50. {
  51. featureType: "poi.business",
  52. stylers: [
  53. { visibility: "off" }
  54. ]
  55. },
  56. {
  57. featureType: "poi.government",
  58. stylers: [
  59. { visibility: "off" }
  60. ]
  61. },
  62. {
  63. featureType: "poi.attraction",
  64. stylers: [
  65. { visibility: "off" }
  66. ]
  67. },
  68. {
  69. featureType: "poi.medical",
  70. stylers: [
  71. { visibility: "off" }
  72. ]
  73. },
  74. {
  75. featureType: "poi.place_of_worship",
  76. stylers: [
  77. { visibility: "off" }
  78. ]
  79. },
  80. {
  81. featureType: "poi.sports_complex",
  82. stylers: [
  83. { visibility: "off" }
  84. ]
  85. },
  86. {
  87. featureType: "poi.school",
  88. stylers: [
  89. { visibility: "off" }
  90. ]
  91. },
  92. {
  93. featureType: "poi.park",
  94. elementType: "labels.icon",
  95. stylers: [
  96. { visibility: "off" }
  97. ]
  98. },
  99. {
  100. featureType: "landscape",
  101. elementType: "labels.icon",
  102. stylers: [
  103. { visibility: "off" }
  104. ]
  105. },
  106. {
  107. featureType: "administrative",
  108. elementType: "labels.icon",
  109. stylers: [
  110. { visibility: "off" }
  111. ]
  112. },
  113. {
  114. featureType: "transit.station",
  115. stylers: [
  116. {visibility: "off" }
  117. ]
  118. },
  119. {
  120. featureType: "poi",
  121. elementType: "labels.icon",
  122. stylers: [
  123. { visibility: "off" }
  124. ]
  125. },
  126. {
  127. featureType: "road.local",
  128. elementType: "labels",
  129. stylers: [
  130. { visibility: "on" }
  131. ]
  132. }
  133. ]);
  134.  
  135.  
  136.  
  137. // Put layer data into a JS object
  138. var layerSource = 'http://evalugo21.cartodb.com/api/v2/viz/100ff358-bbe8-11e4-ab27-0e9d821ea90d/viz.json';
  139.  
  140.  
  141. // For storing the sublayers
  142. var sublayers = [];
  143.  
  144. var cdbOptions = {
  145. cartodb_logo: false,
  146. mobile_layout: true
  147. }
  148. // Add data layer to your map
  149. cartodb.createLayer(map,layerSource, cdbOptions)
  150. .addTo(map)
  151. .done(function(layer) {
  152. //console.log(layer);
  153. var num_sublayers = layer.getSubLayerCount();
  154.  
  155. for (var i = 0; i < num_sublayers; i++) {
  156. sublayers[i] = layer.getSubLayer(i);
  157. //console.log(sublayers[i]);
  158. }
  159.  
  160.  
  161. var sublayer0Shown = true;
  162. $("#sublayer0").on('click', function() {
  163. if (sublayer0Shown) {
  164. sublayers[0].hide();
  165. sublayers[1].hide();
  166. $("#switch1").removeClass('right switch enabled');
  167. $("#switch1").addClass('right switch disabled');
  168.  
  169. } else {
  170. sublayers[0].show();
  171. sublayers[1].show();
  172. $("#switch1").removeClass('right switch disabled');
  173. $("#switch1").addClass('right switch enabled');
  174. }
  175. sublayer0Shown = !sublayer0Shown;
  176. });
  177.  
  178. var sublayer1Shown = true;
  179. $("#sublayer1").on('click', function() {
  180. if (sublayer1Shown) {
  181. sublayers[2].hide();
  182. sublayers[3].hide();
  183. $("#switch2").removeClass('right switch enabled');
  184. $("#switch2").addClass('right switch disabled');
  185. } else {
  186. sublayers[2].show();
  187. sublayers[3].show();
  188. $("#switch2").removeClass('right switch disabled');
  189. $("#switch2").addClass('right switch enabled');
  190. }
  191. sublayer1Shown = !sublayer1Shown;
  192. });
  193.  
  194.  
  195. })
  196. .error(function(err) {
  197. console.log("error: " + err);
  198. });
  199.  
  200.  
  201.  
  202. }
  203.  
  204. window.onload = main;
  205.  
  206. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement