我有一個很長時間以前寫過的腳本,而不是我從V2更新到V3的腳本,我試圖從中心LatLng點繪製範圍環。這工作在V2中,但它不在V3中工作,我不知道爲什麼,因爲我知道一些代碼已折舊,但不知道它需要替換什麼。谷歌地圖V3中的範圍環
//Function to draw circles
function doDrawCircle(circleUnits, center, circleRadius, liColor, liWidth, liOpa, fillColor, fillOpa, opts, radials){
var bounds = new google.maps.LatLngBounds();
var circlePoints = Array();
with (Math) {
if (circleUnits == 'KM') {
var d = circleRadius/6378.8; // radians
}
else { //miles
var d = circleRadius/3963.189; // radians
}
var lat1 = (PI/180)* center.lat(); // radians
var lng1 = (PI/180)* center.lng(); // radians
for (var a = 0 ; a < 361 ; a++) {
var tc = (PI/180)*a;
var y = asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc));
var dlng = atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(y));
var x = ((lng1-dlng+PI) % (2*PI)) - PI ; // MOD function
var point = new google.maps.LatLng(parseFloat(y*(180/PI)),parseFloat(x*(180/PI)));
circlePoints.push(point);
bounds.extend(point);
if(a==0){
var offset = new google.maps.Size(-5,0); // Added the offset - mile markers look a bit better
var label = new ELabel(point, circleRadius, "style1", offset, 40);
map.addOverlay(label);
}
if (((a==0) || (a==45) || (a==90) || (a==135) || (a==180) || (a==225) || (a==270) || (a==315)) && radials) {
//if (((a==0) || (a==45) || (a==90) || (a==135) || (a==180)) && radials) {
var pline = new google.maps.Polyline([center,point] , liColor, liWidth, liOpa);
map.addOverlay(pline);
}
}
var poly = new google.maps.Polygon(circlePoints, liColor, liWidth, liOpa, fillColor, fillOpa, opts);
map.addOverlay(poly); // Add a target circle to the map
map.setZoom(map.getBoundsZoomLevel(bounds)); // This sets the map bounds to be as big as the target circles, comment out if you don't want it
}
}
然後我在initialize()
函數內有這個映射。
// You can add circles, or change other parameters
// radials should be set to true for the maximum distance if you want radials
// doDrawCircle(circleUnits, center, circleRadius, lineColor, lineWidth, lineOpacity, fillColor, fillOpacity, opts, radials)
doDrawCircle('MI',llCenter, 62, lcolor, 1, .7, "#FFFF00", 0, { clickable: false }, false);
doDrawCircle('MI',llCenter, 124, lcolor, 1, .7, "#FFFF00", 0, { clickable: false }, false);
doDrawCircle('MI',llCenter, 187, lcolor, 1, .7, "#FFFF00", 0, { clickable: false }, false);
doDrawCircle('MI',llCenter, 249, lcolor, 1, .7, "#FFFF00", 0, { clickable: false }, false);
doDrawCircle('MI',llCenter, 312, lcolor, 1, .7, "#FFFF00", 0, { clickable: false }, false);
doDrawCircle('MI',llCenter, 374, lcolor, 1, .7, "#FFFF00", 0, { clickable: false }, false);
// doDrawCircle('MI',llCenter, 374, lcolor, 1, .7, '#00FF00', 0, { clickable: false }, true); // This would add the radials
這就是它想象的樣子。這是來自工作的V2地圖。
鏈接到完整的代碼
是的,謝謝你,那很完美!只是一些小的調整。我有一個在本頁頂部的範圍的var設置註釋[NSGMap.js](http://www.mesquiteweather.net/gmap/nsgmap.js),但我很難分配給'ranges = [75,125,175,225,275,325],//以英里爲單位的圓半徑'我所嘗試過的所有東西都會去除圓環並只顯示左上角的英里數。什麼是應用這個的正確方法。此外,我會用什麼var來定義我的按鈕的圓圈。這裏是地圖[V3 MAP](http://www.mesquiteweather.net/wxgmap_lightning.php)謝謝! – Texan78
我剛剛檢查了你的V3地圖,看起來你的圈子和標籤工作正常。你問:「我用什麼var來定義我的按鈕的圓圈」。不確定你的意思,但我猜你想切換他們的知名度?現在沒有時間,可能會在幾個小時後發佈小提琴,但請記住,每個標籤都有一個show()和一個hide()方法,並且每個圓都有一個setVisible(/ *)這裏真或假的方法也是如此。我想如果我要操縱,我可能會創建一個LabelCircle構造函數。稍後.... – astupidname
注意以上第二個版本的增加 – astupidname