一、效果图
二、源码
1. 依赖文件
(1)lushu.js(飞机路线轨迹)
var BMapGLLib = window.BMapGLLib = BMapGLLib || {};
(function() {
var e;
var b = e = b || {
version: "gl 1.0"
};
b.guid = "$BAIDU$";
(function() {
window[b.guid] = window[b.guid] || {};
b.dom = b.dom || {};
b.dom.g = function(k) {
if ("string" == typeof k || k instanceof String) {
return document.getElementById(k)
} else {
if (k && k.nodeName && (k.nodeType == 1 || k.nodeType == 9)) {
return k
}
}
return null
};
b.g = b.G = b.dom.g;
b.lang = b.lang || {};
b.lang.isString = function(k) {
return "[object String]" == Object.prototype.toString.call(k)
};
b.isString = b.lang.isString;
b.dom._g = function(k) {
if (b.lang.isString(k)) {
return document.getElementById(k)
}
return k
};
b._g = b.dom._g;
b.dom.getDocument = function(k) {
k = b.dom.g(k);
return k.nodeType == 9 ? k : k.ownerDocument || k.document
};
b.browser = b.browser || {};
b.browser.ie = b.ie = /msie (\d+\.\d+)/i.test(navigator.userAgent) ? (document.documentMode || +RegExp[
"\x241"]) : undefined;
b.dom.getComputedStyle = function(l, k) {
l = b.dom._g(l);
var n = b.dom.getDocument(l),
m;
if (n.defaultView && n.defaultView.getComputedStyle) {
m = n.defaultView.getComputedStyle(l, null);
if (m) {
return m[k] || m.getPropertyValue(k)
}
}
return ""
};
b.dom._styleFixer = b.dom._styleFixer || {};
b.dom._styleFilter = b.dom._styleFilter || [];
b.dom._styleFilter.filter = function(l, o, p) {
var n = b.dom._styleFilter;
var m;
for (var k = 0; m = n[k]; k++) {
if (m = m[p]) {
o = m(l, o)
}
}
return o
};
b.string = b.string || {};
b.string.toCamelCase = function(k) {
if (k.indexOf("-") < 0 && k.indexOf("_") < 0) {
return k
}
return k.replace(/[-_][^-_]/g, function(l) {
return l.charAt(1).toUpperCase()
})
};
b.dom.getStyle = function(m, l) {
var o = b.dom;
m = o.g(m);
l = b.string.toCamelCase(l);
var n = m.style[l] || (m.currentStyle ? m.currentStyle[l] : "") || o.getComputedStyle(m, l);
if (!n) {
var k = o._styleFixer[l];
if (k) {
n = k.get ? k.get(m) : b.dom.getStyle(m, k)
}
}
if (k = o._styleFilter) {
n = k.filter(l, n, "get")
}
return n
};
b.getStyle = b.dom.getStyle;
b.dom._NAME_ATTRS = (function() {
var k = {
"cellpadding": "cellPadding",
"cellspacing": "cellSpacing",
"colspan": "colSpan",
"rowspan": "rowSpan",
"valign": "vAlign",
"usemap": "useMap",
"frameborder": "frameBorder"
};
if (b.browser.ie < 8) {
k["for"] = "htmlFor";
k["class"] = "className"
} else {
k["htmlFor"] = "for";
k["className"] = "class"
}
return k
})();
b.dom.setAttr = function(l, k, m) {
l = b.dom.g(l);
if ("style" == k) {
l.style.cssText = m
} else {
k = b.dom._NAME_ATTRS[k] || k;
l.setAttribute(k, m)
}
return l
};
b.setAttr = b.dom.setAttr;
b.dom.setAttrs = function(m, k) {
m = b.dom.g(m);
for (var l in k) {
b.dom.setAttr(m, l, k[l])
}
return m
};
b.setAttrs = b.dom.setAttrs;
b.dom.create = function(m, k) {
var n = document.createElement(m),
l = k || {};
return b.dom.setAttrs(n, l)
};
b.object = b.object || {};
b.extend = b.object.extend = function(m, k) {
for (var l in k) {
if (k.hasOwnProperty(l)) {
m[l] = k[l]
}
}
return m
}
})();
WORLD_SIZE_MC_HALF = 20037726.372307256;
WORLD_SIZE_MC = WORLD_SIZE_MC_HALF * 2;
var h = BMapGLLib.LuShu = function(m, l, k) {
if (!l || l.length < 1) {
return
}
this._map = m;
if (k["geodesic"]) {
this.path = g(l)
} else {
this.path = l
}
this.i = 0;
this._setTimeoutQuene = [];
this._opts = {
icon: null,
speed: 400,
defaultContent: ""
};
if (!k["landmarkPois"]) {
k["landmarkPois"] = []
}
this._setOptions(k);
this._rotation = 0;
if (!(this._opts.icon instanceof BMapGL.Icon)) {
this._opts.icon = defaultIcon
}
};
h.prototype._setOptions = function(k) {
if (!k) {
return
}
for (var l in k) {
if (k.hasOwnProperty(l)) {
this._opts[l] = k[l]
}
}
};
h.prototype.start = function(_end_callback) {
var l = this,
k = l.path.length;
//########################### 代码不能标红,此标记显示下方是自己添加的################################
//自定义添加 当结束的时候判断回调函数
if(l.end_callback) {
//当前路书未结束,新的直接返回
console.log("当前路书没有跑完,等跑完后在start");
return ;
}
if(_end_callback) {
//路书跑完结束回调
l.end_callback = _end_callback ;
}
//########################### 代码不能标红,此标记显示上方是自己添加的################################
if (l.i && l.i < k - 1) {
if (!l._fromPause) {
return
} else {
if (!l._fromStop) {
l._moveNext(++l.i)
}
}
} else {
l._addMarker();
l._timeoutFlag = setTimeout(function() {
l._addInfoWin();
if (l._opts.defaultContent == "") {
l.hideInfoWindow()
}
l._moveNext(l.i)
}, 400)
}
this._fromPause = false;
this._fromStop = false
};
h.prototype.stop = function() {
this.i = 0;
this._fromStop = true;
clearInterval(this._intervalFlag);
this._clearTimeout();
for (var m = 0, l = this._opts.landmarkPois, k = l.length; m < k; m++) {
l[m].bShow = false
}
};
h.prototype.pause = function() {
clearInterval(this._intervalFlag);
this._fromPause = true;
this._clearTimeout()
};
h.prototype.hideInfoWindow = function() {
this._overlay._div.style.visibility = "hidden"
};
h.prototype.showInfoWindow = function() {
this._overlay._div.style.visibility = "visible"
};
b.object.extend(h.prototype, {
_addMarker: function(n) {
if (this._marker) {
this.stop();
this._map.removeOverlay(this._marker);
this._map.removeOverlay(this._markerL);
this._map.removeOverlay(this._markerR);
clearTimeout(this._timeoutFlag)
}
this._overlay && this._map.removeOverlay(this._overlay);
var k = new BMapGL.Marker(this.path[0]);
this._opts.icon && k.setIcon(this._opts.icon);
this._map.addOverlay(k);
k.setAnimation(BMAP_ANIMATION_DROP);
this._marker = k;
var l = new BMapGL.Marker(this.path[0], {
left: true
});
this._opts.icon && l.setIcon(this._opts.icon);
this._map.addOverlay(l);
l.setAnimation(BMAP_ANIMATION_DROP);
this._markerL = l;
var m = new BMapGL.Marker(this.path[0], {
right: true
});
this._opts.icon && m.setIcon(this._opts.icon);
this._map.addOverlay(m);
m.setAnimation(BMAP_ANIMATION_DROP);
this._markerR = m
},
_addInfoWin: function() {
var l = this;
var k = new d(l._marker.getPosition(), l._opts.defaultContent);
k.setRelatedClass(this);
this._overlay = k;
this._map.addOverlay(k)
},
_getMercator: function(k) {
return this._map.getMapType().getProjection().lngLatToPoint(k)
},
_getDistance: function(l, k) {
return Math.sqrt(Math.pow(l.x - k.x, 2) + Math.pow(l.y - k.y, 2))
},
_move: function(v, q, u) {
var o = this,
n = 0,
k = 10,
l = this._opts.speed / (1000 / k),
t = BMapGL.Projection.convertLL2MC(v),
s = BMapGL.Projection.convertLL2MC(q);
t = new BMapGL.Pixel(t.lng, t.lat);
s = new BMapGL.Pixel(s.lng, s.lat);
var r = o._getDistance(t, s);
var p = null;
if (r > 30037726) {
if (s.x < t.x) {
s.x += WORLD_SIZE_MC;
p = "right"
} else {
s.x -= WORLD_SIZE_MC;
p = "left"
}
}
var m = Math.round(o._getDistance(t, s) / l);
if (m < 1) {
o._moveNext(++o.i);
return
}
o._intervalFlag = setInterval(function() {
if (n >= m) {
clearInterval(o._intervalFlag);
if (o.i > o.path.length) {
return
}
o._moveNext(++o.i)
} else {
n++;
var w = u(t.x, s.x, n, m),
B = u(t.y, s.y, n, m),
A = BMapGL.Projection.convertMC2LL(new BMapGL.Point(w, B));
if (A.lng > 180) {
A.lng = A.lng - 360
}
if (A.lng < -180) {
A.lng = A.lng + 360
}
if (n == 1) {
var z = null;
if (o.i - 1 >= 0) {
z = o.path[o.i - 1]
}
if (o._opts.enableRotation == true) {
o.setRotation(z, v, q, p)
}
if (o._opts.autoView) {
if (!o._map.getBounds().containsPoint(A)) {
o._map.setCenter(A)
}
}
}
o._marker.setPosition(A);
o._markerL.setPosition(A);
o._markerR.setPosition(A);
o._setInfoWin(A)
}
}, k)
},
setRotation: function(s, l, t, r) {
var p = this;
var k = 0;
l = p._map.pointToPixel(l);
t = p._map.pointToPixel(t);
if (t.x != l.x) {
var q = (t.y - l.y) / (t.x - l.x),
m = Math.atan(q);
k = m * 360 / (2 * Math.PI);
if ((!r && t.x < l.x) || (r === "left")) {
k = -k + 90 + 90
} else {
k = -k
}
p._marker.setRotation(-k);
p._markerL.setRotation(-k);
p._markerR.setRotation(-k)
} else {
var n = t.y - l.y;
var o = 0;
if (n > 0) {
o = -1
} else {
o = 1
}
p._marker.setRotation(-o * 90);
p._markerL.setRotation(-o * 90);
p._markerR.setRotation(-o * 90)
}
return
},
linePixellength: function(l, k) {
return Math.sqrt(Math.abs(l.x - k.x) * Math.abs(l.x - k.x) + Math.abs(l.y - k.y) * Math.abs(
l.y - k.y))
},
pointToPoint: function(l, k) {
return Math.abs(l.x - k.x) * Math.abs(l.x - k.x) + Math.abs(l.y - k.y) * Math.abs(l.y - k.y)
},
_moveNext: function(k) {
var l = this;
if (k < this.path.length - 1) {
l._move(l.path[k], l.path[k + 1], l._tween.linear)
// 自动转向
this._map.panTo(new BMapGL.Point(l.path[k+1]['lng'], l.path[k+1]['lat']),{
noAnimation: false
})
} else {
//########################### 代码不能标红,此标记显示下方是自己添加的################################
if(this.end_callback){
this.end_callback();
this.end_callback = null;
if(this._marker)
this._map.removeOverlay(this._marker);
}
//########################### 代码不能标红,此标记显示上方是自己添加的################################
}
},
_setInfoWin: function(m) {
var l = this;
if (!l._overlay) {
return
}
l._overlay.setPosition(m, l._marker.getIcon().size);
var k = l._troughPointIndex(m);
if (k != -1) {
clearInterval(l._intervalFlag);
l._overlay.setHtml(l._opts.landmarkPois[k].html);
l._overlay.setPosition(m, l._marker.getIcon().size);
l._pauseForView(k)
} else {
l._overlay.setHtml(l._opts.defaultContent)
}
},
_pauseForView: function(k) {
var m = this;
var l = setTimeout(function() {
m._moveNext(++m.i)
}, m._opts.landmarkPois[k].pauseTime * 1000);
m._setTimeoutQuene.push(l)
},
_clearTimeout: function() {
for (var k in this._setTimeoutQuene) {
clearTimeout(this._setTimeoutQuene[k])
}
this._setTimeoutQuene.length = 0
},
_tween: {
linear: function(l, p, n, o) {
var k = l;
var r = p - l;
var m = n;
var q = o;
return r * m / q + k
}
},
_troughPointIndex: function(l) {
var n = this._opts.landmarkPois;
var o;
for (var m = 0, k = n.length; m < k; m++) {
if (!n[m].bShow) {
o = this._map.getDistance(new BMapGL.Point(n[m].lng, n[m].lat), l);
if (o < 10) {
n[m].bShow = true;
return m
}
}
}
return -1
}
});
function g(m) {
var n = [];
for (var l = 0; l < m.length - 1; l++) {
var k = j(m[l], m[l + 1]);
n = n.concat(k)
}
n = n.concat(m[m.length - 1]);
return n
}
function j(q, p) {
if (q.equals(p)) {
return [q]
}
var r = BMapGL.Projection.getDistance(f(q.lng), f(q.lat), f(p.lng), f(p.lat));
var r = BMapGL.Projection.getDistanceByLL(q, p);
if (r < 250000) {
return [q]
}
var k = [];
var o = Math.round(r / 150000);
var m = i(q, p);
k.push(q);
for (var n = 0; n < o; n++) {
var l = c(q, p, n / o, m);
k.push(l)
}
k.push(p);
return k
}
function c(u, t, v, C) {
var o = u.lat;
var n = t.lat;
var B = u.lng;
var w = t.lng;
var D = f(o);
var A = f(n);
var l = f(B);
var k = f(w);
var F = Math.sin((1 - v) * C) / Math.sin(C);
var E = Math.sin(v * C) / Math.sin(C);
var r = F * Math.cos(D) * Math.cos(l) + E * Math.cos(A) * Math.cos(k);
var q = F * Math.cos(D) * Math.sin(l) + E * Math.cos(A) * Math.sin(k);
var p = F * Math.sin(D) + E * Math.sin(A);
var m = Math.atan2(p, Math.sqrt(Math.pow(r, 2) + Math.pow(q, 2)));
var s = Math.atan2(q, r);
return new BMapGL.Point(a(s), a(m))
}
function f(k) {
return k * Math.PI / 180
}
function a(k) {
return k / Math.PI * 180
}
function i(o, l) {
var p = f(o.lat);
var n = f(l.lat);
var m = f(o.lng);
var k = f(l.lng);
return Math.acos(Math.sin(p) * Math.sin(n) + Math.cos(p) * Math.cos(n) * Math.cos(Math.abs(k - m)))
}
function d(k, l) {
this._point = k;
this._html = l
}
d.prototype = new BMapGL.Overlay();
d.prototype.initialize = function(k) {
var l = this._div = b.dom.create("div", {
style: "border:solid 1px #ccc;width:auto;min-width:50px;text-align:center;position:absolute;background:#fff;color:#000;font-size:12px;border-radius: 10px;padding:5px;white-space: nowrap;"
});
l.innerHTML = this._html;
k.getPanes().floatPane.appendChild(l);
this._map = k;
return l
};
d.prototype.draw = function() {
this.setPosition(this.lushuMain._marker.getPosition(), this.lushuMain._marker.getIcon().size)
};
b.object.extend(d.prototype, {
setPosition: function(p, q) {
var n = this._map.pointToOverlayPixel(p);
var l = b.dom.getStyle(this._div, "width");
var o = b.dom.getStyle(this._div, "height");
var k = parseInt(this._div.clientWidth || l, 10);
var m = parseInt(this._div.clientHeight || o, 10);
this._div.style.left = n.x - k / 2 + "px";
this._div.style.bottom = -(n.y - q.height) + "px"
},
setHtml: function(k) {
this._div.innerHTML = k
},
setRelatedClass: function(k) {
this.lushuMain = k
}
})
})();
(2)baidu.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?type=webgl&v=1.0&ak=52PTc99PLGvcTIta0V3yXfK5irWF3c9E"></script>
<script>
window.BMAP_AUTHENTIC_KEY = '7Cc5Kmn672miPzG4qQhvlOrERcXMMinq';
</script>
<script type="text/javascript" src="lushu.js"></script>
<title>地球模式</title>
<style type="text/css">
.anchorBL{display:none;}
</style>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
var allCountries = [
{"country": "China", "latitude": 35.86166, "longitude": 104.195397},
{"country": "Andorra", "latitude": 42.546245, "longitude": 1.601554},
{"country": "United Arab Emirates", "latitude": 23.424076, "longitude": 53.847818},
{"country": "Afghanistan", "latitude": 33.93911, "longitude": 67.709953},
{"country": "Antigua and Barbuda", "latitude": 17.060816, "longitude": -61.796428},
{"country": "Anguilla", "latitude": 18.220554, "longitude": -63.068615},
{"country": "Albania", "latitude": 41.153332, "longitude": 20.168331},
{"country": "Armenia", "latitude": 40.069099, "longitude": 45.038189},
{"country": "Netherlands", "latitude": 12.226079, "longitude": -69.060087},
{"country": "Angola", "latitude": -11.202692, "longitude": 17.873887},
{"country": "Antarctica", "latitude": -75.250973, "longitude": -0.071389},
{"country": "Argentina", "latitude": -38.416097, "longitude": -63.616672},
{"country": "American Samoa", "latitude": -14.270972, "longitude": -170.132217},
{"country": "Austria", "latitude": 47.516231, "longitude": 14.550072},
{"country": "Australia", "latitude": -25.274398, "longitude": 133.775136},
{"country": "Aruba", "latitude": 12.52111, "longitude": -69.968338},
{"country": "Azerbaijan", "latitude": 40.143105, "longitude": 47.576927},
{"country": "Bosnia and Herzegovina", "latitude": 43.915886, "longitude": 17.679076},
{"country": "Barbados", "latitude": 13.193887, "longitude": -59.543198},
{"country": "Bangladesh", "longitude": 90.356331, "latitude": 23.684994},
{"country": "Belgium", "longitude": 4.469936, "latitude": 50.503887},
{"country": "Burkina Faso", "longitude": -1.561593, "latitude": 12.238333},
{"country": "Bulgaria", "longitude": 25.48583, "latitude": 42.733883},
{"country": "Bahrain", "longitude": 50.637772, "latitude": 25.930414},
{"country": "Burundi", "longitude": 29.918886, "latitude": -3.373056},
{"country": "Benin", "longitude": 2.315834, "latitude": 9.30769},
{"country": "Bermuda", "longitude": -64.75737, "latitude": 32.321384},
{"country": "Brunei", "longitude": 114.727669, "latitude": 4.535277},
{"country": "Bolivia", "longitude": -63.588653, "latitude": -16.290154},
{"country": "Brazil", "longitude": -51.92528, "latitude": -14.235004},
{"country": "Bahamas", "longitude": -77.39628, "latitude": 25.03428},
{"country": "Bhutan", "longitude": 90.433601, "latitude": 27.514162},
{"country": "Bouvet Island", "longitude": 3.413194, "latitude": -54.423199},
{"country": "Botswana", "longitude": 24.684866, "latitude": -22.328474},
{"country": "Belarus", "longitude": 27.953389, "latitude": 53.709807},
{"country": "Belize", "longitude": -88.49765, "latitude": 17.189877},
{"country": "Canada", "longitude": -106.346771, "latitude": 56.130366},
{"country": "Cocos [Keeling] Islands", "longitude": 96.870956, "latitude": -12.164165},
{"country": "Congo [DRC]", "longitude": 21.758664, "latitude": -4.038333},
{"country": "Central African Republic", "longitude": 20.939444, "latitude": 6.611111},
{"country": "Congo [Republic]", "longitude": 15.827659, "latitude": -0.228021},
{"country": "Switzerland", "longitude": 8.227512, "latitude": 46.818188},
{"country": "Côte d'Ivoire", "longitude": -5.54708, "latitude": 7.539989},
{"country": "Cook Islands", "longitude": -159.777671, "latitude": -21.236736},
{"country": "Chile", "longitude": -71.542969, "latitude": -35.675147},
{"country": "Cameroon", "longitude": 12.354722, "latitude": 7.369722},
{"country": "China", "longitude": 104.195397, "latitude": 35.86166},
{"country": "Colombia", "longitude": -74.297333, "latitude": 4.570868},
{"country": "Costa Rica", "longitude": -83.753428, "latitude": 9.748917},
{"country": "Cuba", "longitude": -77.781167, "latitude": 21.521757},
{"country": "Cape Verde", "longitude": -24.013197, "latitude": 16.002082},
{"country": "Christmas Island", "longitude": 105.690449, "latitude": -10.447525},
{"country": "Cyprus", "longitude": 33.429859, "latitude": 35.126413},
{"country": "Czech Republic", "longitude": 15.472962, "latitude": 49.817492},
{"country": "Germany", "longitude": 10.451526, "latitude": 51.165691},
{"country": "Djibouti", "longitude": 42.590275, "latitude": 11.825138},
{"country": "Denmark", "longitude": 9.501785, "latitude": 56.26392},
{"country": "Dominica", "longitude": -61.370976, "latitude": 15.414999},
{"country": "Dominican Republic", "longitude": -70.162651, "latitude": 18.735693},
{"country": "Algeria", "longitude": 1.659626, "latitude": 28.033886},
{"country": "Ecuador", "longitude": -78.183406, "latitude": -1.831239},
{"country": "Estonia", "longitude": 25.013607, "latitude": 58.595272},
{"country": "Egypt", "longitude": 30.802498, "latitude": 26.820553},
{"country": "Western Sahara", "longitude": -12.885834, "latitude": 24.215527},
{"country": "Eritrea", "longitude": 39.782334, "latitude": 15.179384},
{"country": "Spain", "longitude": -3.74922, "latitude": 40.463667},
{"country": "Ethiopia", "longitude": 40.489673, "latitude": 9.145},
{"country": "Finland", "longitude": 25.748151, "latitude": 61.92411},
{"country": "Fiji", "longitude": 179.414413, "latitude": -16.578193},
{"country": "Falkland Islands [Islas Malvinas]", "longitude": -59.523613, "latitude": -51.796253},
{"country": "Micronesia", "longitude": 150.550812, "latitude": 7.425554},
{"country": "Faroe Islands", "longitude": -6.911806, "latitude": 61.892635},
{"country": "France", "longitude": 2.213749, "latitude": 46.227638},
{"country": "Gabon", "longitude": 11.609444, "latitude": -0.803689},
{"country": "United Kingdom", "longitude": -3.435973, "latitude": 55.378051},
{"country": "Grenada", "longitude": -61.604171, "latitude": 12.262776},
{"country": "Georgia", "longitude": 43.356892, "latitude": 42.315407},
{"country": "French Guiana", "longitude": -53.125782, "latitude": 3.933889},
{"country": "Guernsey", "longitude": -2.585278, "latitude": 49.465691},
{"country": "Ghana", "longitude": -1.023194, "latitude": 7.946527},
{"country": "Gibraltar", "longitude": -5.345374, "latitude": 36.137741},
{"country": "Greenland", "longitude": -42.604303, "latitude": 71.706936},
{"country": "Gambia", "longitude": -15.310139, "latitude": 13.443182},
{"country": "Guinea", "longitude": -9.696645, "latitude": 9.945587},
{"country": "Guadeloupe", "longitude": -62.067641, "latitude": 16.995971},
{"country": "Equatorial Guinea", "longitude": 10.267895, "latitude": 1.650801},
{"country": "Greece", "longitude": 21.824312, "latitude": 39.074208},
{"country": "South Georgia and the South Sandwich Islands", "longitude": -36.587909, "latitude": -54.429579},
{"country": "Guatemala", "longitude": -90.230759, "latitude": 15.783471},
{"country": "Guam", "longitude": 144.793731, "latitude": 13.444304},
{"country": "Guinea-Bissau", "longitude": -15.180413, "latitude": 11.803749},
{"country": "Guyana", "longitude": -58.93018, "latitude": 4.860416},
{"country": "Gaza Strip", "longitude": 34.308825, "latitude": 31.354676},
{"country": "Hong Kong", "longitude": 114.109497, "latitude": 22.396428},
{"country": "Heard Island and McDonald Islands", "longitude": 73.504158, "latitude": -53.08181},
{"country": "Honduras", "longitude": -86.241905, "latitude": 15.199999},
{"country": "Croatia", "longitude": 15.2, "latitude": 45.1},
{"country": "Haiti", "longitude": -72.285215, "latitude": 18.971187},
{"country": "Hungary", "longitude": 19.503304, "latitude": 47.162494},
{"country": "Indonesia", "longitude": 113.921327, "latitude": -0.789275},
{"country": "Ireland", "longitude": -8.24389, "latitude": 53.41291},
{"country": "Israel ", "longitude": 34.851612, "latitude": 31.046051},
{"country": "Isle of Man", "longitude": -4.548056, "latitude": 54.236107},
{"country": "India", "longitude": 78.96288, "latitude": 20.593684},
{"country": "British Indian Ocean Territory", "longitude": 71.876519, "latitude": -6.343194},
{"country": "Iraq", "longitude": 43.679291, "latitude": 33.223191},
{"country": "Iran", "longitude": 53.688046, "latitude": 32.427908},
{"country": "Iceland", "longitude": -19.020835, "latitude": 64.963051},
{"country": "Italy", "longitude": 12.56738, "latitude": 41.87194},
{"country": "Jersey", "longitude": -2.13125, "latitude": 49.214439},
{"country": "Jamaica", "longitude": -77.297508, "latitude": 18.109581},
{"country": "Jordan", "longitude": 36.238414, "latitude": 30.585164},
{"country": "Japan", "longitude": 138.252924, "latitude": 36.204824},
{"country": "Kenya", "longitude": 37.906193, "latitude": -0.023559},
{"country": "Kyrgyzstan ", "longitude": 74.766098, "latitude": 41.20438},
{"country": "Cambodia", "longitude": 104.990963, "latitude": 12.565679},
{"country": "Kiribati", "longitude": -168.734039, "latitude": -3.370417},
{"country": "Comoros", "longitude": 43.872219, "latitude": -11.875001},
{"country": "Saint Kitts and Nevis", "longitude": -62.782998, "latitude": 17.357822},
{"country": "North Korea", "longitude": 127.510093, "latitude": 40.339852},
{"country": "South Korea", "longitude": 127.766922, "latitude": 35.907757},
{"country": "Kuwait ", "longitude": 47.481766, "latitude": 29.31166},
{"country": "Cayman Islands", "longitude": -80.566956, "latitude": 19.513469},
{"country": "Kazakhstan", "longitude": 66.923684, "latitude": 48.019573},
{"country": "Laos", "longitude": 102.495496, "latitude": 19.85627},
{"country": "Lebanon", "longitude": 35.862285, "latitude": 33.854721},
{"country": "Saint Lucia", "longitude": -60.978893, "latitude": 13.909444},
{"country": "Liechtenstein", "longitude": 9.555373, "latitude": 47.166},
{"country": "Sri Lanka", "longitude": 80.771797, "latitude": 7.873054},
{"country": "Liberia", "longitude": -9.429499, "latitude": 6.428055},
{"country": "Lesotho", "longitude": 28.233608, "latitude": -29.609988},
{"country": "Lithuania", "longitude": 23.881275, "latitude": 55.169438},
{"country": "Luxembourg", "longitude": 6.129583, "latitude": 49.815273},
{"country": "Latvia", "longitude": 24.603189, "latitude": 56.879635},
{"country": "Libya", "longitude": 17.228331, "latitude": 26.3351},
{"country": "Morocco", "longitude": -7.09262, "latitude": 31.791702},
{"country": "Monaco", "longitude": 7.412841, "latitude": 43.750298},
{"country": "Moldova", "longitude": 28.369885, "latitude": 47.411631},
{"country": "Montenegro", "longitude": 19.37439, "latitude": 42.708678},
{"country": "Madagascar", "longitude": 46.869107, "latitude": -18.766947},
{"country": "Marshall Islands", "longitude": 171.184478, "latitude": 7.131474},
{"country": "Macedonia [FYROM]", "longitude": 21.745275, "latitude": 41.608635},
{"country": "Mali", "longitude": -3.996166, "latitude": 17.570692},
{"country": "Myanmar [Burma]", "longitude": 95.956223, "latitude": 21.913965},
{"country": "Mongolia", "longitude": 103.846656, "latitude": 46.862496},
{"country": "Macau", "longitude": 113.543873, "latitude": 22.198745},
{"country": "Northern Mariana Islands", "longitude": 145.38469, "latitude": 17.33083},
{"country": "Martinique", "longitude": -61.024174, "latitude": 14.641528},
{"country": "Mauritania", "longitude": -10.940835, "latitude": 21.00789},
{"country": "Montserrat", "longitude": -62.187366, "latitude": 16.742498},
{"country": "Malta", "longitude": 14.375416, "latitude": 35.937496},
{"country": "Mauritius", "longitude": 57.552152, "latitude": -20.348404},
{"country": "Maldives", "longitude": 73.22068, "latitude": 3.202778},
{"country": "Malawi", "longitude": 34.301525, "latitude": -13.254308},
{"country": "Mexico", "longitude": -102.552784, "latitude": 23.634501},
{"country": "Malaysia", "longitude": 101.975766, "latitude": 4.210484},
{"country": "Mozambique", "longitude": 35.529562, "latitude": -18.665695},
{"country": "Namibia", "longitude": 18.49041, "latitude": -22.95764},
{"country": "New Caledonia", "longitude": 165.618042, "latitude": -20.904305},
{"country": "Niger", "longitude": 8.081666, "latitude": 17.607789},
{"country": "Norfolk Island", "longitude": 167.954712, "latitude": -29.040835},
{"country": "Nigeria", "longitude": 8.675277, "latitude": 9.081999},
{"country": "Nicaragua", "longitude": -85.207229, "latitude": 12.865416},
{"country": "Netherlands", "longitude": 5.291266, "latitude": 52.132633},
{"country": "Norway", "longitude": 8.468946, "latitude": 60.472024},
{"country": "Nepal", "longitude": 84.124008, "latitude": 28.394857},
{"country": "Nauru", "longitude": 166.931503, "latitude": -0.522778},
{"country": "Niue", "longitude": -169.867233, "latitude": -19.054445},
{"country": "New Zealand", "longitude": 174.885971, "latitude": -40.900557},
{"country": "Oman", "longitude": 55.923255, "latitude": 21.512583},
{"country": "Panama", "longitude": -80.782127, "latitude": 8.537981},
{"country": "Peru", "longitude": -75.015152, "latitude": -9.189967},
{"country": "French Polynesia", "longitude": -149.406843, "latitude": -17.679742},
{"country": "Papua New Guinea", "longitude": 143.95555, "latitude": -6.314993},
{"country": "Philippines", "longitude": 121.774017, "latitude": 12.879721},
{"country": "Pakistan", "longitude": 69.345116, "latitude": 30.375321},
{"country": "Poland", "longitude": 19.145136, "latitude": 51.919438},
{"country": "Saint Pierre and Miquelon", "longitude": -56.27111, "latitude": 46.941936},
{"country": "Pitcairn Islands", "longitude": -127.439308, "latitude": -24.703615},
{"country": "Puerto Rico", "longitude": -66.590149, "latitude": 18.220833},
{"country": "Palestinian Territories", "longitude": 35.233154, "latitude": 31.952162},
{"country": "Portugal", "longitude": -8.224454, "latitude": 39.399872},
{"country": "Palau", "longitude": 134.58252, "latitude": 7.51498},
{"country": "Paraguay", "longitude": -58.443832, "latitude": -23.442503},
{"country": "Qatar", "longitude": 51.183884, "latitude": 25.354826},
{"country": "Réunion", "longitude": 55.536384, "latitude": -21.115141},
{"country": "Romania", "longitude": 24.96676, "latitude": 45.943161},
{"country": "Serbia ", "longitude": 21.005859, "latitude": 44.016521},
{"country": "Russia", "longitude": 105.318756, "latitude": 61.52401},
{"country": "Rwanda", "longitude": 29.873888, "latitude": -1.940278},
{"country": "Saudi Arabia", "longitude": 45.079162, "latitude": 23.885942},
{"country": "Solomon Islands", "longitude": 160.156194, "latitude": -9.64571},
{"country": "Seychelles", "longitude": 55.491977, "latitude": -4.679574},
{"country": "Sudan", "longitude": 30.217636, "latitude": 12.862807},
{"country": "Sweden", "longitude": 18.643501, "latitude": 60.128161},
{"country": "Singapore", "longitude": 103.819836, "latitude": 1.352083},
{"country": "Saint Helena", "longitude": -10.030696, "latitude": -24.143474},
{"country": "Slovenia", "longitude": 14.995463, "latitude": 46.151241},
{"country": "Svalbard and Jan Mayen", "longitude": 23.670272, "latitude": 77.553604},
{"country": "Slovakia", "longitude": 19.699024, "latitude": 48.669026},
{"country": "Sierra Leone", "longitude": -11.779889, "latitude": 8.460555},
{"country": "San Marino", "longitude": 12.457777, "latitude": 43.94236},
{"country": "Senegal", "longitude": -14.452362, "latitude": 14.497401},
{"country": "Somalia", "longitude": 46.199616, "latitude": 5.152149},
{"country": "Suriname", "longitude": -56.027783, "latitude": 3.919305},
{"country": "São Tomé and Príncipe", "longitude": 6.613081, "latitude": 0.18636},
{"country": "El Salvador", "longitude": -88.89653, "latitude": 13.794185},
{"country": "Syria ", "longitude": 38.996815, "latitude": 34.802075},
{"country": "Swaziland", "longitude": 31.465866, "latitude": -26.522503},
{"country": "Turks and Caicos Islands", "longitude": -71.797928, "latitude": 21.694025},
{"country": "Chad", "longitude": 18.732207, "latitude": 15.454166},
{"country": "French Southern Territories", "longitude": 69.348557, "latitude": -49.280366},
{"country": "Togo", "longitude": 0.824782, "latitude": 8.619543},
{"country": "Thailand", "longitude": 100.992541, "latitude": 15.870032},
{"country": "Tajikistan", "longitude": 71.276093, "latitude": 38.861034},
{"country": "Tokelau", "longitude": -171.855881, "latitude": -8.967363},
{"country": "Timor-Leste ", "longitude": 125.727539, "latitude": -8.874217},
{"country": "Turkmenistan", "longitude": 59.556278, "latitude": 38.969719},
{"country": "Tunisia", "longitude": 9.537499, "latitude": 33.886917},
{"country": "Tonga", "longitude": -175.198242, "latitude": -21.178986},
{"country": "Turkey", "longitude": 35.243322, "latitude": 38.963745},
{"country": "Trinidad and Tobago", "longitude": -61.222503, "latitude": 10.691803},
{"country": "Tuvalu", "longitude": 177.64933, "latitude": -7.109535},
{"country": "Taiwan", "longitude": 120.960515, "latitude": 23.69781},
{"country": "Tanzania", "longitude": 34.888822, "latitude": -6.369028},
{"country": "Ukraine", "longitude": 31.16558, "latitude": 48.379433},
{"country": "Uganda", "longitude": 32.290275, "latitude": 1.373333},
{"country": "United States", "longitude": -95.712891, "latitude": 37.09024},
{"country": "Uruguay", "longitude": -55.765835, "latitude": -32.522779},
{"country": "Uzbekistan", "longitude": 64.585262, "latitude": 41.377491},
{"country": "Vatican City", "longitude": 12.453389, "latitude": 41.902916},
{"country": "Saint Vincent and the Grenadines", "longitude": -61.287228, "latitude": 12.984305},
{"country": "Venezuela", "longitude": -66.58973, "latitude": 6.42375},
{"country": "British Virgin Islands", "longitude": -64.639968, "latitude": 18.420695},
{"country": "U.S. Virgin Islands", "longitude": -64.896335, "latitude": 18.335765},
{"country": "Vietnam", "longitude": 108.277199, "latitude": 14.058324},
{"country": "Vanuatu", "longitude": 166.959158, "latitude": -15.376706},
{"country": "Wallis and Futuna", "longitude": -177.156097, "latitude": -13.768752},
{"country": "Samoa", "longitude": -172.104629, "latitude": -13.759029},
{"country": "Kosovo", "longitude": 20.902977, "latitude": 42.602636},
{"country": "Yemen", "longitude": 48.516388, "latitude": 15.552727},
{"country": "Mayotte", "longitude": 45.166244, "latitude": -12.8275},
{"country": "South Africa", "longitude": 22.937506, "latitude": -30.559482},
{"country": "Zambia", "longitude": 27.849332, "latitude": -13.133897},
{"country": "Zimbabwe", "longitude": 29.154857, "latitude": -19.015438}
]
// GL版命名空间为BMapGL
var map = new BMapGL.Map("allmap"); // 创建Map实例
map.setMaxZoom(7.0);
map.setMinZoom(2.0);
map.centerAndZoom(new BMapGL.Point(104.195397, 35.86166), 2); // 初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
map.setMapType(BMAP_EARTH_MAP); // 设置地图类型为地球模式
/// 点击后开始飞行
map.addEventListener('click', function (e) {
if(map.getZoom() < 5.0){
map.setZoom(5.0);
map.addEventListener('zoomend', function zoomendOver (e) {
ready(104.195397, 35.86166, 120.960515, 23.69781)
});
} else {
ready(104.195397, 35.86166, 120.960515, 23.69781)
}
});
/// 调用飞行
function ready(longitude1, latitude1, longitude2, latitude2){
var path = [
new BMapGL.Point(longitude1,latitude1),
new BMapGL.Point(longitude2,latitude2)
];
var polyline = new BMapGL.Polyline(path, {
clip: false,
geodesic: true,
strokeWeight: 3
});
polyline.setStrokeColor("#00CED1");
polyline.setStrokeStyle("dashed");
var myIconStart = new BMapGL.Icon("light.png", new BMapGL.Size(100, 100));
var ptStart = new BMapGL.Point(longitude1, latitude1);
var markerStart = new BMapGL.Marker(ptStart, {
icon: myIconStart
});
markerStart.setAnimation(Animation.BMAP_ANIMATION_BOUNCE)
// 将标注添加到地图
map.addOverlay(markerStart);
var myIcon = new BMapGL.Icon("light.png", new BMapGL.Size(100, 100));
var pt = new BMapGL.Point(longitude2, latitude2);
var marker = new BMapGL.Marker(pt, {
icon: myIcon
});
// 将标注添加到地图
map.addOverlay(marker);
startLushu(polyline);
}
function startLushu(polyline) {
var fly = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAwCAYAAACFUvPfAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAACcQAAAnEAGUaVEZAAABWWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWx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SMQgZgWkqU78yvFe2XpPXsG9Sc/LzRCRRx9t4TuZtGeecQJR3w8cPX+5vr6ysVH1/++RmFNRB93KmUDfUVCg4HttWxDZugebdkNtRK8w4R3lpbRF9h4TNNb+Ov6ZeWXJyibP3yY3LKn64qabFCsJaiVzNuTnWROSf1t5pdXwvUh04MP3sfPfnn+Tnd73eWcOUnBSKuo9XATvgOUycxSZo8+CQcMWUWqeuKK9tlucaRdBIKFXDoBsKqPIiRPvXh8vOFdCZl8gEnR6QE5KWsiWfYdCLG6vK/irWi0foDVwYtY76hD95PeIzR7kLgVnT8ueWPoxf89h9FRgNfjcfP2zTwvplDjZ8JCz2t4RCOWcjDvpFsU3Qkz+34LWiLGYrEa5xmoLcHx/OZIIHZ5uU+jw9EV14OjoyUsmAr3UwjXIxv75xBY47yF2zSwLtIe9KjnylQ/SPe6uD3zvISmKXBFojpYGjy11tBvGudgZI7H8AkTfFhaeSQPNv6zUMKbf5Jnp77bJK7lkWh1yDnjoXWZsHVrsm4KM8/AVjuQYdGkzwURc1zUIiz072Xbc86HziNMvAzaNr0KqmrOaAciLaqc1PyW/sjMW4N9dpN475wLKZ7ZZM22KCe/g3rq5aFp/mLc6d60xzN7mJIdk6OzqQDpcfWRyYM726yrT5NzOMZfhv5u9tfzO/uhGRe5fFJ1umig8mDxL/zT/0i0f6H9L8B7n+trJOMfuMAAAAAElFTkSuQmCC';
lushu = new BMapGLLib.LuShu(map, polyline.getPath(), {
geodesic: true,
autoCenter: true,
autoView: true,
icon: new BMapGL.Icon(fly, new BMapGL.Size(48, 48), { anchor: new BMapGL.Size(12, 12) }),
speed: 5000000, /// 设置速度
enableRotation: true
});
lushu.start(function() {
lushu = null; //当前路书置空
map.clearOverlays();
map.removeEventListener('zoomend');
/// 飞行结束后回调iOS端finishFlyiOS方法
window.webkit.messageHandlers.finishFlyiOS.postMessage(1)
});
map.addOverlay(polyline);
}
</script>
(3)资源文件
飞行时,起终点高亮