上文《Leaflet笔记(9)最简单的事件响应》实现了最基本的click响应,本文将上文的例子包装一下,实现一个点击显示一个Popup的效果。基本效果如图:
Leaflet监听点击事件并弹出Popup
var m = L.map('map-container').setView([36.52,120.31], 7);
var tileAddress = 'https://api.mapbox.com/styles/v1/yqcim/';
tileAddress += 'cizh1ma3400ez2so5x1anhuzo/tiles/256/{z}/{x}/{y}';
tileAddress += '?access_token=pk.eyJ1IjoieXFjaW0iLCJhIjoiY2l6ZmhnZjEx';
tileAddress += 'MDBhajJ4cGxnNGN5MnhpdCJ9.pcZtdfk8mSFboCdwqkvW6g';
var attribution = 'Map data © ';
attribution += 'OpenStreetMap contributors, '
attribution += '';
attribution += 'CC-BY-S