2014-11-21 74 views

回答

5

聲明圖層後,您需要在地圖上添加一個圖層,就像使用tilelayer一樣。請參閱下面的代碼。這應該工作。圖層控件將確定該圖層可見/添加到地圖並在列表中進行檢查。

var map = L.map('map').setView([52.814172, -2.079479], 9); 

L.tileLayer('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.jpg', { 
    maxZoom: 18, 
    attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.' 
}).addTo(map); 

// Left out layer-declarations, they are HUGE 

anti_soc.addTo(map); // here it is 

var overlayMaps = { 
    "Anti-social behaviour" :anti_soc, 
    "Criminal damage and arson": crim_dam, 
    "Burglary": burg, 
    "Violence and sexual offences": viol, 
    "Other theft": other_theft, 
    "Vehicle crime": veh_crime, 
    "Shoplifting": shoplift, 
    "Public order": pub_ord, 
    "Robbery": robb, 
    "Bicycle theft": bikes, 
    "Drugs": drugs, 
    "Theft from the person": theft_person, 
    "Other crime": other_crime, 
    "Possession of weapons": weap 
}; 

L.control.layers(null, overlayMaps).addTo(map);