Advertisement
Guest User

map.php

a guest
Jun 1st, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.87 KB | None | 0 0
  1. <?php
  2. $owner = JRequest::getVar("owner", "", "GET");
  3. $id = JRequest::getVar("id", "", "GET");
  4. JFactory::getLanguage()->load("contentmap", JPATH_LIBRARIES . "/contentmap");
  5. ?>
  6. imageObjs = new Array();
  7.  
  8. function init_<?php echo $owner; ?>_<?php echo $id; ?>()
  9. {
  10.     if (!data_<?php echo $owner; ?>_<?php echo $id; ?>.places.length)
  11.     {
  12.         // There is no places viewable in this module
  13.         document.getElementById('contentmap_<?php echo $owner; ?>_<?php echo $id; ?>').innerHTML += '<?php echo str_replace("'", "\\'", JText::_("CONTENTMAP_NO_DATA")); ?>';
  14.         return;
  15.     }
  16.  
  17. <?php if ($center = $this->Params->get("center", NULL)) {
  18.     $coordinates = explode(",", $center);
  19.     // Google map js needs them as two separate values (See constructor: google.maps.LatLng(lat, lon))
  20.     $center = new stdClass();
  21.     $center->latitude = floatval($coordinates[0]);
  22.     $center->longitude = floatval($coordinates[1]);
  23.  ?>
  24.     var center = new google.maps.LatLng(<?php echo $center->latitude; ?>, <?php echo $center->longitude; ?>);
  25. <?php } else { ?>
  26.     var center = new google.maps.LatLng(data_<?php echo $owner; ?>_<?php echo $id; ?>.places[0].latitude, data_<?php echo $owner; ?>_<?php echo $id; ?>.places[0].longitude);
  27. <?php } ?>
  28.  
  29.     // Map creation
  30.     var map = new google.maps.Map(document.getElementById('contentmap_<?php echo $owner; ?>_<?php echo $id; ?>'),
  31.     {
  32.         zoom: <?php echo $this->Params->get("zoom", 0); ?>,
  33.         center: center,
  34.         mapTypeId: google.maps.MapTypeId.<?php echo $this->Params->get("map_type", "ROADMAP"); ?>
  35.     });
  36.  
  37. <?php if (!$center) {
  38. // Used only by the module which contains more than one marker but only when a center is not defined
  39. ?>
  40. /*
  41.     if (data_<?php echo $owner; ?>_<?php echo $id; ?>.places.length > 1)
  42.     {
  43.         // Automatic scale and center the map based on the marker points
  44.         var bounds = new google.maps.LatLngBounds();
  45.         var pmin = new google.maps.LatLng(data_<?php echo $owner; ?>_<?php echo $id; ?>.minlatitude, data_<?php echo $owner; ?>_<?php echo $id; ?>.minlongitude);
  46.         var pmax = new google.maps.LatLng(data_<?php echo $owner; ?>_<?php echo $id; ?>.maxlatitude, data_<?php echo $owner; ?>_<?php echo $id; ?>.maxlongitude);
  47.         bounds.extend(pmin);
  48.         bounds.extend(pmax);
  49.         map.fitBounds(bounds);
  50.     }
  51. */
  52. <?php } ?>
  53.  
  54.     // InfoWindow creation
  55.     var infowindow = new google.maps.InfoWindow({maxWidth: <?php echo $this->Params->get("infowindow_width", "200"); ?>});
  56.  
  57.     // Markers creation
  58.     var markers = [];
  59.     var minlatitude = 90.0;
  60.     var maxlatitude = -90.0;
  61.     var minlongitude = 180.0;
  62.     var maxlongitude = -180.0;
  63.  
  64.     for (var i = 0; i < data_<?php echo $owner; ?>_<?php echo $id; ?>.places.length; ++i)
  65.     {
  66.         // Compute bounds rectangle
  67.         minlatitude = Math.min(data_<?php echo $owner; ?>_<?php echo $id; ?>.places[i].latitude, minlatitude);
  68.         maxlatitude = Math.max(data_<?php echo $owner; ?>_<?php echo $id; ?>.places[i].latitude, maxlatitude);
  69.         minlongitude = Math.min(data_<?php echo $owner; ?>_<?php echo $id; ?>.places[i].longitude, minlongitude);
  70.         maxlongitude = Math.max(data_<?php echo $owner; ?>_<?php echo $id; ?>.places[i].longitude, maxlongitude);
  71.  
  72.         // Set marker position
  73.         var pos = new google.maps.LatLng(data_<?php echo $owner; ?>_<?php echo $id; ?>.places[i].latitude, data_<?php echo $owner; ?>_<?php echo $id; ?>.places[i].longitude);
  74.  
  75.         // Marker creation
  76.         var marker = new google.maps.Marker(
  77.         {
  78.             map: map,
  79.             position: pos,
  80.             title: data_<?php echo $owner; ?>_<?php echo $id; ?>.places[i].title,
  81.             zIndex: i
  82.         });
  83.  
  84.         // Custom marker icon if present
  85.         if ("icon" in data_<?php echo $owner; ?>_<?php echo $id; ?>)
  86.         marker.setIcon(data_<?php echo $owner; ?>_<?php echo $id; ?>.icon);
  87.  
  88.         google.maps.event.addListener(marker, '<?php echo $this->Params->get("infowindow_event", "click"); ?>',
  89.         function()
  90.         {
  91. <?php if ($this->Params->get("markers_action") == "infowindow") { ?>
  92.             // InfoWindow handling event
  93.             infowindow.setContent(data_<?php echo $owner; ?>_<?php echo $id; ?>.places[this.getZIndex()].html);
  94.             infowindow.open(map, this);
  95. <?php } else { ?>
  96.             // Redirect handling event
  97.             location.href = data_<?php echo $owner; ?>_<?php echo $id; ?>.places[this.getZIndex()].article_url;
  98. <?php } ?>
  99.         });
  100.  
  101.         markers.push(marker);
  102.     }
  103.  
  104. <?php if (!$center) {
  105. // Set bounds rectangle
  106. // Used only by the module which contains more than one marker but only when a center is not defined
  107. ?>
  108.     if (data_<?php echo $owner; ?>_<?php echo $id; ?>.places.length > 1)
  109.     {
  110.         // Automatic scale and center the map based on the marker points
  111.         var bounds = new google.maps.LatLngBounds();
  112.         var pmin = new google.maps.LatLng(minlatitude, minlongitude);
  113.         var pmax = new google.maps.LatLng(maxlatitude, maxlongitude);
  114.         bounds.extend(pmin);
  115.         bounds.extend(pmax);
  116.         map.fitBounds(bounds);
  117.     }
  118. <?php } ?>
  119.  
  120. <?php if ($this->Params->get("cluster", "1")) { ?>
  121.     // Marker Cluster creation
  122.     var markerCluster = new MarkerClusterer(map, markers);
  123. <?php } ?>
  124. }
  125.  
  126.  
  127. // Preload article images shown inside the infowindows
  128. function preload_<?php echo $owner; ?>_<?php echo $id; ?>()
  129. {
  130.     for (var i = 0; i < data_<?php echo $owner; ?>_<?php echo $id; ?>.places.length; ++i)
  131.     {
  132.         if (data_<?php echo $owner; ?>_<?php echo $id; ?>.places[i].image)
  133.         {
  134.             imageObj = new Image();
  135.             //imageObj.src = data_<?php echo $owner; ?>_<?php echo $id; ?>.baseurl + data_<?php echo $owner; ?>_<?php echo $id; ?>.places[i].image;
  136.             imageObj.src = data_<?php echo $owner; ?>_<?php echo $id; ?>.places[i].image;
  137.             imageObjs.push(imageObj);
  138.         }
  139.     }
  140.  
  141. }
  142.  
  143. google.maps.event.addDomListener(window, 'load', init_<?php echo $owner; ?>_<?php echo $id; ?>);
  144. google.maps.event.addDomListener(window, 'load', preload_<?php echo $owner; ?>_<?php echo $id; ?>);
  145. //window.onload = preload_<?php echo $owner; ?>_<?php echo $id; ?>;
  146. //google.maps.event.addDomListener(document.getElementById("contentmap_<?php echo $owner; ?>_<?php echo $id; ?>"), 'mouseover', preload_<?php echo $owner; ?>_<?php echo $id; ?>);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement