Created
November 16, 2020 23:59
-
-
Save stefanocudini/6c9f337fde4d7f19031dd8b1632bd2a1 to your computer and use it in GitHub Desktop.
show integer and primes coordinates in the world
This file contains hidden or 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title></title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<link href="https://unpkg.com/[email protected]/dist/leaflet.css" rel="stylesheet" type="text/css" /> | |
<style> | |
#map { | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"> | |
</div> | |
<script src="https://unpkg.com/[email protected]/underscore.js"></script> | |
<script src="https://unpkg.com/[email protected]/dist/leaflet-src.js"></script> | |
<script src="https://unpkg.com/[email protected]/leaflet-providers.js"></script> | |
<script src="https://unpkg.com/[email protected]/dist/jquery.js"></script> | |
<script src="https://unpkg.com/[email protected]/turf.js"></script> | |
<script> | |
const coastlineUrl = 'https://unpkg.com/@geo-maps/earth-lands-10km/map.geo.json'; | |
const tileUrl = 'https://{s}.tile.osm.org/{z}/{x}/{y}.png'; | |
const map = L.map('map', { | |
worldCopyJump: true, | |
layers: L.tileLayer(tileUrl), | |
center: [46,11], | |
zoom: 2 | |
}); | |
function isPrime(i) { | |
let n = Math.abs(i); | |
if(n===1) { | |
return false; | |
} | |
else if(n === 2) { | |
return true; | |
} | |
else { | |
for(var x = 2; x < n; x++) { | |
if(n % x === 0) | |
return false; | |
} | |
return true; | |
} | |
} | |
function isPrimePoint(f) { | |
return isPrime(f.geometry.coordinates[0]) && | |
isPrime(f.geometry.coordinates[1]); | |
} | |
const coll = { | |
type: 'FeatureCollecton', | |
features: [] | |
}; | |
$.getJSON(coastlineUrl, coastGeo => { | |
//L.geoJson(coastGeo).addTo(map); | |
var coastF = turf.feature(coastGeo.geometries[0]); | |
/*EUROPE for(let lat = 30; lat<=70; lat++) { | |
for(let lon = -10; lon<=40; lon++) {*/ | |
for(let lat = -60; lat<=70; lat++) { | |
for(let lon = -180; lon<=180; lon++) { | |
coll.features.push({ | |
"type": "Feature", | |
"geometry": { | |
"type": "Point", | |
"coordinates": [lon, lat] | |
} | |
}); | |
} | |
} | |
L.geoJson(coll, { | |
noWrap:true, | |
style: f => { | |
return { | |
weight: 0, | |
fillOpacity: 1, | |
color: isPrimePoint(f) ? 'red': 'blue', | |
} | |
}, | |
pointToLayer: (f, loc) => { | |
return L.circleMarker(loc, { | |
radius: isPrimePoint(f) ? 6 : 2 | |
}) | |
}, | |
filter: f => turf.inside(f, coastF) | |
}) | |
.bindTooltip(l => l.feature.geometry.coordinates.join()) | |
.addTo(map); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment