Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Google maps v3 i zoom przy wyznaczaniu trasy.
muwie
post
Post #1





Grupa: Zarejestrowani
Postów: 30
Pomógł: 1
Dołączył: 21.02.2007
Skąd: Milejów

Ostrzeżenie: (0%)
-----


Witam,
Mam problem. Otóż chce ustalić na sztywno zoom przy wyznaczaniu trasy w google maps. Poniżej przedstawiam wam kod
  1. <!DOCTYPE html>
  2. <head>
  3. <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  4. <meta charset="utf-8">
  5. <title>Google Maps JavaScript API v3 Example: Directions Simple</title>
  6. <link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
  7. <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
  8. var directionDisplay;
  9. var directionsService = new google.maps.DirectionsService();
  10. var map;
  11.  
  12. function initialize() {
  13. directionsDisplay = new google.maps.DirectionsRenderer();
  14. var chicago = new google.maps.LatLng(41.850033, -87.6500523);
  15. var mapOptions = {
  16. zoom:13,
  17. mapTypeId: google.maps.MapTypeId.ROADMAP,
  18. center: chicago,
  19.  
  20. }
  21. map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
  22. directionsDisplay.setMap(map);
  23. }
  24.  
  25. function calcRoute() {
  26.  
  27.  
  28. var start = document.getElementById('skad').value;
  29. var end = document.getElementById('dokad').value;
  30. var request = {
  31. origin:start,
  32. destination:end,
  33. travelMode: google.maps.DirectionsTravelMode.DRIVING
  34. };
  35. directionsService.route(request, function(response, status) {
  36. if (status == google.maps.DirectionsStatus.OK) {
  37. //directionsDisplay.setOptions({ });
  38.  
  39. directionsDisplay.setDirections(response);
  40. }
  41. });
  42. }
  43. </script>
  44. html, body {
  45. height: 100%;
  46. margin: 0;
  47. padding: 0;
  48. }
  49.  
  50. #map_canvas {
  51. height: 100%;
  52. }
  53.  
  54. @media print {
  55. html, body {
  56. height: auto;
  57. }
  58.  
  59. #map_canvas {
  60. height: 650px;
  61. }
  62. }
  63.  
  64. </head>
  65. <body onload="initialize()">
  66. <div>
  67. <b>Start: </b>
  68. <input id="skad">
  69.  
  70. <b>End: </b>
  71. <input id="dokad" >
  72. <input type="button" value="Pokaż" onclick="calcRoute();">
  73. </div>
  74. <div id="map_canvas" style="top:30px;"></div>
  75. </body>
  76. </html>
  77.  

Teraz zoom dobiera się optymalnie, a chciałbym zmniejszyć zoom
Go to the top of the page
+Quote Post
sowiq
post
Post #2





Grupa: Zarejestrowani
Postów: 1 890
Pomógł: 339
Dołączył: 14.12.2006
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


[JAVASCRIPT] pobierz, plaintext
  1. if (status == google.maps.DirectionsStatus.OK) {
  2. //directionsDisplay.setOptions({ });
  3. directionsDisplay.setDirections(response);
  4.  
  5. map.zetZoom(5); // <-- ustawiasz niższy zoom
  6. }
[JAVASCRIPT] pobierz, plaintext


Pewien na 100% nie jestem, ale wydaje mi się, że setDirections wykonuje się synchronicznie i w ten sposób powinno być dobrze.

Ten post edytował sowiq 12.03.2013, 09:56:41
Go to the top of the page
+Quote Post
muwie
post
Post #3





Grupa: Zarejestrowani
Postów: 30
Pomógł: 1
Dołączył: 21.02.2007
Skąd: Milejów

Ostrzeżenie: (0%)
-----


Dzięki za odpowiedź, ale to nie pomogło
Go to the top of the page
+Quote Post
lukasz1985
post
Post #4





Grupa: Zarejestrowani
Postów: 205
Pomógł: 43
Dołączył: 5.03.2012

Ostrzeżenie: (0%)
-----


Możesz wyłączyć zoom na kólku myszy i na sliderze. W tym celu dodaj do mapOptions dwie właściwości:
[JAVASCRIPT] pobierz, plaintext
  1. scaleControl: false, // wyłącza kontrolę zoomu na sliderze
  2. scrollwheel: false // wyłącza kontrole zoomu na kółku mysy
[JAVASCRIPT] pobierz, plaintext


Ten post edytował lukasz1985 12.03.2013, 13:51:51
Go to the top of the page
+Quote Post
sowiq
post
Post #5





Grupa: Zarejestrowani
Postów: 1 890
Pomógł: 339
Dołączył: 14.12.2006
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Zerknij na to https://developers.google.com/maps/document...RendererOptions :

Cytat
preserveViewport (boolean)
By default, the input map is centered and zoomed to the bounding box of this set of directions. If this option is set to true, the viewport is left unchanged, unless the map's center and zoom were never set.


[edit]
Ewentualnie spróbuj tego:
[JAVASCRIPT] pobierz, plaintext
  1. google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
  2. map.setZoom(5);
  3. });
[JAVASCRIPT] pobierz, plaintext


Ten post edytował sowiq 12.03.2013, 13:55:33
Go to the top of the page
+Quote Post
muwie
post
Post #6





Grupa: Zarejestrowani
Postów: 30
Pomógł: 1
Dołączył: 21.02.2007
Skąd: Milejów

Ostrzeżenie: (0%)
-----


  1. directionsDisplay.setOptions({ preserveViewport: true });

Ten kod działa, ale mam pewień problem ponieważ wyznacza mi się trasa ale mapa się nie przesuwa nad trasę

Ten post edytował muwie 13.03.2013, 08:58:03
Go to the top of the page
+Quote Post
sowiq
post
Post #7





Grupa: Zarejestrowani
Postów: 1 890
Pomógł: 339
Dołączył: 14.12.2006
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


@muwie, zgadza się, zgodnie z dokumentacją. Sprawdziłem i faktycznie event wywołuje się jeszcze przed dostosowaniem zooma. Spróbuj takiego obejścia (inne nie przychodzi mi do głowy, bo ta funkcjonalność trochę uboga jest :/):
[JAVASCRIPT] pobierz, plaintext
  1. // po:
  2. directionsDisplay.setMap(map);
  3. // daj to:
  4. var directionsZoom = 5;
  5. google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
  6. setTimeout( function(){ map.setZoom(directionsZoom) }, 50 );
  7. });
[JAVASCRIPT] pobierz, plaintext

Go to the top of the page
+Quote Post
muwie
post
Post #8





Grupa: Zarejestrowani
Postów: 30
Pomógł: 1
Dołączył: 21.02.2007
Skąd: Milejów

Ostrzeżenie: (0%)
-----


Dzięki. Pomogło (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 19.12.2025 - 18:30