<!DOCTYPE html>
<html>
<head>
<title>GeoJSON Example</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<style>
#wrapper {
margin: 0 auto;
width: 100%;
}
#panel{
float: left;
width: 100%;
height:50px;
background-color: #175B81;
color:white;
}
#map {
float: left;
width: 80%;
height:600px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="panel"><span class="p2"></span>
<select id="league" onchange="LeagueSelect()">
<option value="NL" >National</option>
<option value="AL" >American</option>
</select>
</div>
<div id="map"> </div>
</div>
<script>
var url = 'BaseBallFinal.json';
var map = L.map('map').setView([39.0, -98.26], 4);
var osm=new L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',{
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'});
osm.addTo(map);
var myData = L.layerGroup([]);
var bbTeam = L.geoJSON(null, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, {
radius:6,
opacity: .5,
color:'green',
fillColor: 'green',
fillOpacity: 0.8
}).bindTooltip(feature.properties.Name);
}
});
$.getJSON(url, function(data) {
bbTeam.addData(data);
});
myData.addLayer(bbTeam);
myData.addTo(map);
function LeagueSelect() {
var choice = document.getElementById("league").value;
console.log(choice);
var theColor;
switch(choice) {
case 'NL':
theColor = 'blue'
break;
case 'AL':
theColor = 'red'
break;
default:
theColor = 'green'
}
myData.clearLayers();
map.removeLayer(myData);
bbTeam = L.geoJSON(null, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, {
radius:6,
opacity: .5,
color:theColor,
fillColor: theColor,
fillOpacity: 0.8
}).bindTooltip(feature.properties.Name);
},
filter: function(feature, layer) {
return (feature.properties.League == choice );
},
});
$.getJSON(url, function(data) {
bbTeam.addData(data);
});
myData.addLayer(bbTeam);
myData.addTo(map);
}
</script>
</body>
</html>