Advertisement
Guest User

Untitled

a guest
Nov 10th, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. function initialize() {
  2. var map = L.map('map', {
  3. crs: L.CRS.Simple,
  4. minZoom: -5
  5. });
  6. var bounds = [[-100,-100], [100,100]];
  7. var image = L.imageOverlay('uqm_map_full.png', bounds).addTo(map);
  8. //retourne les coordonées pour X,Y
  9. var yx = L.latLng;
  10.  
  11. var xy = function(x, y) {
  12. if (L.Util.isArray(x)) { // When doing xy([x, y]);
  13. return yx(x[1], x[0]);
  14. }
  15. return yx(y, x); // When doing xy(x, y);
  16. };
  17. //entrée des données
  18.  
  19. var centre = L.icon({
  20. iconUrl: 'marker-icon.png',
  21. iconSize: [20, 30],
  22. });
  23.  
  24. var milieu = xy( 0, 0);
  25. L.marker( milieu, {icon: centre}).addTo(map).bindPopup( 'Centre du monde');
  26.  
  27.  
  28. //debut d'insertion de champi
  29.  
  30. let creatures = JSON.parse('<?php echo $jsonC ?>' )
  31. for (creature of creatures) {
  32. console.log("id:", creature.id, creature._x, creature._y, creature._owner)
  33. }
  34. let plantes = JSON.parse('<?php echo $jsonP ?>' )
  35. for (plante of plantes) {
  36. console.log("id:", plante.id, plante._x, plante._y)
  37. }
  38. var c = 0;
  39. NbElems = Object.keys(creatures).length;
  40.  
  41. while (c != NbElems) {
  42.  
  43. var logo = L.icon({
  44. iconUrl: 'creature.png',
  45. iconSize: [10, 10],
  46. });
  47.  
  48. var id = xy( creatures[c]._x, creatures[c]._y);
  49. L.marker( id, {icon: logo}).addTo(map).bindPopup( ' ' + creatures[c]._owner + ' ' );
  50.  
  51. c++;
  52. }
  53. var p = 0;
  54. NbElems = Object.keys(plantes).length;
  55.  
  56. while (p != NbElems) {
  57.  
  58. var logo = L.icon({
  59. iconUrl: 'plante.png',
  60. iconSize: [10, 10],
  61. });
  62.  
  63. var id = xy( plantes[p]._x, plantes[p]._y);
  64. L.marker( id, {icon: logo}).addTo(map).bindPopup( ' ' + plantes[p].id + ' ' );
  65.  
  66. p++;
  67. }
  68.  
  69.  
  70. map.fitBounds(bounds);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement