[Javascript] Adding Shapes to Maps with Leaflet and GeoJSON

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title>Leaflet Demo</title>
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css"/>

</head>
<body>

<div id="map"></div>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>

</body>
</html>

 

$.getJSON(‘//jsbin.com/qogati/1.js‘, renderMap);

function renderMap (geoData) {
  var map = L.map(‘map‘);
  var osm = ‘//{s}.tiles.mapbox.com/v3/examples.map-i87786ca/{z}/{x}/{y}.png‘;

  L.tileLayer(osm).addTo(map);

  var geoJson = L.geoJson(geoData, {
    style: function (feature) {
      return {
        weight: 1,
        opacity: 0.5,
        color: ‘#00ff00‘,
        fillColor: ‘#00dd00‘,
        fillOpacity: 0.2
      }
    }
  }).addTo(map);
  map.fitBounds(geoJson.getBounds());
}

 

技术分享

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。