admin管理员组文章数量:1327685
I have crested a heat-map using google maps js api. all the locations are weighted and would like the color to represent the weights instead i am getting a red dot that fades to yellow and then green. not this is only a test and i will be populating the zip codes and weights from a database
<script src=".exp&libraries=visualization"></script>
.
function initialize() {
geocoder = new google.maps.Geocoder();
var mapProp = {
center:new google.maps.LatLng(40.785091,-73.968285),
zoom:11,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
codeAddress("10001", 6119);
codeAddress("10002", 5180);
codeAddress("10003", 4110);
codeAddress("10004", 899);
codeAddress("10005", 520);
codeAddress("10006", 599);
function codeAddress(zip, noAccidents) {
//var address = document.getElementById("address").value;
geocoder.geocode( { 'address': zip}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var hotSpot = results[0].geometry.location;
console.log(hotSpot + " " + noAccidents);
var heatMapZip = [
{location: hotSpot, weight: noAccidents}
];
var color =[
"#ff0000",
"#00ff00"
];
var heatmap = new google.maps.visualization.HeatmapLayer({
data: heatMapZip,
radius: 50,
dissapating: false
});
heatmap.setMap(map);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
I have crested a heat-map using google maps js api. all the locations are weighted and would like the color to represent the weights instead i am getting a red dot that fades to yellow and then green. not this is only a test and i will be populating the zip codes and weights from a database
<script src="https://maps.googleapis./maps/api/js?v=3.exp&libraries=visualization"></script>
.
function initialize() {
geocoder = new google.maps.Geocoder();
var mapProp = {
center:new google.maps.LatLng(40.785091,-73.968285),
zoom:11,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
codeAddress("10001", 6119);
codeAddress("10002", 5180);
codeAddress("10003", 4110);
codeAddress("10004", 899);
codeAddress("10005", 520);
codeAddress("10006", 599);
function codeAddress(zip, noAccidents) {
//var address = document.getElementById("address").value;
geocoder.geocode( { 'address': zip}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var hotSpot = results[0].geometry.location;
console.log(hotSpot + " " + noAccidents);
var heatMapZip = [
{location: hotSpot, weight: noAccidents}
];
var color =[
"#ff0000",
"#00ff00"
];
var heatmap = new google.maps.visualization.HeatmapLayer({
data: heatMapZip,
radius: 50,
dissapating: false
});
heatmap.setMap(map);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
Share
Improve this question
edited Jul 13, 2016 at 16:14
Lonergan6275
asked Jul 10, 2015 at 13:55
Lonergan6275Lonergan6275
2,0386 gold badges34 silver badges63 bronze badges
1
-
You're a little vague on how 'weight' corresponds to colours. What does your array
color
do? Nothing it seems... why not pass that as thegradient
parameter for your HeatmapLayerOptions? Also NB: the parameter is documented asdissipating
notdissapating
– duncan Commented Jul 10, 2015 at 14:03
1 Answer
Reset to default 4You should use the function heatmap.set('gradient', gradient);
to set the color of your heat map. The color can be calculated by the # of accident, and the max and min of the # in your data set.
I created a fiddle for that, hope it helps.
http://jsfiddle/hzy0y6es/
本文标签: javascriptGoogle heat map change colour based on intensityStack Overflow
版权声明:本文标题:javascript - Google heat map change colour based on intensity - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742217351a2434814.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论