Permalink
Browse files

updated polylines conf

  • Loading branch information...
1 parent 5559b23 commit 2378025a9b91d491bb8c1010039f01983d268337 @slayer slayer committed Mar 2, 2012
View
@@ -2,9 +2,10 @@
*.cache
*.log
*.pid
+.*.sw?
.DS_Store
test/dummy/tmp/**/*
test/dummy/log/**/*
test/dummy/.rvmrc
pkg
-.idea
+.idea
@@ -1,6 +1,6 @@
Gmaps = {}
-Gmaps.loadMaps = ->
+Gmaps.loadMaps = ->
#loop through all variable names.
#there should only be maps inside so it trigger their load function
for key, value of Gmaps
@@ -26,22 +26,22 @@ class @Gmaps4Rails
@infobox = -> false #to let user use custom infoboxes
@jsTemplate = false #to let user create infowindows client side
- @default_map_options =
+ @default_map_options =
id: 'map'
draggable: true
detect_location: false # should the browser attempt to use geolocation detection features of HTML5?
center_on_user: false # centers map on the location detected through the browser
center_latitude: 0
- center_longitude: 0
+ center_longitude: 0
zoom: 7
maxZoom: null
minZoom: null
auto_adjust : true # adjust the map to the markers if set to true
auto_zoom: true # zoom given by auto-adjust
- bounds: [] # adjust map to these limits. Should be [{"lat": , "lng": }]
+ bounds: [] # adjust map to these limits. Should be [{"lat": , "lng": }]
raw: {} # raw json to pass additional options
- @default_markers_conf =
+ @default_markers_conf =
#Marker config
title: ""
#MarkerImage config
@@ -65,15 +65,15 @@ class @Gmaps4Rails
@circles = [] # contains raw data, array of hash
@markerClusterer = null # contains all marker clusterers
@markerImages = []
-
+
#tnitializes the map
initialize : ->
@map = @createMap()
- if (@map_options.detect_location == true or @map_options.center_on_user == true)
- @findUserLocation(this)
+ if (@map_options.detect_location == true or @map_options.center_on_user == true)
+ @findUserLocation(this)
#resets sidebar if needed
@resetSidebarContent()
-
+
findUserLocation : (map_object) ->
if (navigator.geolocation)
#try to retrieve user's position
@@ -84,9 +84,9 @@ class @Gmaps4Rails
map_object.centerMapOnUser()
positionFailure = ->
map_object.geolocationFailure(true)
-
+
navigator.geolocation.getCurrentPosition( positionSuccessful, positionFailure)
- else
+ else
#failure but the navigator doesn't handle geolocation
map_object.geolocationFailure(false)
@@ -101,16 +101,16 @@ class @Gmaps4Rails
directionsDisplay.setMap(@map)
#display panel only if required
- if @direction_conf.display_panel
+ if @direction_conf.display_panel
directionsDisplay.setPanel(document.getElementById(@direction_conf.panel_id))
-
+
directionsDisplay.setOptions
suppressMarkers: false
suppressInfoWindows: false
suppressPolylines: false
-
- request =
- origin: @direction_conf.origin
+
+ request =
+ origin: @direction_conf.origin
destination: @direction_conf.destination
waypoints: @direction_conf.waypoints
optimizeWaypoints: @direction_conf.optimizeWaypoints
@@ -195,7 +195,7 @@ class @Gmaps4Rails
#creates a single polygon, triggered by create_polygons
create_polygon : (polygon) ->
polygon_coordinates = []
-
+
#Polygon points are in an Array, that's why looping is necessary
for point in polygon
latlng = @createLatLng(point.lat, point.lng)
@@ -225,7 +225,7 @@ class @Gmaps4Rails
#////////////////////////////////////////////////////
#/////////////////// POLYLINES //////////////////////
#////////////////////////////////////////////////////
-
+
#replace old markers with new markers on an existing map
replacePolylines : (new_polylines) ->
#reset previous polylines and kill them from map
@@ -236,7 +236,7 @@ class @Gmaps4Rails
@create_polylines()
#.... and adjust map boundaries
@adjustMapToBounds()
-
+
destroy_polylines : ->
for polyline in @polylines
#delete polylines from map
@@ -252,36 +252,39 @@ class @Gmaps4Rails
#creates a single polyline, triggered by create_polylines
create_polyline : (polyline) ->
polyline_coordinates = []
-
+
#2 cases here, either we have a coded array of LatLng or we have an Array of LatLng
for element in polyline
#if we have a coded array
- if element.coded_array?
+ if element.coded_array?
decoded_array = new google.maps.geometry.encoding.decodePath(element.coded_array)
#loop through every point in the array
for point in decoded_array
polyline_coordinates.push(point)
-
+
#or we have an array of latlng
else
#by convention, a single polyline could be customized in the first array or it uses default values
if element == polyline[0]
strokeColor = element.strokeColor || @polylines_conf.strokeColor
strokeOpacity = element.strokeOpacity || @polylines_conf.strokeOpacity
strokeWeight = element.strokeWeight || @polylines_conf.strokeWeight
-
+ clickable = element.clickable || @polylines_conf.clickable
+ zIndex = element.zIndex || @polylines_conf.zIndex
+
#add latlng if positions provided
- if element.lat? && element.lng?
+ if element.lat? && element.lng?
latlng = @createLatLng(element.lat, element.lng)
polyline_coordinates.push(latlng)
- # Construct the polyline
+ # Construct the polyline
new_poly = new google.maps.Polyline
path: polyline_coordinates
strokeColor: strokeColor
strokeOpacity: strokeOpacity
strokeWeight: strokeWeight
- clickable: false
+ clickable: clickable
+ zIndex: zIndex
#save polyline
polyline.serviceObject = new_poly
@@ -291,7 +294,7 @@ class @Gmaps4Rails
#///////////////////// MARKERS //////////////////////
#////////////////////////////////////////////////////
- #creates, clusterizes and adjusts map
+ #creates, clusterizes and adjusts map
create_markers : ->
@createServiceMarkersFromMarkers()
@clusterize()
@@ -309,7 +312,7 @@ class @Gmaps4Rails
#retrieve coordinates from the æarray
Lat = LatLng[0]
Lng = LatLng[1]
-
+
#save object
@markers[index].serviceObject = @createMarker
"marker_picture": if @markers[index].picture then @markers[index].picture else @markers_conf.picture
@@ -331,10 +334,10 @@ class @Gmaps4Rails
@createInfoWindow(@markers[index])
#create sidebar if enabled
@createSidebar(@markers[index])
-
+
@markers_conf.offset = @markers.length
- #creates Image Anchor Position or return null if nothing passed
+ #creates Image Anchor Position or return null if nothing passed
createImageAnchorPosition : (anchorLocation) ->
if (anchorLocation == null)
return null
@@ -408,31 +411,31 @@ class @Gmaps4Rails
if @map_options.auto_adjust
#from markers
@extendBoundsWithMarkers()
-
+
#from polylines:
- for polyline in @polylines
+ for polyline in @polylines
polyline_points = polyline.serviceObject.latLngs.getArray()[0].getArray()
for point in polyline_points
@boundsObject.extend point
-
+
#from polygons:
for polygon in @polygons
polygon_points = polygon.serviceObject.latLngs.getArray()[0].getArray()
- for point in polygon_points
+ for point in polygon_points
@boundsObject.extend point
-
+
#from circles
for circle in @circles
@boundsObject.extend(circle.serviceObject.getBounds().getNorthEast())
@boundsObject.extend(circle.serviceObject.getBounds().getSouthWest())
- #in every case, I've to take into account the bounds set up by the user
+ #in every case, I've to take into account the bounds set up by the user
for bound in @map_options.bounds
#create points from bounds provided
#TODO:only works with google maps
bound = @createLatLng(bound.lat, bound.lng)
@boundsObject.extend bound
-
+
#SECOND_STEP: ajust the map to the bounds
if @map_options.auto_adjust or @map_options.bounds.length > 0
@@ -442,13 +445,13 @@ class @Gmaps4Rails
@map_options.center_latitude = map_center.lat()
@map_options.center_longitude = map_center.lng()
@map.setCenter(map_center)
- else
+ else
@fitBounds()
-
+
#////////////////////////////////////////////////////
#///////////////// KML //////////////////
#////////////////////////////////////////////////////
-
+
create_kml : ->
for kml in @kml
kml.serviceObject = @createKmlLayer kml
@@ -470,7 +473,7 @@ class @Gmaps4Rails
Lat = parseFloat(Lat0) + (180/Math.PI)*(dy/6378137)
Lng = parseFloat(Lng0) + ( 90/Math.PI)*(dx/6378137)/Math.cos(Lat0)
return [Lat, Lng]
-
+
mergeObjectWithDefault : (object1, object2) ->
copy_object1 = {}
for key, value of object1
@@ -480,12 +483,12 @@ class @Gmaps4Rails
unless copy_object1[key]?
copy_object1[key] = value
return copy_object1
-
+
mergeWithDefault : (objectName) ->
default_object = @["default_" + objectName]
object = @[objectName]
@[objectName] = @mergeObjectWithDefault(object, default_object)
return true
-
+
#gives a value between -1 and 1
- random : -> return(Math.random() * 2 -1)
+ random : -> return(Math.random() * 2 -1)
Oops, something went wrong.

0 comments on commit 2378025

Please sign in to comment.