PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/views/shortcodes/google_map.php

https://bitbucket.org/extracodingdev2/stamina-functions
PHP | 103 lines | 88 code | 14 blank | 1 comment | 8 complexity | 721985b68b768bb8af1ae26d1a8e863b MD5 | raw file
  1. <?php if ( ! function_exists( 'stamina_google_map_shortcode' ) )
  2. {
  3. function stamina_google_map_shortcode( $atts )
  4. {
  5. $add_height = '';
  6. extract(shortcode_atts( array(
  7. 'lat' => '51.516284',
  8. 'lng' => '-0.127637',
  9. 'map_name' => 'Custom Map',
  10. 'zoom' => 15,
  11. 'map_height' => '400',
  12. 'el_class' => '',
  13. 'marker' => 'default',
  14. 'marker_image' => '',
  15. ), $atts ) );
  16. if ( empty( stamina_option( 'map_api' ) ) ) {
  17. return;
  18. }
  19. $map_name = "google_map_" . uniqid();
  20. if ( $map_height != '' ) {
  21. $add_height = 'height: '. $map_height . 'px;';
  22. }
  23. // Classes
  24. $css_classes = array(
  25. $map_name,
  26. $el_class,
  27. );
  28. $classes = trim( implode( ' ', array_filter( array_unique( $css_classes ) ) ) );
  29. $icon = get_template_directory_uri() . '/assets/img/map-marker.png';
  30. if ( ! empty( $marker ) && $marker == 'custom' && ! empty( $marker_image ) ) {
  31. $icon = wp_get_attachment_image_url( $marker_image );
  32. }
  33. $output = '
  34. <script type="text/javascript">
  35. var places = [['.$lat.', '.$lng.', 1]];
  36. function initialize()
  37. {
  38. var mapOptions =
  39. {
  40. scrollwheel: false,
  41. zoom: '.$zoom.',
  42. center: new google.maps.LatLng('.$lat.', '.$lng.'),
  43. mapTypeId:google.maps.MapTypeId.ROADMAP
  44. }
  45. var map = new google.maps.Map(document.getElementById("'.$map_name.'"), mapOptions);
  46. setMarkers(map, places);
  47. }
  48. function setMarkers(map, locations)
  49. {
  50. for (var i = 0; i < locations.length; i++)
  51. {
  52. var place = locations[i];
  53. var myLatLng = new google.maps.LatLng(place[0], place[1]);
  54. var marker = new google.maps.Marker(
  55. {
  56. position: myLatLng,
  57. map: map,
  58. icon:"'.$icon.'",
  59. zIndex: place[2],
  60. animation: google.maps.Animation.BOUNCE
  61. });
  62. var styles = [
  63. {
  64. stylers: [
  65. { hue: "#c5c5c5" },
  66. { saturation: -100 }
  67. ]
  68. },
  69. ];
  70. map.setOptions({styles: styles});
  71. marker.setMap(map);
  72. }
  73. }
  74. google.maps.event.addDomListener(window, "load", initialize);
  75. </script>
  76. ';
  77. $output .= '<div id="'.$map_name.'" style="'.$add_height.'"></div>';
  78. return $output;
  79. }
  80. }
  81. add_shortcode( 'stamina_gmap', 'stamina_google_map_shortcode' ); ?>