2013-12-10 78 views
2

我是新手册和JavaScript。我想我可以使用geocommons和GeoJSON为映射项目托管数据。将外部geojson添加到传单层

我找到了External GeoJSON and Leaflet: The Other Way(s)。本教程使用传单插件阅读外部GeoJSON,但我无法获取它在地图上呈现的点。代码的地图部分呈现良好,但GeoJSON不会出现。

var geojsonLayer = new L.GeoJSON.AJAX("http://geocommons.com/datasets/168923/features.json?lat=53.796&lon=-1.551&radius=3&callback=?", {onEachFeature:popUp}); 

function popUp(feature, layer) { 
    layer.bindPopup(feature.properties.name); 
} 

geojsonLayer.addTo(myMap); 
+0

之间加入这一行调用它能否请你打开你创建的HTML文件的首选浏览器并添加您可能在JavaScript控制台中看到的错误?以下是一些[更多文档](https://developers.google.com/chrome-developer-tools/)帮助您诊断错误的方法。 – geraldarthur

+0

感谢您的回复以及有关调试的信息。我收到三个错误。 – user3085296

+0

拒绝执行'https://raw.github.com/calvinmetcalf/leaflet-ajax/master/dist/leaflet.ajax.min.js'脚本,因为它的MIME类型('text/plain')不可执行,并启用严格的MIME类型检查。 index.html:1 Uncaught TypeError:undefined不是函数 – user3085296

回答

3

保存leaflet.ajax pluginleaflet.ajax.min.js在同一文件夹作为你的HTML页面,然后通过在<head>标签

<script src="leaflet.ajax.min"></script>