Skip to content
Snippets Groups Projects
Commit f6bcb90a authored by jaxxed's avatar jaxxed Committed by Andriy Podanenko http://druler.com
Browse files

Issue #1982320 by jaxxed: Gmaps shapes library upgrade to v3 compatible format.

parent 1f7e3cec
No related branches found
No related tags found
No related merge requests found
...@@ -14,42 +14,48 @@ ...@@ -14,42 +14,48 @@
*/ */
/*global $, Drupal, google.maps, !google.maps.geometry! */ /*global $, Drupal, google.maps, !google.maps.geometry! */
(function($) {
Drupal.gmap.addHandler('gmap', function (elem) { Drupal.gmap.addHandler('gmap', function (elem) {
var obj = this; var obj = this;
// prepare and build a google.maps shape object // prepare and build a google.maps shape object
obj.bind('prepareshape', function (shape) { obj.bind('prepareshape', function (shape) {
var pa, cargs, style fillstyle; var style;
fillstyle = false; // does this shape have a fill option? var fillstyle = false; // does this shape have a fill option?
cargs = {}; var cargs = {};
pa = []; // point array (array of LatLng-objects) var pa = []; // point array (array of LatLng-objects)
// positioning determination // positioning determination
switch (shape.type) { switch (shape.type) {
case 'circle': case 'circle':
if ( typeof shape.center === 'array') { shape.center = new google.maps.LatLng(shape.center[0], shape.center[1]); } // otherwise it should be a LatLng already if ( shape.center.length) { shape.center = new google.maps.LatLng(shape.center[0], shape.center[1]); } // otherwise it should be a LatLng already
if ( shape.point2 ) { if ( shape.opts.radius ) {
if ( typeof shape.point2 === 'array') { shape.point2 = new google.maps.LatLng(shape.point2[0], shape.point2[1]); } // otherwise it should be a LatLng already shape.radius = shape.opts.radius;
}
else if ( shape.point2 ) {
if ( shape.point2.length) { shape.point2 = new google.maps.LatLng(shape.point2[0], shape.point2[1]); } // otherwise it should be a LatLng already
shape.radius = (google.maps.geometry) ? google.maps.geometry.spherical.computeDistanceBetween( shape.center, shape.point2 ) : 250; shape.radius = (google.maps.geometry) ? google.maps.geometry.spherical.computeDistanceBetween( shape.center, shape.point2 ) : 250;
} // if you didn't pass a shape.point2, then you should have passed a shape.radius in meters } // if you didn't pass a shape.point2, then you should have passed a shape.radius in meters
break; break;
case 'rpolygon': /* this is deprecated as we have circle now. It is left for backwards compatibility */ case 'rpolygon': /* this is deprecated as we have circle now. It is left for backwards compatibility */
if ( typeof shape.center === 'array') { shape.center = new google.maps.LatLng(shape.center[0], shape.center[1]); } // otherwise it should be a LatLng already if ( shape.center.length ) { shape.center = new google.maps.LatLng(shape.center[0], shape.center[1]); } // otherwise it should be a LatLng already
if ( typeof shape.point2 === 'array') { shape.point2 = new google.maps.LatLng(shape.point2[0], shape.point2[1]); } // otherwise it should be a LatLng already if ( shape.point2.length ) { shape.point2 = new google.maps.LatLng(shape.point2[0], shape.point2[1]); } // otherwise it should be a LatLng already
shape.radius = (google.maps.geometry) ? google.maps.geometry.spherical.computeDistanceBetween( shape.center, shape.point2 ) : 250; shape.radius = (google.maps.geometry) ? google.maps.geometry.spherical.computeDistanceBetween( shape.center, shape.point2 ) : 250;
if ( !shape.numpoints ) { shape.numpoints = 20; } if ( !shape.numpoints ) { shape.numpoints = 20; }
pa = obj.poly.calcPolyPoints(shape.center, radius, shape.numpoints); pa = obj.poly.calcPolyPoints(shape.center, shape.radius, shape.numpoints);
break; break;
case 'polygon': case 'polygon':
fillstyle = true; fillstyle = true;
case 'line': case 'line':
$.each(shape.points, function (i, n) { if ( shape.points ) {
if ( typeof n === 'array') { n = new google.maps.LatLng(n[0], n[1]); } // otherwise it should be a LatLng already $.each( shape.points , function (i, n) {
pa.push( n ); if ( n.length ) { n = new google.maps.LatLng(n[0], n[1]); } // otherwise it should be a LatLng already
}); pa.push( n );
});
}
break; break;
case 'encoded_polygon': case 'encoded_polygon':
...@@ -194,3 +200,5 @@ Drupal.gmap.addHandler('gmap', function (elem) { ...@@ -194,3 +200,5 @@ Drupal.gmap.addHandler('gmap', function (elem) {
} }
}); });
}); });
})(jQuery);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment