Advertisement
dammarpol

problem with setting global variable

Oct 16th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.  $(document).ready(function() {
  3.     // var pic = 'http://muzeum.pyramidlab.pl/uploads/Maps/muzeum.jpg';
  4.     var pic;
  5.         $('#Exhibits_isVisible').change(function(){
  6.         if($('#Exhibits_isVisible').is(':checked'))
  7.             $(this).attr('value','1');
  8.         else
  9.            $(this).attr('value','0');
  10.        });
  11.        
  12.         display = function(value) {
  13.        // $('#test').html("Id wybranej mapy: " + value);
  14.        /*$.getJSON( ", function( data ) {
  15.         console.log(data);
  16.         $('#test').html("URl wybranej mapy: " + data);
  17.        });*/
  18.         $.ajax({
  19.             //dataType: "json",
  20.             url: "<?php echo $this->createUrl('/map/getPictureMapById') ?>/id/" +  value,
  21.             success: function(data){
  22.                // console.log(data);
  23.                 //$('#test').html("URl wybranej mapy: " + data);
  24.                 pic = data;
  25.                 console.log(pic);
  26.             }
  27.         });
  28.     };
  29.      
  30.        function invokeMap(){
  31.         var floorOverlay;
  32.         var centerOfTheMap = new google.maps.LatLng(51.246613, 22.567874);
  33.         var swBound = new google.maps.LatLng(51.245522, 22.565557);
  34.         var neBound = new google.maps.LatLng(51.247403, 22.569746);
  35.         var imageBounds = new google.maps.LatLngBounds(swBound, neBound);
  36.            
  37.             var allowedBounds = new google.maps.LatLngBounds(
  38.                       new google.maps.LatLng(51.246294, 22.567010),
  39.                       new google.maps.LatLng(51.246926, 22.568571)
  40.                     );
  41.         var mapOptions = {
  42.                 zoom: 19,  
  43.                 zoomControl: false,
  44.                 scrollwheel: false,
  45.                 disableDefaultUI: true,
  46.                 disableDoubleClickZoom: true,
  47.                 center: centerOfTheMap
  48.               };
  49.         var map = new google.maps.Map(document.getElementById('map'),
  50.                   mapOptions);
  51.         var boundLimits = {
  52.                         maxLat : allowedBounds.getNorthEast().lat(),
  53.                         maxLng : allowedBounds.getNorthEast().lng(),
  54.                         minLat : allowedBounds.getSouthWest().lat(),
  55.                         minLng : allowedBounds.getSouthWest().lng()
  56.                     };
  57.  
  58.                     var lastValidCenter = map.getCenter();
  59.                     var newLat, newLng;
  60.                     google.maps.event.addListener(map, 'center_changed', function() {
  61.                         center = map.getCenter();
  62.                                            
  63.                         if (allowedBounds.contains(center)) {
  64.                             lastValidCenter = map.getCenter();
  65.                             return;
  66.                         }
  67.                        
  68.                         newLat = lastValidCenter.lat();
  69.                         newLng = lastValidCenter.lng();
  70.                         if(center.lng() > boundLimits.minLng && center.lng() < boundLimits.maxLng){
  71.                             newLng = center.lng();
  72.                         }
  73.                         if(center.lat() > boundLimits.minLat && center.lat() < boundLimits.maxLat){
  74.                             newLat = center.lat();
  75.                         }
  76.                         map.panTo(new google.maps.LatLng(newLat, newLng));
  77.                        
  78.                     });
  79.                        
  80.                         var marker = new google.maps.Marker({
  81.                         position: centerOfTheMap,
  82.                         map: map,
  83.                         draggable:true,
  84.                         //title:""
  85.                            });
  86.                    
  87.                     function countBounds() {
  88.                         var mapBounds = map.getBounds();
  89.                         var lewyDolny = mapBounds.getSouthWest();
  90.                         var prawyGorny = mapBounds.getNorthEast();
  91.                         var lewo    = mapBounds.lng();
  92.                         var prawo   = mapBounds.lng();
  93.                         var gora    = mapBounds.lat();
  94.                         var dol     = mapBounds.lat();
  95.                         var prawyDolny  = new google.maps.LatLng(dol,prawo);
  96.                         var lewyGorny   = new google.maps.LatLng(gora,lewo);
  97.                     }
  98.                         google.maps.event.addListener(marker, 'dragend', function (event) {
  99.                        document.getElementById("Exhibits_mapPositionX").value = this.getPosition().lat();
  100.                        document.getElementById("Exhibits_mapPositionY").value = this.getPosition().lng();
  101.                        });
  102.                           floorOverlay = new google.maps.GroundOverlay(
  103.                      // 'http://muzeum.pyramidlab.pl/uploads/Maps/muzeum.jpg',
  104.                     pic,  
  105.                                         imageBounds);
  106.               floorOverlay.setMap(map);
  107.                           console.log(pic);
  108.                       };
  109.                       invokeMap();
  110.     });
  111.    
  112. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement