Created
February 9, 2017 00:02
-
-
Save maggiben/c6730fc7363f122131e15b29b57a44c0 to your computer and use it in GitHub Desktop.
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
var MAP = null; | |
// This example creates a simple polygon representing the Bermuda Triangle. | |
function initMap() { | |
MAP = new google.maps.Map(document.getElementById('map'), { | |
zoom: 2, | |
center: { | |
lat: 24.886, | |
lng: -70.268 | |
}, | |
mapTypeId: 'terrain' | |
}); | |
google.maps.event.addListener(MAP, 'mousemove', function(event) { | |
displayCoordinates(event.latLng); | |
}); | |
function displayCoordinates(pnt) { | |
var lat = pnt.lat(); | |
lat = lat.toFixed(4); | |
var lng = pnt.lng(); | |
lng = lng.toFixed(4); | |
console.log("Latitude: " + lat + " Longitude: " + lng); | |
} | |
} | |
function makePath(feature) { | |
var paths = _.get(feature, 'geometry.coordinates').map(entry => { | |
return entry.reduce((list, polygon) => { | |
// This map() only transforms the data. | |
polygon = polygon.map(point => { | |
// Important: the lat/lng are vice-versa in GeoJSON | |
return { | |
lat: point[1], | |
lng: point[0] | |
}; | |
}); | |
polygon.forEach(point => { | |
list.push(point); | |
}) | |
return list; | |
}, []); | |
}); | |
return paths; | |
} | |
function filter(geo, names) { | |
var features = geo.features.filter(feature => { | |
return names.indexOf(feature.properties.name.toLowerCase()) > -1; | |
}); | |
//var union = turf.union(features[0], features[1], features[2]); | |
var [x, ...z] = features; | |
var union = z.reduce((a, b) => { | |
return turf.union(a, b); | |
}, x); | |
console.log(features.map(f => f.id)) | |
var bolivia = { | |
type: 'Feature', | |
geometry: { | |
type: 'Point', | |
coordinates: [-61.206924245413745, -21.278068598002434] | |
}, | |
properties: { | |
name: 'bolivia' | |
} | |
}; | |
var isInside = turf.inside(bolivia, union); // returns true | |
console.log(isInside) | |
var paths = makePath(union); | |
var polygon = new google.maps.Polygon({ | |
paths: paths[1], | |
}); | |
// given "map" is defined, this will display the polygon on the map | |
//geojson.js | |
polygon.setMap(MAP); | |
} | |
$(document).ready(initMap); | |
axios.get('http://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json') | |
.then(result => result.data) | |
.then(json => { | |
find('argentina') | |
filter(json, ['argentina', 'uruguay', 'bolivia', 'brazil', 'peru', 'paraguay']); | |
/*function find(name) { | |
var feature = json.features.find(feature => { | |
return feature.properties.name.toLowerCase() === name; | |
}); | |
console.log(feature.geometry.coordinates[0].length) | |
var paths = _.map(feature.geometry.coordinates, function(entry) { | |
return _.reduce(entry, function(list, polygon) { | |
// This map() only transforms the data. | |
_.each(_.map(polygon, function(point) { | |
// Important: the lat/lng are vice-versa in GeoJSON | |
//return new google.maps.LatLng(point[1], point[0]); | |
return { | |
lat: point[1], | |
lng: point[0] | |
} | |
}), function(point) { | |
list.push(point); | |
}); | |
return list; | |
}, []); | |
}); | |
console.log(paths) | |
var polygon = new google.maps.Polygon({ | |
paths: paths[1], | |
}); | |
// given "map" is defined, this will display the polygon on the map | |
//geojson.js | |
polygon.setMap(MAP); | |
}*/ | |
}) | |
class Region { | |
constructor() { | |
} | |
makePath(feature) { | |
var paths = _.map(feature.geometry.coordinates, function(entry) { | |
return _.reduce(entry, function(list, polygon) { | |
// This map() only transforms the data. | |
_.each(_.map(polygon, function(point) { | |
// Important: the lat/lng are vice-versa in GeoJSON | |
return { | |
lat: point[1], | |
lng: point[0] | |
} | |
}), function(point) { | |
list.push(point); | |
}); | |
return list; | |
}, []); | |
}); | |
return paths; | |
} | |
} | |
// Fetch a random joke | |
function fetchQuote() { | |
return new Promise((resolve, reject) => { | |
setTimeout(function() { | |
return resolve(1000) | |
}, 1500) | |
}) | |
} | |
async function sayJoke() { | |
try { | |
let result = await fetchQuote(); | |
//document.writeln("Joke:", result); | |
} catch (err) { | |
console.error(err); | |
} | |
} | |
sayJoke(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment