html 加载外部GeoJSON(Promises):请求数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 加载外部GeoJSON(Promises):请求数据相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Starter map</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
<!-- MAP SCRIPT -->
<script>
// Add AJAX request for data
var counties = $.ajax({
url:"https://gist.githubusercontent.com/maptastik/df8e483d5ac1c6cae3dc4a7c02ea9039/raw/9cd46849bddcfa90aab240772a12275408d6d8d0/kyCounties.geojson",
dataType: "json",
success: console.log("County data successfully loaded."),
error: function (xhr) {
alert(xhr.statusText)
}
})
var map = L.map('map')
.setView([37.857507, -85.632935], 7);
var basemap = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>',
subdomains: 'abcd',
maxZoom: 19
}).addTo(map);
</script>
</body>
</html>
以上是关于html 加载外部GeoJSON(Promises):请求数据的主要内容,如果未能解决你的问题,请参考以下文章
html 加载外部GeoJSON(Promises):向地图添加数据
html 加载外部GeoJSON(Promises):. when()和.done()
html 加载外部GeoJSON(Promise方法):Boilerplate
如何从 openlayers 读取外部 GeoJSON 文件?
PromiseKit 在 Promises 中包装外部闭包
从外部访问 Leaflet.js GeoJson 功能