var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: {lat: -33.865427, lng: 151.196123},
mapTypeId: 'terrain'
});
// Creamos, mediante el método createElement, una etiqueta script para pasar el enlace
// de la fuente URL con el GeoJSON
var script = document.createElement('script');
/* Cargamos un fichero GeoJSON. En este ejemplo, hemos obtenido un fichero del servicio de USGS de terremotos, https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php y lo hemos subido a un servidor propio, ya que no permite hacer llamadas directamente. */
/* - Mediante el atributo src cargamos la URL, selecciondo el head del documento, y añadiendo,
con el método appendChild, el script */
script.src = 'http://comunicaciondigital.es/files/masterdatos/earthquakes.geojson';
document.getElementsByTagName('head')[0].appendChild(script);
/* - Mediante la clase setStyle se le pasan, a través de una función, los valores de Feature
de la propiedad mag de cada item del fichero GeoJSON
- Con la sentencia return la función devolverá el valor de mag representado con el icono
círculo */
map.data.setStyle(function(feature) {
var magnitude = feature.getProperty('mag');
return {
icon: getCircle(magnitude)
};
});
}
/* Creamos ahora una función que devuelva como parámetro las opciones del símbolo, en este
caso: círculo de color rojo, etc. */
function getCircle(magnitude) {
return {
path: google.maps.SymbolPath.CIRCLE,
fillColor: 'red',
fillOpacity: .2,
scale: Math.pow(2, magnitude) / 2,
strokeColor: 'white',
strokeWeight: .5
};
}
/* Ahora tenemos que cargar las posiciones de los...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.