为什么我的圈子不出现在这张叶子图上?

时间:2016-08-04 20:37:43

标签: javascript gps leaflet

我的问题here得到了圆满的回答,但现在我的代码找到了正确的坐标以放置圆圈,圆圈没有出现。谁能告诉我这里发生了什么? This example显示圈子出现,我尽可能地复制了它。

var linkDistance = 10; //$('#linkDistance').val();
var nodesCount = 8;
var bandwidth = "10 GB/s";
var rootLongitude = 35.088878;
var rootLatitude = -106.65262;
var EARTH_RADIUS = 6378137;

var mymap = L.map('mapid').setView([rootLongitude, rootLatitude], 11);

L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpandmbXliNDBjZWd2M2x6bDk3c2ZtOTkifQ._QA7i5Mpkd_m30IGElHziw', {
  maxZoom: 18,
  attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
    '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
    'Imagery © <a href="http://mapbox.com">Mapbox</a>',
  id: 'mapbox.streets'
}).addTo(mymap);


function drawNext(rootLongitude, rootLatitude) {
  var coords = [];

  for (var i = 0; i <= nodesCount; i++) {
    var radius = linkDistance*1000;
    var angle = Math.PI*2*i/nodesCount;
    var dx = radius*Math.cos(angle);
    var dy = radius*Math.sin(angle);

    coords.push([(rootLatitude + (180/Math.PI)*(dy/EARTH_RADIUS)), (rootLongitude + (180/Math.PI)*(dx/EARTH_RADIUS)/Math.cos(rootLatitude*Math.PI/180))]);
  }

  for (var i = 0; i < coords.length; i++) {
    new L.Circle(coords[i], 500, {
      color: 'black',
      fillColor: '#f03',
      fillOpacity: 0.1
    }).addTo(mymap);
      console.log("added circle to: " + coords[i]);
  }

}

drawNext(rootLongitude, rootLatitude);


var popup = L.popup();

function onMapClick(e) {
    popup
        .setLatLng(e.latlng)
        .setContent("You clicked the map at " + e.latlng.toString())
        .openOn(mymap);
}

mymap.on('click', onMapClick);

0 个答案:

没有答案