netmon.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. var map;
  2. var tenantList = [];
  3. var providerList = [];
  4. function init() {
  5. map = L.map('map', { zoomControl:true }).setView([47.078, 3.812], 6);
  6. // #6/46.823/6.669
  7. if (L.Browser.mobile) {
  8. map.removeControl(map.zoomControl);
  9. }
  10. var mapnikUrl = 'http://b.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png';
  11. var vmfabsUrl = 'https://tiles.wmflabs.org/hillshading/{z}/{x}/{y}.png';
  12. var osmUrl='https://a.tile.openstreetmap.org/{z}/{x}/{y}.png';
  13. var ignsatUrl='https://wxs.ign.fr/3tz7turb776yzy17kwux3nkf/geoportail/wmts?layer=ORTHOIMAGERY.ORTHOPHOTOS&style=normal&tilematrixset=PM&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image/jpeg&TileMatrix={z}&TileCol={x}&TileRow={y}';
  14. var ignUrl='https://wxs.ign.fr/3tz7turb776yzy17kwux3nkf/geoportail/wmts?layer=GEOGRAPHICALGRIDSYSTEMS.MAPS&style=normal&tilematrixset=PM&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image/jpeg&TileMatrix={z}&TileCol={x}&TileRow={y}';
  15. var minimal = L.tileLayer(mapnikUrl, { maxZoom: 18 });
  16. var vmfabs = L.tileLayer(vmfabsUrl, { maxZoom: 18 });
  17. var osm = L.tileLayer(osmUrl, { maxZoom: 18 });
  18. var ignsat = L.tileLayer(ignsatUrl, { maxZoom: 18 });
  19. var ign = L.tileLayer(ignUrl, { maxZoom: 18 });
  20. var baseMaps = {
  21. 'HillShade': vmfabs,
  22. 'OSM': osm,
  23. 'IGN': ign,
  24. 'Minimal': minimal,
  25. 'Satellite': ignsat,
  26. };
  27. facilities=new L.layerGroup();
  28. network=new L.layerGroup();
  29. var overlayMaps = {
  30. 'Locations': facilities,
  31. 'Network': network,
  32. }
  33. L.control.layers(baseMaps, overlayMaps, { autoZIndex: true }).addTo(map);
  34. osm.addTo(map);
  35. load_geojson(tenantList, providerList);
  36. $('#sidebar').hide();
  37. $("#sidebar_button").click(function() {
  38. $("#sidebar").toggle();
  39. }).tooltip({
  40. placement : 'left',
  41. title : 'Afficher/masquer la sidebar'
  42. });
  43. var first_coord = [0, 0];
  44. var second_coord = [0, 0];
  45. var string_coord = '';
  46. $("#gpspos").html('C1 : ' + first_coord[0] + " / " + first_coord[1] + '<br/>C2 : ' + second_coord[0] + " / " + second_coord[1]);
  47. map.on('click', function(e) {
  48. if (first_coord[0] == 0) {
  49. first_coord = [ e.latlng.lat.toString().slice(0,9), e.latlng.lng.toString().slice(0,8) ];
  50. string_coord = 'GPSPOS : '+ first_coord[0] + " / " + first_coord[1] + '<br/><a href=# onClick=pop_nearby_links("'+first_coord[0]+'","'+first_coord[1]+'")>Spectre hertzien à proximité</a>';
  51. } else if (second_coord[0] == 0) {
  52. second_coord = [ e.latlng.lat.toString().slice(0,9), e.latlng.lng.toString().slice(0,8) ];
  53. string_coord = 'C1 : ' + first_coord[0] + " / " + first_coord[1] + '<br/>C2 : ' + second_coord[0] + " / " + second_coord[1] + '<br/><a href=# onClick=pop_heywhatsthat("'+first_coord[0]+','+first_coord[1]+',,6","'+second_coord[0]+','+second_coord[1]+',,6")>Vue &eacute;levation</a>';
  54. } else {1
  55. first_coord = [0, 0];
  56. second_coord = [0, 0];
  57. string_coord = '';
  58. }
  59. $("#gpspos").html(string_coord);
  60. });
  61. var hash = new L.Hash(map);
  62. }
  63. function load_geojson (tenantList, providerList) {
  64. var geojsonMarkerOptions = {
  65. radius: 6,
  66. color: "#000",
  67. fill: 1,
  68. weight: 1,
  69. opacity: 1,
  70. zindex: 1,
  71. fillOpacity: 1,
  72. draggable: true
  73. };
  74. var geojsonPolyLineOptions = {
  75. weight: 3,
  76. fill: 1,
  77. zindex: 2,
  78. opacity: 0.8,
  79. };
  80. var okProdMarker = L.icon({
  81. iconUrl: 'images/green.png',
  82. iconAnchor: [ 8, 8 ],
  83. });
  84. var nokProdMarker = L.icon({
  85. iconUrl: 'images/red.png',
  86. iconAnchor: [ 8, 8 ],
  87. });
  88. var worktodoProdMarker = L.icon({
  89. iconUrl: 'images/worker_sign.png',
  90. iconAnchor: [ 10, 10 ],
  91. });
  92. var waitingMarker = L.icon({
  93. iconUrl: 'images/yellow.png',
  94. iconAnchor: [ 8, 8 ],
  95. });
  96. var terminatedMarker = L.icon({
  97. iconUrl: 'images/blue.png',
  98. inconAnchor: [ 8, 8 ],
  99. });
  100. var eligibleMarker = L.icon({
  101. iconUrl: 'images/purple.png',
  102. iconAnchor: [ 8, 8 ],
  103. });
  104. // On load le réseau
  105. $.get("https://netbox.polyno.me/circuits/circuits/geojson/", function(data) {
  106. var geojsonLayer = new L.GeoJSON(data, {
  107. style: function(feature) {
  108. if (feature.geometry.type == 'LineString') {
  109. geojsonPolyLineOptions.color = '#009900';
  110. // feature.properties.color;
  111. return geojsonPolyLineOptions;
  112. }
  113. },
  114. onEachFeature: function(feature, layer) {
  115. if (feature.geometry.type == 'LineString') {
  116. layer.on({
  117. click: function(e) {
  118. createPopup(e.target.feature, e.target);
  119. // e.target.openPopup();
  120. }
  121. });
  122. }
  123. }
  124. } );
  125. network.clearLayers();
  126. network.addLayer(geojsonLayer);
  127. network.addTo(map);
  128. map.almostOver.addLayer(network);
  129. map.on('almost:click', function (e) { e.layer.fire('click', e); });
  130. });
  131. $.get("https://netbox.polyno.me/dcim/facilities/geojson/", function(data) {
  132. var geojsonLayer = new L.GeoJSON(data, {
  133. style: function(feature) {
  134. return {fillColor: '#009900'};
  135. },
  136. pointToLayer: function(feature, latlng) {
  137. geojsonMarkerOptions.icon=okProdMarker;
  138. return L.marker(latlng, geojsonMarkerOptions);
  139. },
  140. onEachFeature: function(feature, layer) {
  141. createPopup(feature, layer);
  142. }
  143. } );
  144. facilities.clearLayers();
  145. facilities.addLayer(geojsonLayer);
  146. facilities.addTo(map);
  147. });
  148. }
  149. function createPopup (feature, layer) {
  150. console.log(feature.geometry.type);
  151. if (feature.geometry.type == 'Point') {
  152. var divNode = document.createElement('DIV');
  153. divNode.setAttribute('style', 'width:450px');
  154. divNode.innerHTML = '<h4 align="center">'+feature.properties.name+' ('+feature.properties.description+')</h4>';
  155. for (var i in feature.properties.sites) {
  156. var site = feature.properties.sites[i];
  157. divNode.innerHTML = divNode.innerHTML + site.tenant+' (AS'+site.asn+')<br/>';
  158. }
  159. console.log(divNode.innerHTML);
  160. return layer.bindPopup(divNode, { maxWidth:450 });
  161. } else if (feature.geometry.type == 'LineString') {
  162. var divNode = document.createElement('DIV');
  163. divNode.setAttribute('style', 'width:450px');
  164. divNode.innerHTML = '<h4 align="center">'+feature.properties.link_type+' '+feature.properties.provider+' ('+feature.properties.tenant+')</h4>';
  165. divNode.innerHTML = divNode.innerHTML + 'Commit : '+(feature.properties.commit/1000)+'Mbps <br/>Ports speed : '+(feature.properties.port_speed_a/1000)+'Mbps / '+(feature.properties.port_speed_b/1000)+'Mbps';
  166. console.log(divNode.innerHTML);
  167. return layer.bindPopup(divNode, { maxWidth:450 });
  168. }
  169. }
  170. Number.prototype.toRad = function() {
  171. return this * Math.PI / 180;
  172. }
  173. Number.prototype.toDeg = function() {
  174. return this * 180 / Math.PI;
  175. }