Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Problem z szarym tłem na mapie (mapa źle się wczytuje)
northwest
post 19.06.2019, 16:40:19
Post #1





Grupa: Zarejestrowani
Postów: 788
Pomógł: 1
Dołączył: 17.09.2004

Ostrzeżenie: (10%)
X----


Witam serdecznie.
Mam mapkę w Open Street Maps: http://serwer1356363.home.pl/pub/test/mapa.html
Podgląd: https://ibb.co/x8mqR62


Mój kod wygląda następująco:
  1.  
  2. <script type="text/javascript">
  3.  
  4. function onLocationFound(e) {
  5. var radius = e.accuracy / 2;
  6. lat = e.latlng.lat;
  7. lng = e.latlng.lng;
  8.  
  9. L.marker(e.latlng).addTo(map).bindPopup("Tutaj jesteś!!!");
  10. //L.circle(e.latlng, radius).addTo(map);
  11.  
  12. map.setView([lat, lng], 12);
  13. }
  14.  
  15. function onLocationError(e) {
  16. //alert(e.message);
  17. console.log(e.message);
  18. }
  19.  
  20.  
  21. var map = L.map('mapdiv', {
  22. editable: true,
  23. fadeAnimation: false
  24. }).setView([54.35070881441067, 18.641191756395074], 12);
  25. L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  26. // L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  27. attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors',
  28. maxZoom: 18, zoomControl: true, detectRetina: true
  29. }).addTo(map);
  30.  
  31.  
  32.  
  33.  
  34.  
  35. let myFilter = ['grayscale:100%'];
  36.  
  37. let myTileLayer = L.tileLayer.colorFilter('https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png', {
  38. attribution: '<a href="https://wikimediafoundation.org/wiki/Maps_Terms_of_Use">Wikimedia</a>',
  39. filter: myFilter,
  40. }).addTo(map);
  41.  
  42.  
  43. // lc = L.control.locate({
  44. // strings: {
  45. // title: "Pokaż gdzie jestem"
  46. // }
  47. // }).addTo(map);
  48.  
  49.  
  50. var LeafIcon = L.Icon.extend({
  51. options: {
  52. iconSize: [25, 29],
  53. iconAnchor: [25, 29],
  54. popupAnchor: [-12, -22]
  55. }
  56. });
  57.  
  58.  
  59. L.icon = function (options) {
  60. return new L.Icon(options);
  61. };
  62.  
  63.  
  64. var icons = {
  65. greenIcon: new LeafIcon({iconUrl: '{{asset('assets/images/ikon19.png')}}'}),
  66. redIcon: new LeafIcon({iconUrl: '{{asset('assets/images/ikon20.png')}}'}),
  67. blackIcon: new LeafIcon({iconUrl: '{{asset('assets/images/ikon20.png')}}'})
  68. }
  69.  
  70.  
  71. var image = '';
  72. $.ajax({
  73. url: '{{url('/getPointForMap')}}',
  74. method: 'get',
  75. cache: false,
  76. success: function (data) {
  77. $.each(JSON.parse(data), function(i, poi) {
  78. if (poi.photo != ''){
  79. image = '<img src="'+poi.photo+'" class="mapImgF"><br/>';
  80. }
  81. L.marker([poi.lat, poi.lng], {icon: icons[poi.marker]}).addTo(map).addTo(map).bindPopup('<a href="'+poi.url+'">' + image + '<div class="mapTitleF">' + poi.name + '</div>' + '<div class="mapDescF"> ocena: ' + poi.score + '<br/>' + poi.price + ' </div></a>', {maxWidth: "auto", closeOnClick: true});
  82. });
  83. }
  84. });
  85.  
  86. map.on('locationfound', onLocationFound);
  87. map.on('locationerror', onLocationError);
  88. map.locate({setView: true, maxZoom: 18});
  89.  
  90. </script>
  91.  
  92. <style type="text/css">
  93. #mapdiv {
  94. height: 600px;
  95. width:100%;
  96. }
  97.  
  98. </style>




W jaki sposób można naprawić to szare tło?
Go to the top of the page
+Quote Post
nospor
post 19.06.2019, 16:49:57
Post #2





Grupa: Moderatorzy
Postów: 36 446
Pomógł: 6292
Dołączył: 27.12.2004




Gdy nawet lekko sie zmieni obszar przegladarki to mapa sie "naprawia". Wyglada wiec to na to, ze na poczatku ma zle wymiary.

Sprobuj moze przeniesc o to
<style type="text/css">
#mapdiv {
height: 600px;
width:100%;
}

</style>

przed tworzeniem mapy a nie po


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.04.2024 - 10:39