diff --git a/source/mxn.core.js b/source/mxn.core.js index 2660819..ed36023 100644 --- a/source/mxn.core.js +++ b/source/mxn.core.js @@ -1842,7 +1842,7 @@ var Radius = mxn.Radius = function(center, quality) { var rad = Math.PI / 180; this.calcs = []; - for(var i = 0; i < 360; i += quality){ + for(var i = 0; i < 360; i += 360/quality){ this.calcs.push([Math.cos(i * rad) / latConv, Math.sin(i * rad) / lonConv]); } }; @@ -1868,7 +1868,8 @@ Radius.prototype.getPolyline = function(radius, color) { points.push(points[0]); var line = new Polyline(points); - line.setColor(color); + line.setClosed(true); + if (color) line.setColor(color); return line; }; diff --git a/source/mxn.google.core.js b/source/mxn.google.core.js index 598b70c..528ee85 100644 --- a/source/mxn.google.core.js +++ b/source/mxn.google.core.js @@ -14,7 +14,7 @@ Mapstraction: { marker.mapstraction_marker.click.fire(); } else if ( location ) { - me.click.fire({'location': new mxn.LatLonPoint(location.y, location.x)}); + me.click.fire({ 'location': new mxn.LatLonPoint(location.lat(), location.lng()) }); } // If the user puts their own Google markers directly on the map @@ -498,6 +498,18 @@ Marker: { Polyline: { + fromProprietary: function(gpolyline) { + var points = []; + + for (var i = 0; i < gpolyline.getVertexCount(); i++) { + point = new mxn.LatLonPoint(); + point.fromProprietary('google', gpolyline.getVertex(i)); + points.push(point); + } + + this.points = points; + }, + toProprietary: function() { var gpoints = []; for (var i = 0, length = this.points.length ; i< length; i++){ diff --git a/source/mxn.googlev3.core.js b/source/mxn.googlev3.core.js index 44ea72c..001326c 100644 --- a/source/mxn.googlev3.core.js +++ b/source/mxn.googlev3.core.js @@ -413,9 +413,33 @@ Mapstraction: { }, getPixelRatio: function() { - var map = this.maps[this.api]; - // TODO: Add provider code + function distanceBetween(point1, point2) { + var R = 6371; // km (change this constant to get miles) + //var R = 6378100; // meters + var lat1 = point1.lat(); + var lon1 = point1.lng(); + var lat2 = point2.lat(); + var lon2 = point2.lng(); + var dLat = (lat2-lat1) * Math.PI / 180; + var dLon = (lon2-lon1) * Math.PI / 180; + var a = Math.sin(dLat/2) * Math.sin(dLat/2) + + Math.cos(lat1 * Math.PI / 180 ) * Math.cos(lat2 * Math.PI / 180 ) * + Math.sin(dLon/2) * Math.sin(dLon/2); + var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); + var d = R * c; + return d; + } + + var map = this.maps[this.api]; + var projection = map.getProjection(); + var centerPoint = map.getCenter(); + var zoom = map.getZoom(); + var centerPixel = projection.fromLatLngToPoint(centerPoint); + // distance is the distance in metres for 5 pixels (3-4-5 triangle) + var distancePoint = projection.fromPointToLatLng(new google.maps.Point(centerPixel.x + 3, centerPixel.y + 4)); + //*1000(km to m), /5 (pythag), *2 (radius to diameter) + return 10000/distanceBetween(centerPoint, distancePoint); }, mousePosition: function(element) { @@ -592,6 +616,22 @@ Marker: { Polyline: { + fromProprietary: function(gPolyline) { + var points = []; + var path = gPolyline.getPath(); + + for (var i = 0; i < path.getLength(); i++) { + point = new mxn.LatLonPoint(); + point.fromProprietary('googlev3', path.getAt(i)); + points.push(point); + } + + this.points = points; + this.color = gPolyline.strokeColor; + this.opacity = gPolyline.strokeOpacity; + this.width = gPolyline.strokeWeight; + }, + toProprietary: function() { var points = []; for (var i = 0, length = this.points.length; i < length; i++) { @@ -606,8 +646,9 @@ Polyline: { }; if (this.closed) { - polyOptions.fillColor = this.fillColor || '#000000'; - polyOptions.fillOpacity = polyOptions.strokeOpacity; + polyOptions.fillColor = this.fillColor || "#5462E3"; + polyOptions.fillOpacity = this.opacity || "0.3"; + polyOptions.strokeWeight = this.width || 0; return new google.maps.Polygon(polyOptions); }