码迷,mamicode.com
首页 > 编程语言 > 详细

[Javascript] Adding Shapes to Maps with Leaflet and GeoJSON

时间:2015-03-21 21:09:51      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

<!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());
}

 

技术分享

[Javascript] Adding Shapes to Maps with Leaflet and GeoJSON

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/4356172.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!