相关疑难解决方法(0)

随机颜色发生器

鉴于此功能,我想更换颜色与颜色随机发生器.

document.overlay = GPolyline.fromEncoded({
    color: "#0000FF",
    weight: 10,
    points: encoded_points,
    zoomFactor: 32,
    levels: encoded_levels,
    numLevels: 4
});
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

javascript random colors

397
推荐指数
27
解决办法
54万
查看次数

在JavaScript中查找多边形的中心点

我有一个来自谷歌地图的"地方"对象,它有一组坐标,代表一个给定位置的边界框,比如伦敦.每组坐标都有纬度和经度.

我写了下面的代码来找到中心点,但我不确定它是否确实产生了中心点.如果多边形有5个点而不是4个怎么办?此外,这可以通过更少的操作以更有效的方式完成吗?

function average(array) {
  // Add together and then divide by the length
  return _.reduce(array, function (sum, num) {
    return sum + num;
  }, 0) / array.length;
}

// I have a two-dimensional array that I want to get the average of

var coords = [
  [ -1.2, 5.1 ],
  [ -1.3, 5.2 ],
  [ -1.8, 5.9 ],
  [ -1.9, 5.8 ]
]

// So I get the first column

var lats = coords.map(function (coord) {
  return coord[0];
}) …
Run Code Online (Sandbox Code Playgroud)

javascript math geometry google-maps geolocation

10
推荐指数
4
解决办法
1万
查看次数

标签 统计

javascript ×2

colors ×1

geolocation ×1

geometry ×1

google-maps ×1

math ×1

random ×1