Skip to content

Instantly share code, notes, and snippets.

@blackbing
Created December 5, 2011 08:30
Show Gist options
  • Save blackbing/1432860 to your computer and use it in GitHub Desktop.
Save blackbing/1432860 to your computer and use it in GitHub Desktop.
map test
Map = ->
map
markerData = undefined
markers
_routes
init = ->
myOptions =
zoom: 8
center: new google.maps.LatLng(24.518389, 121.528015)
mapTypeId: google.maps.MapTypeId.ROADMAP
map = new google.maps.Map(document.getElementById(args.id), myOptions)
_routes = new Route(map)
$.get args.requestURL, (data) ->
json = $.parseJSON(data)
markerData = json.data
drop()
google.maps.event.addListener map, "mouseup", ->
infowindow.close()
drop = ->
dropMarker = []
bounds = new google.maps.LatLngBounds()
i = 0
while i < markerData["subject"].length
data =
content: markerData.content[i]
icon: markerData.icon[i]
lat: markerData.lat[i]
link: markerData.link[i]
lng: markerData.lng[i]
picture: markerData.picture[i]
subject: markerData.subject[i]
bounds.extend new google.maps.LatLng(data["lng"], data["lat"])
dropMarker.push data
i++
map.fitBounds bounds
waypts = []
i = 0
while i < dropMarker.length
mkr = addMarker(dropMarker[i])
if i > 0 and i < dropMarker.length - 1
waypts.push
location: mkr.getPosition()
stopover: true
i++
start = markers[0].getPosition()
end = markers[markers.length - 1].getPosition()
_routes.go start, end, waypts
addMarker = (data) ->
contentString = [ "<div class=\"map\"><div class=\"map_content\">" + "<h2><a href=\"" + data["link"] + "\" class=\"link_blue3 text_tab\">" + data["subject"] + "</a></h2>", "<div class=\"map_picture\"><a href=\"" + data["link"] + "\"><img src=\"" + data["picture"] + "\" width=192 height=142 border=0 class=\"imgbox\"></a></div>", "<div class=\"p_tab Text\">" + data["content"] + "</div>", "</div></div>" ].join("")
icon = new google.maps.MarkerImage(data["icon"], new google.maps.Size(32, 32), new google.maps.Point(0, 0), new google.maps.Point(16, 32))
marker = new google.maps.Marker(
position: new google.maps.LatLng(data["lng"], data["lat"])
map: map
draggable: false
icon: icon
animation: google.maps.Animation.DROP
)
marker.contentString = contentString
google.maps.event.addListener marker, "click", ->
infowindow.setContent contentString
infowindow.open map, marker
markers.push marker
marker
args = arguments[0]
markerData = []
markers = []
infowindow = new google.maps.InfoWindow()
init()
window.Map = Map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment