Leaflet(Leaflet.Photo)显示带有地理标签的照片

时间:2015-11-17 09:34:11

标签: javascript web leaflet photos


我是网络技术的新手,我在将地理标记的照片放入/插入openstreetmap时遇到了问题。在script.js中我做:

var map = L.map( map_div, {
        center: [20.0, 5.0],
        minZoom: 2,
        maxZoom: 18,
        zoom: 3
});

L.tileLayer( 'http://{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="http://osm.org/copyright" title="OpenStreetMap" target="_blank">OpenStreetMap</a> contributors | Tiles Courtesy of <a href="http://www.mapquest.com/" title="MapQuest" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png" width="16" height="16">',
            subdomains: ['otile1','otile2','otile3','otile4']
}).addTo( map );

                 // here is my problem
var photoLayer = L.Photo.Cluster( { spiderfyDistanceMultiplier: 1.2 }).on('click', function (evt) {
        evt.layer.bindPopup(L.Util.template('<img src="{url}"/></a><p>{caption}</p>', evt.layer.photo), {
        className: 'leaflet-popup-photo',
        minWidth: 400
        }).openPopup();
});


var photos = [];
photos.push({
        lat: map_lat, // longitude
        lng: map_lon, // latitude
        thumbnail: path // path to my photo
});

photoLayer.add(photos).addTo(map);
map.fitBounds(photoLayer.getBounds());

我的浏览器(Chromium)仍在抱怨:

Uncaught TypeError: Cannot read property 'Cluster' ofundefined
(anonymous function) @ script.js:71m.
Callbacks.j @ jquery.min_1.11.3.js:2m.
Callbacks.k.fireWith @ jquery.min_1.11.3.js:2
x @ jquery.min_1.11.3.js:5
m.ajaxTransport.a.send.b @ jquery.min_1.11.3.js:5

难道你们,请问,为什么我不能把照片放到地图上?

答案:通过纠正调用函数中的案例来解决问题L.Photo.Cluster - &gt; L.photo.cluster和另一个问题是导入JS文件,正确的导入序列:

    <script type="text/javascript" src="leaflet/leaflet.js"></script>
    <script type="text/javascript" src="leaflet/leaflet-src.js"></script>
    <script src="//rawgit.com/turban/Leaflet.Photo/gh-pages/examples/lib/cluster/leaflet.markercluster.js"></script>
    <script src="//rawgit.com/turban/Leaflet.Photo/gh-pages/examples/lib/cluster/leaflet.markercluster-src.js"></script>
    <script src="//rawgit.com/turban/Leaflet.Photo/gh-pages/Leaflet.Photo.js"></script>
    <script src="MYscript.js"></script>

1 个答案:

答案 0 :(得分:0)

查看有问题插件的文档似乎是一个简单的区分大小写问题,正确的是:

 L.photo.cluster( <insert code here> )

https://github.com/turban/Leaflet.Photo/blob/gh-pages/examples/picasa.html