Created
November 14, 2017 18:38
-
-
Save sevamoo/2442e9463c80d1b3ef276bf42ca4f509 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var markerClusters = new L.MarkerClusterGroup({ | |
spiderfyOnMaxZoom: true, | |
showCoverageOnHover: true, | |
zoomToBoundsOnClick: true, | |
disableClusteringAtZoom: 17, | |
maxClusterRadius: 120, | |
iconCreateFunction: function (cluster) { | |
selected_building_feature = 'Numbers'; | |
if (selected_building_feature=='Rent'){ | |
// selected_building_feature = 'Rent'; | |
var mnval=1000; | |
var mxval=7000; | |
var mnval = 15.7; //rental/psqm | |
var mxval = 41; //rental.psq | |
}; | |
if (selected_building_feature=='Living space'){ | |
// selected_building_feature = 'Living space'; | |
var mnval=50; | |
var mxval=250; | |
}; | |
if (selected_building_feature=='Rooms'){ | |
var mnval=1; | |
var mxval=7; | |
}; | |
if (selected_building_feature=='Numbers'){ | |
var mnval=10; | |
var mxval=100; | |
}; | |
var colorR = (mxval-mnval)/9; | |
var color = d3.scale.linear().domain(d3.range(mnval, mxval,colorR)) | |
.range(colorspec) | |
.interpolate(d3.interpolateLab); | |
var markers = cluster.getAllChildMarkers(); | |
var n = 0; | |
var l = 0; | |
for (var i = 0; i < markers.length; i++) { | |
if (selected_building_feature=='Rent'){ | |
var rent = parseInt(markers[i].feature.properties[selected_building_feature]) || 0; | |
var size = parseInt(markers[i].feature.properties['Living space']) || 0; | |
// var rooms = parseInt(markers[i].feature.properties.Rooms) || 0; | |
if (rent*size>0){ | |
l+=1; | |
n += rent/size; | |
}; | |
}; | |
if (selected_building_feature=='Living space'){ | |
var building_f = parseInt(markers[i].feature.properties[selected_building_feature]) || 0; | |
// var rooms = parseInt(markers[i].feature.properties.Rooms) || 0; | |
if (building_f>0){ | |
l+=1; | |
n += building_f; | |
}; | |
}; | |
if (selected_building_feature=='Rooms'){ | |
var building_f = parseInt(markers[i].feature.properties[selected_building_feature]) || 0; | |
// var rooms = parseInt(markers[i].feature.properties.Rooms) || 0; | |
if (building_f>0){ | |
l+=1; | |
n += building_f; | |
}; | |
}; | |
if (selected_building_feature=='Numbers'){ | |
var building_f = 1; | |
// var rooms = parseInt(markers[i].feature.properties.Rooms) || 0; | |
if (building_f>0){ | |
l+=1; | |
n += l; | |
}; | |
}; | |
} | |
if (l>=1){ | |
building_f = Math.round(n/l); | |
f = Math.min(mxval, building_f); | |
f = Math.max(mnval, f); | |
pcl = color(f); | |
if (selected_building_feature=='Numbers'){ | |
building_f = l; | |
f = Math.min(mxval, building_f); | |
f = Math.max(mnval, f); | |
pcl = color(f); | |
} | |
}else{ | |
building_f = 'Null'; | |
// pcl = 'white'; | |
} | |
// console.log(building_f); | |
// console.log(pcl); | |
return L.divIcon({html:'<div style="width:40px;height:40px;border-radius:40px;text-align:center;font-size:12px;text-align: center;padding-top: 10px;color:DimGray;background:' + | |
pcl + '">' + building_f + '</div>',iconSize: L.point(0, 0)}); | |
// return L.divIcon({html:'<div style="width:40px;height:40px;border-radius:40px;text-align:center;font-size:12px;text-align: center;padding-top: 10px;color:DimGray;background:' + | |
// pcl + '">' + l + '</div>',iconSize: L.point(0, 0)}); | |
}, | |
}); | |
map.addLayer(markerClusters); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment