functioncreateCustomIcon(feature,latlng){letmyIcon=L.icon({iconUrl:'my-icon.png',shadowUrl:'my-icon.png',iconSize:[25,25],// width and height of the image in pixelsshadowSize:[35,20],// width, height of optional shadow imageiconAnchor:[12,12],// point of the icon which will correspond to marker's locationshadowAnchor:[12,6],// anchor point of the shadow. should be offsetpopupAnchor:[0,0]// point from which the popup should open relative to the iconAnchor})returnL.marker(latlng,{icon:myIcon})}
The following code will turn your geojson from lab1 into a choropleth map:
// this is a function to get the color, notice how the numbers are hard coded, who decides that?functiongetColor(d){returnd>1000000?'#800026':d>500000?'#BD0026':d>200000?'#FEB24C':d>10000?'#FED976':'#FFEDA0';}// this is the generation function for the style, notice it uses the getColor functionfunctionstyle(feature){return{fillColor:getColor(feature.properties.TOTAL_POP),weight:2,opacity:1,color:'white',dashArray:'3',fillOpacity:0.7};}fetch("js/lab1.geojson").then(response=>{returnresponse.json()}).then(ca_counties=>{// Basic Leaflet method to add GeoJSON dataL.geoJSON(ca_counties,{style:style}).bindPopup(function(layer){returnlayer.feature.properties.name;}).addTo(map);})