Open nicopace opened 5 years ago
use a different geojson group for those that have guessed locations: https://gist.github.com/geog4046instructor/80ee78db60862ede74eacba220809b64
Basically,
for (node in nodeswithoutlocation) {
node.location = averageGeolocation(node.links.map(l => nodeposition[l]);
node.location.estimated = true;
}
where averageLocation is
function averageGeolocation(coords) {
if (coords.length === 1) {
return coords[0];
}
let x = 0.0;
let y = 0.0;
let z = 0.0;
for (let coord of coords) {
let latitude = coord.latitude * Math.PI / 180;
let longitude = coord.longitude * Math.PI / 180;
x += Math.cos(latitude) * Math.cos(longitude);
y += Math.cos(latitude) * Math.sin(longitude);
z += Math.sin(latitude);
}
let total = coords.length;
x = x / total;
y = y / total;
z = z / total;
let centralLongitude = Math.atan2(y, x);
let centralSquareRoot = Math.sqrt(x * x + y * y);
let centralLatitude = Math.atan2(z, centralSquareRoot);
return {
latitude: centralLatitude * 180 / Math.PI,
longitude: centralLongitude * 180 / Math.PI
};
}
and then
function estimateNodeIcon(feature, latlng) {
let myIcon = L.icon({
iconUrl: 'my-icon.png',
shadowUrl: 'my-icon.png',
iconSize: [25, 25], // width and height of the image in pixels
shadowSize: [35, 20], // width, height of optional shadow image
iconAnchor: [12, 12], // point of the icon which will correspond to marker's location
shadowAnchor: [12, 6], // anchor point of the shadow. should be offset
popupAnchor: [0, 0] // point from which the popup should open relative to the iconAnchor
})
return L.marker(latlng, { icon: myIcon })
}
// create an options object that specifies which function will called on each feature
let estimateNodeLayerOpts = {
pointToLayer: estimateNodeIcon
}
certainnodes = nodes.filter(n => !nodes.location.estimated)
estimatednodes = nodes.filter(n => nodes.location.estimated)
L.geoJSON(estimatednodes, estimateNodeLayerOpts).addTo(map)
and we can use this icon as a marker: https://fontawesome.com/icons/question-circle?style=solid
https://gist.github.com/tlhunter/0ea604b77775b3e7d7d25ea0f70a23eb