Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. function getCountryColor(popEst){
  2. if(popEst > 100000000){
  3. return 'red';
  4. }else if(popEst > 50000000){
  5. return 'blue';
  6. }else{
  7. return 'green';
  8. }
  9. }
  10.  
  11. function countriesStyle(feature){
  12. return {
  13. fillColor : getCountryColor(feature.properties.pop_est),
  14. weight : 2,
  15. opacity : 1,
  16. color : 'white',
  17. dashArray : 3,
  18. fillOpacity : 0.7
  19. }
  20. }
  21. var popmaps = function(feature,layer){
  22. var popUp = feature.properties.name
  23. layer.bindPopup(String(popUp));
  24. }
  25.  
  26.  
  27. var map = L.map('map').setView([43.8476, 18.3564], 13);//Sets the view of the map (geographical center and zoom) with the given animation options.
  28. var countriesLayer = L.geoJson(
  29. countries,
  30. {style : countriesStyle},{
  31. pointToLayer:function (feature, latlng) {
  32. return L.marker(latlng, {
  33.  
  34. fillColor: "#000000",
  35. color: "green",
  36.  
  37. opacity: 1,
  38.  
  39. });
  40. },
  41. onEachFeature:popmaps
  42. }).addTo(map);
  43.  
  44. L.geoJSON(countries,{
  45. pointToLayer: function (feature, latlng) {
  46. return L.circleMarker(name ,geojsonMarkerOptions);
  47. }
  48. }).addTo(map);
  49.  
  50. map.fitBounds(countriesLayer.getBounds());//in order to cover the whole canvas
  51.  
  52. countriesLayer.on("click", function (event) {//in order to zoom in each layer
  53. // Assuming the clicked feature is a shape, not a point marker.
  54. map.fitBounds(event.layer.getBounds());
  55. });
  56.  
  57. var legend = L.control({position : 'bottomright'});
  58. legend.onAdd = function(map){
  59. var div = L.DomUtil.create('div', 'legend');
  60. var labels = [
  61. "Population greater than 100000000",
  62. "Population greater than 50000000",
  63. "Population equal or less than 50000000"
  64. ];
  65.  
  66.  
  67. var grades = [100000001, 50000001, 50000000];
  68. div.innerHTML = '<div><b>Legend</b></div>';
  69. for(var i = 0; i < grades.length; i++){
  70. div.innerHTML += '<i style="background:'
  71. + getCountryColor(grades[i]) + '">&nbsp;&nbsp;</i>&nbsp;&nbsp;'
  72. + labels[i] + '<br />';
  73. }
  74. return div;
  75. }
  76. legend.addTo(map);
  77. </script>
  78.  
  79. <div id='buttons'>
  80.  
  81. <input type="button" id="l1" value="layer one" onclick="alert('layer one');msgr(); "/>
  82. <input type="button" id="l2" value="layer two" onclick="dofunction();"/>
  83. <input type="button" id="l3" value="layer three" onclick="dofunction(); "/>
  84. </div>
  85.  
  86. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement