Я пытаюсь построить карту листов с слоем геойсона. Слой - это огромный файл, поэтому у меня есть отдельный файл с geojson в переменной.Листовка не читает внешние geojson или JS
Однако, когда я запускаю код, я получаю:
Uncaught ReferenceError: myLayer is not defined
<script src="leaflet/mygeofile.geojson"></script> <!-- or use leaflet-src.js -->
<script src="/leaflet/leaflet.js"></script> <!-- or use leaflet-src.js -->
<script src="/leaflet/leaflet_javascript.js"></script> <!-- or use leaflet-src.js -->
<script>
$(document).ready(function() {
//Set attributes of map (location and zoom)
var map = L.map('map').setView([51.505, -0.09], 13);
//Add base map layer, using a compatible source, with accesstoken/permissions
//for more basemaps: https://github.com/leaflet-extras/leaflet-providers
L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
maxZoom: 18,
id: 'your.mapbox.project.id',
accessToken: 'your.mapbox.public.access.token'
}).addTo(map);
//***********GEO JSON FILE IS CALLED RIGHT HERE*******************
L.geoJson(myLayer).addTo(map);
});
</script>
GeoJSON SAMPLE:
myLayer=[{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "Name": null, "description": null, "timestamp": null, "begin": null, "end": null, "altitudeMode": "relativeToGround", "tessellate": -1, "extrude": -1, "visibility": -1, "drawOrder": null, "icon": null, "STATEFP": "17", "COUNTYFP": "019", "TRACTCE": "005401", "BLKGRPCE": "2", "GEOID": "1701900540...........
}]}]
является '.geojson' действительное расширение файла? Я бы подумал, что вы должны сохранять свои данные в виде файла '.js' – lucas
Да, я считаю, что это так. Это то, что QGIS сохраняет как автоматически. Тем не менее, я попытался изменить расширение на json и js, и он по-прежнему дает ту же ошибку. Также изменение расширений фактически изменило структуру данных как json вместо формата geojson. – auto