Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: apneadiving/Google-Maps-for-Rails
base: 203036b564
...
head fork: apneadiving/Google-Maps-for-Rails
compare: ea0915fce5
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
Commits on May 23, 2012
Alexis Tejeda Added polylines support for openlayers (used as a provider). The json…
… structure to use is the same used for gmaps as data provider.

Polyline (as far as I know) was only implemented for gmaps, now this was moved to his own .js.coffee file, same for openlayers.
d525946
Commits on Jun 05, 2012
@apneadiving Merge pull request #216 from atejeda/master
Polyline when :provider => "openlayers"
ea0915f
View
103 app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee 100755 → 100644
@@ -70,6 +70,14 @@ class @Gmaps4Rails
@markerClusterer = null # contains all marker clusterers
@markerImages = []
+ #Polyline Styling
+ @polylines_conf = #default style for polylines
+ strokeColor: "#FF0000"
+ strokeOpacity: 1
+ strokeWeight: 2
+ clickable: false
+ zIndex: null
+
#tnitializes the map
initialize : ->
@serviceObject = @createMap()
@@ -228,73 +236,7 @@ class @Gmaps4Rails
#save polygon in list
polygon.serviceObject = new_poly
- #////////////////////////////////////////////////////
- #/////////////////// POLYLINES //////////////////////
- #////////////////////////////////////////////////////
-
- #replace old markers with new markers on an existing map
- replacePolylines : (new_polylines) ->
- #reset previous polylines and kill them from map
- @destroy_polylines()
- #set new polylines
- @polylines = new_polylines
- #create
- @create_polylines()
- #.... and adjust map boundaries
- @adjustMapToBounds()
-
- destroy_polylines : ->
- for polyline in @polylines
- #delete polylines from map
- polyline.serviceObject.setMap(null)
- #empty array
- @polylines = []
-
- #polylines is an array of arrays. It loops.
- create_polylines : ->
- for polyline in @polylines
- @create_polyline polyline
-
- #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?
- 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?
- latlng = @createLatLng(element.lat, element.lng)
- polyline_coordinates.push(latlng)
-
- # Construct the polyline
- new_poly = new google.maps.Polyline
- path: polyline_coordinates
- strokeColor: strokeColor
- strokeOpacity: strokeOpacity
- strokeWeight: strokeWeight
- clickable: clickable
- zIndex: zIndex
-
- #save polyline
- polyline.serviceObject = new_poly
- new_poly.setMap(@serviceObject)
+
#////////////////////////////////////////////////////
#///////////////////// MARKERS //////////////////////
@@ -464,6 +406,33 @@ class @Gmaps4Rails
kml.serviceObject = @createKmlLayer kml
#////////////////////////////////////////////////////
+ #/////////////////// POLYLINES //////////////////////
+ #////////////////////////////////////////////////////
+
+ #replace old markers with new markers on an existing map
+ replacePolylines : (new_polylines) ->
+ #reset previous polylines and kill them from map
+ @destroy_polylines()
+ #set new polylines
+ @polylines = new_polylines
+ #create
+ @create_polylines()
+ #.... and adjust map boundaries
+ @adjustMapToBounds()
+
+ destroy_polylines : ->
+ for polyline in @polylines
+ #delete polylines from map
+ polyline.serviceObject.setMap(null)
+ #empty array
+ @polylines = []
+
+ #polylines is an array of arrays. It loops.
+ create_polylines : ->
+ for polyline in @polylines
+ @create_polyline polyline
+
+ #////////////////////////////////////////////////////
#///////////////// Basic functions //////////////////
#///////////////////tests coded//////////////////////
View
53 app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee 100755 → 100644
@@ -36,14 +36,6 @@ class @Gmaps4RailsGoogle extends Gmaps4Rails
fillOpacity: 0.35
clickable: false
- #Polyline Styling
- @polylines_conf = #default style for polylines
- strokeColor: "#FF0000"
- strokeOpacity: 1
- strokeWeight: 2
- clickable: false
- zIndex: null
-
#Circle Styling
@circles_conf = #default style for circles
fillColor: "#00AAFF"
@@ -250,6 +242,51 @@ class @Gmaps4RailsGoogle extends Gmaps4Rails
kml.setMap(@serviceObject)
return kml
+ #////////////////////////////////////////////////////
+ #/////////////////// POLYLINES //////////////////////
+ #////////////////////////////////////////////////////
+
+ #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?
+ 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?
+ latlng = @createLatLng(element.lat, element.lng)
+ polyline_coordinates.push(latlng)
+
+ # Construct the polyline
+ new_poly = new google.maps.Polyline
+ path: polyline_coordinates
+ strokeColor: strokeColor
+ strokeOpacity: strokeOpacity
+ strokeWeight: strokeWeight
+ clickable: clickable
+ zIndex: zIndex
+
+ #save polyline
+ polyline.serviceObject = new_poly
+ new_poly.setMap(@serviceObject)
+
#////////////////////////////////////////////////////
#/////////////////// Other methods //////////////////
View
41 app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee
@@ -18,6 +18,7 @@ class @Gmaps4RailsOpenlayers extends Gmaps4Rails
@openMarkers = null
@markersLayer = null
@markersControl = null
+ @polylinesLayer = null
#////////////////////////////////////////////////////
#/////////////// Basic Objects ////////////////////
@@ -197,6 +198,46 @@ class @Gmaps4RailsOpenlayers extends Gmaps4Rails
feature.popup.destroy()
feature.popup = null
+ #////////////////////////////////////////////////////
+ #/////////////////// POLYLINES //////////////////////
+ #////////////////////////////////////////////////////
+
+ create_polyline : (polyline) ->
+
+ if(@polylinesLayer == null)
+ @polylinesLayer = new OpenLayers.Layer.Vector("Polylines", null)
+ @serviceObject.addLayer(@polylinesLayer)
+ @polylinesLayer.events.register("featureselected", @polylinesLayer, @onFeatureSelect)
+ @polylinesLayer.events.register("featureunselected", @polylinesLayer, @onFeatureUnselect)
+ @polylinesControl = new OpenLayers.Control.DrawFeature(@polylinesLayer, OpenLayers.Handler.Path)
+ @serviceObject.addControl(@polylinesControl)
+
+ polyline_coordinates = []
+
+ for element in polyline
+ #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?
+ latlng = new OpenLayers.Geometry.Point(element.lng, element.lat)
+ polyline_coordinates.push(latlng)
+
+ line_points = new OpenLayers.Geometry.LineString(polyline_coordinates);
+ line_style = { strokeColor: strokeColor, strokeOpacity: strokeOpacity, strokeWidth: strokeWeight };
+
+ polyline = new OpenLayers.Feature.Vector(line_points, null, line_style);
+ polyline.geometry.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"))
+
+ @polylinesLayer.addFeatures([polyline])
+
+ return polyline
+
# #////////////////////////////////////////////////////
# #/////////////////// Other methods //////////////////
# #////////////////////////////////////////////////////

No commit comments for this range

Something went wrong with that request. Please try again.