Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. $.fn.extend
  2. multiMap: (options) ->
  3.  
  4. if !$(@).length > 0
  5. return
  6.  
  7. $self = $(@)
  8.  
  9. settings = {
  10. callback: ()->
  11. }
  12. # mapArr = []
  13. # duration: 500
  14.  
  15. # Merge default settings with options.
  16. settings = $.extend settings, options
  17.  
  18.  
  19. # init = ->
  20. google.load("maps", "3.x", {"other_params":"sensor=false"})
  21. # 作成したマップの呼び出し
  22.  
  23.  
  24.  
  25. initialize = ()->
  26. $self.each (i,e)->
  27.  
  28. # console.log("hello")
  29. obj = {}
  30. # console.log(e)
  31. obj.latLng = new google.maps.LatLng($(e).data('lat'),$(e).data('lng'))
  32. obj.myOptions = {
  33. zoom: 18, #ズームレベル
  34. center: obj.latLng, #中心座標
  35. mapTypeId: google.maps.MapTypeId.ROADMAP,
  36. scrollwheel: false,
  37. mapTypeControl: true, #マップタイプ
  38. mapTypeControlOptions:
  39. mapTypeIds: [
  40. google.maps.MapTypeId.ROADMAP,google.maps.MapTypeId.SATELLITE,
  41. 'simple'
  42. ]
  43. }
  44. if window.devicePixelRatio >= 1.5
  45. obj.myOptions.zoom = 16
  46.  
  47. obj.mapStyle = [
  48. {
  49. "stylers": [
  50. { "visibility": "simplified" },
  51. { "saturation": -100 },
  52. { "gamma": 0.92 },
  53. { "lightness": 38 }
  54. ]
  55. }
  56. ]
  57.  
  58. obj.styleOptions = {
  59. name: "test"
  60. }
  61.  
  62. obj.map = new google.maps.Map(e, obj.myOptions)
  63. google.maps.event.addDomListener window, 'resize', ()->
  64. obj.map.panTo(obj.myOptions.center)
  65.  
  66. obj.mapType = new google.maps.StyledMapType(obj.mapStyle, obj.styleOptions)
  67. obj.map.mapTypes.set('simple', obj.mapType);
  68. obj.map.setMapTypeId('simple');
  69.  
  70.  
  71. if window.devicePixelRatio >= 1.5
  72. obj.marker = new google.maps.Marker(
  73. map: obj.map,
  74. position: new google.maps.LatLng($(e).data('lat'),$(e).data('lng')),
  75. icon: {
  76.  
  77. url: '/images/map/marker@2x.png',
  78. size: new google.maps.Size(130, 154),
  79. anchor : new google.maps.Point(31, 77),
  80. scaledSize: new google.maps.Size(65,77)
  81.  
  82. }
  83. )
  84. else
  85.  
  86. obj.marker = new google.maps.Marker(
  87. map: obj.map,
  88. position: new google.maps.LatLng($(e).data('lat'),$(e).data('lng')),
  89. icon:
  90.  
  91. url: '/images/map/marker.png',
  92. size: new google.maps.Size(65, 77),
  93. origin : new google.maps.Point(0, 0),
  94. anchor : new google.maps.Point(32, 77),
  95.  
  96. ,
  97. )
  98.  
  99. settings.callback({
  100. num :i,
  101. map :obj.map,
  102. latLng:obj.latLng
  103. })
  104.  
  105.  
  106. google.setOnLoadCallback(initialize)
  107.  
  108.  
  109.  
  110.  
  111.  
  112. $('.js-map').multiMap(
  113. callback:(obj)->
  114.  
  115. $(".js-tabs li").eq(obj.num).on 'click', (e)->
  116. tab = e.target.href
  117. tab = "#"+tab.split("#")[1];
  118. $(tab+" .js-map").css({opacity:0})
  119. setTimeout(()->
  120. google.maps.event.trigger(obj.map, 'resize')
  121. obj.map.setCenter(obj.latLng)
  122. $(tab+" .js-map").velocity({opacity:1},500)
  123. ,1000)
  124.  
  125. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement