如何在渐变色的地图上绘制区域?
How to draw an area on a map colored by a gradient?
我想绘制一个形状(为简单起见,假设为一个矩形)覆盖一个区域,该区域的颜色会从例如阴影改变阴影。绿色到红色。绘制无数小矩形的唯一方法是颜色按索引移动,还是有一种方法可以表示渐变的从到(或者更好,从到到)颜色数组?
我认为您可以使用 html canvas 创建渐变并用它填充您的形状 (http://www.w3schools.com/tags/canvas_createlineargradient.asp)。
或者您可以使用 svg 渐变 (https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients)。
您也可以尝试使用带有某些插件的 html 地图区域。
你的地图多边形绘制得像 this. Parameters for them are described here. It seems that they support only colors without gradients, but as an option you can try overlay like this 。
如果您正在使用 Google 地图,您可以尝试 Heatmaps 渐变
如果您真的很喜欢热图,正如您在@jaganathan-bantheswaran 回答中的评论中所建议的那样,那么您将能够在 HERE 地图中使用 H.data.heatmap.Provider class
API 参考描述了如何做到这一点:
// Create heat map provider
var heatmapProvider = new H.data.heatmap.Provider({
colors: new H.data.heatmap.Colors({
'0': 'blue',
'0.5': 'yellow',
'1': 'red'
}, true),
// paint assumed values in regions where no data is available
assumeValues: true
});
// Add the data
heatmapProvider.addData([
{lat: 52, lng: 1, value: 1},
{lat: 53, lng: 2, value: 2}
]);
// Create semi transparent heat map layer
var heatmapLayer = new H.map.layer.TileLayer(heatmapProvider, {
opacity: 0.6
});
// Add layer to the map
map.addLayer(heatmapLayer);
我想绘制一个形状(为简单起见,假设为一个矩形)覆盖一个区域,该区域的颜色会从例如阴影改变阴影。绿色到红色。绘制无数小矩形的唯一方法是颜色按索引移动,还是有一种方法可以表示渐变的从到(或者更好,从到到)颜色数组?
我认为您可以使用 html canvas 创建渐变并用它填充您的形状 (http://www.w3schools.com/tags/canvas_createlineargradient.asp)。
或者您可以使用 svg 渐变 (https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients)。
您也可以尝试使用带有某些插件的 html 地图区域。
你的地图多边形绘制得像 this. Parameters for them are described here. It seems that they support only colors without gradients, but as an option you can try overlay like this 。
如果您正在使用 Google 地图,您可以尝试 Heatmaps 渐变
如果您真的很喜欢热图,正如您在@jaganathan-bantheswaran 回答中的评论中所建议的那样,那么您将能够在 HERE 地图中使用 H.data.heatmap.Provider class
API 参考描述了如何做到这一点:
// Create heat map provider
var heatmapProvider = new H.data.heatmap.Provider({
colors: new H.data.heatmap.Colors({
'0': 'blue',
'0.5': 'yellow',
'1': 'red'
}, true),
// paint assumed values in regions where no data is available
assumeValues: true
});
// Add the data
heatmapProvider.addData([
{lat: 52, lng: 1, value: 1},
{lat: 53, lng: 2, value: 2}
]);
// Create semi transparent heat map layer
var heatmapLayer = new H.map.layer.TileLayer(heatmapProvider, {
opacity: 0.6
});
// Add layer to the map
map.addLayer(heatmapLayer);