Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Circular Sector Overlay for Google Maps API v3 MooTools 1.2 Class, based on CircleOverlay
- *
- * Arguments:
- * map -- the google.maps.Map object instnace
- * point -- the center point of the circle, google.maps.LatLng object
- * radius -- radius of the circle, in meters, number
- * angle -- sector angle (theta as in fig. here: http://en.wikipedia.org/wiki/Circular_sector), in degrees
- * direction -- a point, which the sector faces, google.maps.LatLng object
- * options -- various options, mainly drawing
- */
- var CircularSectorOverlay = new Class({
- Implements: [Options],
- options: {
- numPoints: 100, // for 360 deg.
- drawOptions: {
- strokeColor: "#FF0000",
- strokeOpacity: 0.8,
- strokeWeight: 2,
- fillColor: "#FF0000",
- fillOpacity: 0.35
- }
- },
- initialize: function(map, center, radius, angle, direction, options) {
- this.setOptions(options);
- google.maps.OverlayView.call(this);
- var q = 180 / 63781370 / Math.sin(90 - center.lat()) / Math.PI;
- this._map = map;
- this._point = center;
- this._angle = angle;
- this._direction = direction;
- this._radius = radius * q * 10; // convert meters to latlang degrees
- // Fit bounds of a sector that is drawn into the map
- this.latlngbounds = new google.maps.LatLngBounds();
- this.sectorLatLngs = new Array();
- this.sectorLatLngs.push(this._point);
- var numPointsSector = Math.ceil(this.options.numPoints * angle / 360);
- var angleIncrement = this._angle / numPointsSector;
- var startAngle = Math.asin(2 * (center.lat() - direction.lat()) / 2) * Math.PI - angle / 2;
- var d2r = Math.PI / 180;
- var circleLat = this._radius;
- var circleLng = circleLat / Math.cos(center.lat() * d2r);
- for (var i = 0; i < numPointsSector; i++) {
- var theta = startAngle + i * angleIncrement;
- var vertexLat = center.lat() + circleLat * Math.sin(theta * d2r);
- var vertexLng = center.lng() + circleLng * Math.cos(theta * d2r);
- var vertextLatLng = new google.maps.LatLng(vertexLat, vertexLng);
- this.sectorLatLngs.push(vertextLatLng);
- this.latlngbounds.extend(vertextLatLng);
- }
- map.fitBounds(this.latlngbounds);
- this.set_map(map);
- },
- onAdd: function() {
- var polyOptions = this.options.drawOptions;
- polyOptions.paths = this.sectorLatLngs;
- this.polygon = new google.maps.Polygon(polyOptions);
- this.polygon.setMap(this.map);
- },
- onRemove: function() {
- this.polygon.setMap(null);
- },
- draw: function() {
- this.onRemove();
- this.onAdd();
- }
- });
- CircularSectorOverlay.implement(new google.maps.OverlayView());
Advertisement
Add Comment
Please, Sign In to add comment