【Leafletjs】1.创建一个地图

code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" />
</head>
<body>
    <div id="map" style=" 600px; height: 400px"></div>
    <script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"/>
    <script>
    var map = L.map('map').setView([30, 118], 4);
    L.tileLayer('http://{s}.mapabc.com/mapabc/maptile?&x={x}&y={y}&z={z}', {
    subdomains: ["emap1", "emap2", "emap3"]
    }).addTo(map);
    </script>
</body>
</html>

简单介绍:

   L.map是在页面上创建地图并操控它的只要方法。

L.map('map').setView([30, 118], 4)
其形式相当于:L.map( <HTMLElement|String> *id*, <Map options> *options*? )

   L.tileLayer用于在地图中加载瓦片(示例加载mapabc的瓦片)。

L.tileLayer('http://{s}.mapabc.com/mapabc/maptile?&x={x}&y={y}&z={z}', {
    subdomains: ["emap1", "emap2", "emap3"]
    }).addTo(map)
其形式相当于:L.tileLayer( <String> *urlTemplate*, <TileLayer options> *options*? )

Demo:http://jsfiddle.net/shitao1988/KDr4B/
原文地址:https://www.cnblogs.com/shitao/p/3538219.html