admin管理员组文章数量:1332395
I need to be able to center the leaflet map on a marker when the appropriate button is click.
<button onclick='getLoc(" + geojson.features[i].geometry.coordinates[0] + "," + geojson.features[i].geometry.coordinates[1] + ")'>View</button>
function getLoc(c){
var c = L.GeoJSON([lng,lat]);
}
I'm stuck from here, any help to finish this would be greatly appreciated. Or if anyone else has a different way of doing it using JSON.
I need to be able to center the leaflet map on a marker when the appropriate button is click.
<button onclick='getLoc(" + geojson.features[i].geometry.coordinates[0] + "," + geojson.features[i].geometry.coordinates[1] + ")'>View</button>
function getLoc(c){
var c = L.GeoJSON([lng,lat]);
}
I'm stuck from here, any help to finish this would be greatly appreciated. Or if anyone else has a different way of doing it using JSON.
Share Improve this question asked Mar 21, 2014 at 20:09 TiddlyWinTiddlyWin 1551 silver badge8 bronze badges2 Answers
Reset to default 6I think what you're looking for is the setView
method. Assuming that your map variable is called map
, you can set the lat/lng of the map by calling the method like this:
map.setView([51.505, -0.09], 13); // ([lat, lng], zoom)
I managed to solve this problem
Here is the solution
<button onclick='getLoc(" + geojson.features[i].geometry.coordinates[0] + "," + geojson.features[i].geometry.coordinates[1] + ")'>View</button>
function getLoc(lat, lng){
map.setView(new L.LatLng(lat, lng), 12);
}
本文标签: javascriptTo center a leaflet map on a marker from a link or buttonStack Overflow
版权声明:本文标题:javascript - To center a leaflet map on a marker from a link or button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742282813a2446406.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论