2014-07-25 18 views
6

पर सर्कल की चाप खींचें विचार यह है कि कोणों का उपयोग करके एक विशिष्ट बिंदु पर केंद्रित एक चाप खींचना है। नोट: तार, न ही क्षेत्र, न ही तार और चाप के बीच का क्षेत्र।Google मानचित्र

मेमेंटो: http://en.wikipedia.org/wiki/Arc_(geometry)

एक चक्र पूरा पैरामीटर:

- center at coordinates LatC,LngC 
- radius of 1 609 meters 
- start angle of 0 degrees 
- end angle of 360 degrees 

उदाहरण http://jsfiddle.net/GGvQH/3/

new google.maps.Circle({ 
    center: new google.maps.LatLng(18.4894, 73.910158), 
    radius: 1609, 
    ... 
}); 

का एक आर्क 180 डिग्री (पीआई/2 उज्ज्वल) उत्तर के लिए उन्मुख की तरह होगा:

- center at coordinates LatC,LngC 
- radius of 1 609 meters 
- start angle of 270 degrees (9 o'clock) 
- end angle of 90 degrees (3 o'clock) 

सबसे पहले, मैं एक चिकनी प्रभाव प्राप्त करने के लिए अंक के टन का उपयोग करके प्रत्येक चाप के लिए एक पॉलीलाइन प्लॉट नहीं करना चाहता हूं: प्रत्येक पैमाने के लिए पुन: सम्मिलित करने की आवश्यकता है और संसाधनों का खर्च हो सकता है ... या है ना?

बहुभुज चौराहे Google Maps API v3 - circle sector ... क्या किसी ने काम कर रहे jsfiddle देखा है? नोट: http://jsfiddle.net/Morlock0821/4dRB2/1/ चाप के बहुत करीब है, लेकिन मुझे बंद सतह नहीं चाहिए।

असर के साथ एक और विचार ... लेकिन मैं पृथ्वी की त्रिज्या को फिर से परिभाषित करने के लिए अनिच्छुक हूं, जिससे मैं चाहता हूं कि वह छोटा चाप प्राप्त कर सके। https://developers.google.com/maps/documentation/javascript/examples/geometry-headings (इस मामले में, मुझे केवल बैंगनी रेखा चाहिए, लाल नहीं)।

किसी भी मदद की सराहना की जाएगी।

+2

http://www.geocodezip.com/v3_polygon_example_arc.html – geocodezip

+0

अच्छा डिस्क क्षेत्र, मुझे लगता है की कोशिश करेंगे स्रोत। यदि क्षेत्र और त्रिज्या को हटा देना संभव है (केवल चाप प्राप्त करने के लिए), मैं इसे यहां लिंक करूँगा :) – nicolallias

+1

अपने ब्राउज़र में स्रोत देखें ... – geocodezip

उत्तर

8

इस कोड मैं this example में उपयोग करते हैं:

function drawArc(center, initialBearing, finalBearing, radius) { 
    var d2r = Math.PI/180; // degrees to radians 
    var r2d = 180/Math.PI; // radians to degrees 

    var points = 32; 

    // find the raidus in lat/lon 
    var rlat = (radius/EarthRadiusMeters) * r2d; 
    var rlng = rlat/Math.cos(center.lat() * d2r); 

    var extp = new Array(); 

    if (initialBearing > finalBearing) finalBearing += 360; 
    var deltaBearing = finalBearing - initialBearing; 
    deltaBearing = deltaBearing/points; 
    for (var i=0; (i < points+1); i++) 
    { 
    extp.push(center.DestinationPoint(initialBearing + i*deltaBearing, radius)); 
    bounds.extend(extp[extp.length-1]); 
    } 
    return extp; 
} 

इस, जहां StartPoint यह चाप की शुरुआत, endpoint चाप का अंत है और केंद्र-केंद्र है की तरह किया जाता है, लेकिन आप निर्दिष्ट कर सकते हैं केंद्र, कोण और त्रिज्या।

var arcPts = drawArc(centerPoint, centerPoint.Bearing(startPoint), centerPoint.Bearing(endPoint), centerPoint.distanceFrom(startPoint)); 


var piePoly = new google.maps.Polygon({ 
      paths: [arcPts], 
      strokeColor: "#00FF00", 
      strokeOpacity: 0.5, 
      strokeWeight: 2, 
      fillColor: "#FF0000", 
      fillOpacity: 0.35, 
      map: map 
}); 

सहायक काम करता है, अब आवश्यक हो सकता है अगर आप में शामिल geometry library

var EarthRadiusMeters = 6378137.0; // meters 
/* Based the on the Latitude/longitude spherical geodesy formulae & scripts 
    at http://www.movable-type.co.uk/scripts/latlong.html 
    (c) Chris Veness 2002-2010 
*/ 
google.maps.LatLng.prototype.DestinationPoint = function (brng, dist) { 
var R = EarthRadiusMeters; // earth's mean radius in meters 
var brng = brng.toRad(); 
var lat1 = this.lat().toRad(), lon1 = this.lng().toRad(); 
var lat2 = Math.asin(Math.sin(lat1)*Math.cos(dist/R) + 
         Math.cos(lat1)*Math.sin(dist/R)*Math.cos(brng)); 
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(dist/R)*Math.cos(lat1), 
          Math.cos(dist/R)-Math.sin(lat1)*Math.sin(lat2)); 

return new google.maps.LatLng(lat2.toDeg(), lon2.toDeg()); 
} 

// === A function which returns the bearing between two LatLng in radians === 
// === If v1 is null, it returns the bearing between the first and last vertex === 
// === If v1 is present but v2 is null, returns the bearing from v1 to the next vertex === 
// === If either vertex is out of range, returns void === 
google.maps.LatLng.prototype.Bearing = function(otherLatLng) { 
    var from = this; 
    var to = otherLatLng; 
    if (from.equals(to)) { 
    return 0; 
    } 
    var lat1 = from.latRadians(); 
    var lon1 = from.lngRadians(); 
    var lat2 = to.latRadians(); 
    var lon2 = to.lngRadians(); 
    var angle = - Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2)); 
    if (angle < 0.0) angle += Math.PI * 2.0; 
    if (angle > Math.PI) angle -= Math.PI * 2.0; 
    return parseFloat(angle.toDeg()); 
} 


/** 
* Extend the Number object to convert degrees to radians 
* 
* @return {Number} Bearing in radians 
* @ignore 
*/ 
Number.prototype.toRad = function() { 
    return this * Math.PI/180; 
}; 

/** 
* Extend the Number object to convert radians to degrees 
* 
* @return {Number} Bearing in degrees 
* @ignore 
*/ 
Number.prototype.toDeg = function() { 
    return this * 180/Math.PI; 
}; 

/** 
* Normalize a heading in degrees to between 0 and +360 
* 
* @return {Number} Return 
* @ignore 
*/ 
Number.prototype.toBrng = function() { 
    return (this.toDeg() + 360) % 360; 
}; 
+0

चाप प्राप्त करने के लिए एक अच्छा प्रारंभिक बिंदु की तरह लगता है, धन्यवाद! – nicolallias