You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Uncaught Error: Resolution argument was outside of acceptable range (code: 4, value: -1)
c h3.js:1
s h3.js:1
y h3.js:1
polygonToCells h3.js:1
updateMapDisplay h3viewer.js:115
fire Events.js:195
_moveEnd Map.js:1248
_onZoomTransitionEnd Map.js:1735
setTimeout handler*_animateZoom Map.js:1714
_tryAnimatedZoom Map.js:1679
x Util.js:231
_tryAnimatedZoom Map.js:1676
setView Map.js:195
setZoomAround Map.js:249
_performZoom Map.ScrollWheelZoom.js:83
setTimeout handler*_onWheelScroll Map.ScrollWheelZoom.js:57
o DomEvent.js:108
ke DomEvent.js:123
S DomEvent.js:34
addHooks Map.ScrollWheelZoom.js:33
enable Handler.js:23
addHandler Map.js:733
i Class.js:114
callInitHooks Class.js:81
initialize Map.js:156
e Class.js:24
map Map.js:1750
<anonymous> logic.js:204
[h3.js:1:157510](/h3.umd.js)
this also happens when you zoom out so multiple earths are in frame. . it would be nice if the polygons supported Mercator clipping or something. not sure what the most sain implementation is
Anyway though id point it out if curious this is how im adding this to leaflet map
h3viewer.js
// let map, hexLayer, p;constGeoUtils={EARTH_RADIUS_METERS: 6371000,radiansToDegrees: (r)=>r*180/Math.PI,degreesToRadians: (d)=>d*Math.PI/180,getDistanceOnEarthInMeters: (lat1,lon1,lat2,lon2)=>{constlat1Rad=GeoUtils.degreesToRadians(lat1);constlat2Rad=GeoUtils.degreesToRadians(lat2);constlonDelta=GeoUtils.degreesToRadians(lon2-lon1);constx=Math.sin(lat1Rad)*Math.sin(lat2Rad)+Math.cos(lat1Rad)*Math.cos(lat2Rad)*Math.cos(lonDelta);returnGeoUtils.EARTH_RADIUS_METERS*Math.acos(Math.max(Math.min(x,1),-1));}};constZOOM_TO_H3_RES_CORRESPONDENCE={5: 1,6: 2,7: 3,8: 3,9: 4,10: 5,11: 6,12: 6,13: 7,14: 8,15: 9,16: 9,17: 10,18: 10,19: 11,20: 11,21: 12,22: 13,23: 14,24: 15,};constH3_RES_TO_ZOOM_CORRESPONDENCE={};for(const[zoom,res]ofObject.entries(ZOOM_TO_H3_RES_CORRESPONDENCE)){H3_RES_TO_ZOOM_CORRESPONDENCE[res]=zoom;}constgetH3ResForMapZoom=(mapZoom)=>{returnZOOM_TO_H3_RES_CORRESPONDENCE[mapZoom]??Math.floor((mapZoom-1)*0.7);};consth3BoundsToPolygon=(lngLatH3Bounds)=>{lngLatH3Bounds.push(lngLatH3Bounds[0]);// "close" the polygonreturnlngLatH3Bounds;};/** * Parse the current Query String and return its components as an object. */constparseQueryString=()=>{constqueryString=window.location.search;constquery={};constpairs=(queryString[0]==='?' ? queryString.substr(1) : queryString).split('&');for(leti=0;i<pairs.length;i++){constpair=pairs[i].split('=');query[decodeURIComponent(pair[0])]=decodeURIComponent(pair[1]||'');}returnquery;};constqueryParams=parseQueryString();constcopyToClipboard=(text)=>{constdummy=document.createElement("textarea");document.body.appendChild(dummy);dummy.value=text;dummy.select();document.execCommand("copy");document.body.removeChild(dummy);};functioninitH3LayerOnMap(h3code){letself={computeAverageEdgeLengthInMeters: function(vertexLocations){lettotalLength=0;letedgeCount=0;for(leti=1;i<vertexLocations.length;i++){const[fromLat,fromLng]=vertexLocations[i-1];const[toLat,toLng]=vertexLocations[i];constedgeDistance=GeoUtils.getDistanceOnEarthInMeters(fromLat,fromLng,toLat,toLng);totalLength+=edgeDistance;edgeCount++;}returntotalLength/edgeCount;},updateMapDisplay: function(){if(hexLayer){hexLayer.remove();}hexLayer=L.layerGroup().addTo(map);constzoom=map.getZoom();self.currentH3Res=getH3ResForMapZoom(zoom);const{_southWest: sw,_northEast: ne}=map.getBounds();constboundsPolygon=[[sw.lat,sw.lng],[ne.lat,sw.lng],[ne.lat,ne.lng],[sw.lat,ne.lng],[sw.lat,sw.lng],];consth3s=h3.polygonToCells(boundsPolygon,self.currentH3Res);for(consth3idofh3s){constpolygonLayer=L.layerGroup().addTo(hexLayer);constisSelected=h3id===self.searchH3Id;conststyle=isSelected ? {fillColor: "orange"} : {};consth3Bounds=h3.cellToBoundary(h3id);constaverageEdgeLength=self.computeAverageEdgeLengthInMeters(h3Bounds);constcellArea=h3.cellArea(h3id,"m2");consttooltipText=` Cell ID: <b>${h3id}</b> <br /> Average edge length (m): <b>${averageEdgeLength.toLocaleString()}</b> <br /> Cell area (m^2): <b>${cellArea.toLocaleString()}</b> `;consth3Polygon=L.polygon(h3BoundsToPolygon(h3Bounds),style).on('click',()=>copyToClipboard(h3id)).bindTooltip(tooltipText).addTo(polygonLayer);// less SVG, otherwise perf is badif(Math.random()>0.8||isSelected){varsvgElement=document.createElementNS("http://www.w3.org/2000/svg","svg");svgElement.setAttribute('xmlns',"http://www.w3.org/2000/svg");svgElement.setAttribute('viewBox',"0 0 200 200");svgElement.innerHTML=`<text x="20" y="70" class="h3Text">${h3id}</text>`;varsvgElementBounds=h3Polygon.getBounds();L.svgOverlay(svgElement,svgElementBounds).addTo(polygonLayer);}}},gotoLocation: function(){const[lat,lon]=(self.gotoLatLon||"").split(",").map(Number);if(Number.isFinite(lat)&&Number.isFinite(lon)&&lat<=90&&lat>=-90&&lon<=180&&lon>=-180){map.setView([lat,lon],16);}},findH3: function(){if(!h3.isValidCell(self.searchH3Id)){return;}consth3Boundary=h3.cellToBoundary(self.searchH3Id);letbounds=undefined;for([lat,lng]ofh3Boundary){if(bounds===undefined){bounds=newL.LatLngBounds([lat,lng],[lat,lng]);}else{bounds.extend([lat,lng]);}}map.fitBounds(bounds);constnewZoom=H3_RES_TO_ZOOM_CORRESPONDENCE[h3.getResolution(self.searchH3Id)];map.setZoom(newZoom);}}functionmounted(){map.on("zoomend",self.updateMapDisplay);map.on("moveend",self.updateMapDisplay);consth3=h3code||p.h3viewer;console.log(h3)// if (h3) {// self.searchH3Id = h3;// window.setTimeout(() => self.findH3(), 50);// }self.updateMapDisplay();returnself;}returnmounted()}varhexLayerfunctiongetParamH3Viewer(){letz=map.getZoom()letc=map.getCenter()leta=[z,c.lat,c.lng]return"mapinfo="+encodeURIComponent(JSON.stringify(a))}if(p&&p.h3viewer){try{leta=p.h3viewer// hmm coulf be hexcodeconsole.log("yo dog")window.h3viewer=initH3LayerOnMap(false)}catch(e){console.error("Invaled mapinfo doing nothing [zoom, lat, lon]")}}
The text was updated successfully, but these errors were encountered:
The problem in the image is a rendering issue, not an H3-js issue. H3 always provides coordinates with normalized longitudes (in the range -180 to 180) but this doesn't always render well on web maps.
The error you pasted to is a different issue - at some point you're sending resolution -1 to the polygonToCells function, and this throws an error for bad input.
Anyway though id point it out if curious this is how im adding this to leaflet map
h3viewer.js
The text was updated successfully, but these errors were encountered: