Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add query class, and bycar bybus class, but by car and by bus not got…
… done.
- Loading branch information
Showing
10 changed files
with
273 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | ||
|
||
<title>Example</title> | ||
<link rel="stylesheet" href="../lib/leaflet/leaflet.css"/> | ||
<script type="text/javascript" src="../lib/leaflet/leaflet.js"></script> | ||
|
||
<script type="text/javascript" src="../src/L.ChinaProj.js"></script> | ||
<script type="text/javascript" src="../src/L.Routing.js"></script> | ||
<script src="../src/L.Request.js"></script> | ||
|
||
<script src="../src/L.Routing.Conf.js"></script> | ||
<script src="../src/L.Routing.Controller.js"></script> | ||
<script src="../src/L.Routing.Reader.js"></script> | ||
<script src="../src/L.Routing.Bywalk.js"></script> | ||
<script src="../src/L.Routing.Query.js"></script> | ||
<style> | ||
html, body, #map { | ||
height: 100%; | ||
width: 100%; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="map"></div> | ||
</body> | ||
<script type="text/javascript"> | ||
var osmUrl = 'http://tile-{s}.openstreetmap.fr/hot/{z}/{x}/{y}.png', | ||
osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', | ||
osm = L.tileLayer(osmUrl, { | ||
maxZoom: 18, | ||
attribution: osmAttrib, | ||
tileSize: 256 | ||
}), | ||
latlng = new L.LatLng(39.91668168130951, 116.3941812515259); | ||
|
||
var map = new L.Map('map', {center: latlng, zoom: 15, layers: [osm]}); | ||
|
||
|
||
var route = new L.Routing(map); | ||
route.getTarget("KFC"); | ||
|
||
|
||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
L.Routing.Bybus = L.Routing.Reader.extend({ | ||
initialize: function (layer, options) { | ||
L.Routing.Reader.prototype.initialize.call(this, options); | ||
this.layer = layer; | ||
}, | ||
setParams: function (from, to) { | ||
this.params = { | ||
origin: from[1] + "," + from[0], | ||
destination: to[1] + "," + to[0], | ||
city: "北京", | ||
output: "json", | ||
key: this.key | ||
} | ||
|
||
|
||
this.url = this.url + "direction/transit/integrated"; | ||
}, | ||
callback: function (a, b, c) { | ||
debugger; | ||
var steps = b.route.paths[0].steps; | ||
var distance = b.route.paths[0].distance; | ||
var duration = b.route.paths[0].duration; | ||
for (var i in steps) { | ||
this._lineReader(steps[i].polyline).addTo(this.layer); | ||
} | ||
|
||
this.layer._map.fitBounds(this.layer.getBounds()); | ||
|
||
var time = (duration / 60) / 60 | ||
console.log("需要花费:" + time + "小时"); | ||
console.log("距离:" + (distance / 1000) + "公里"); | ||
} | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
L.Routing.Bycar = L.Routing.Reader.extend({ | ||
initialize: function (layer, options) { | ||
L.Routing.Reader.prototype.initialize.call(this, options); | ||
this.layer = layer; | ||
}, | ||
setParams: function (from, to) { | ||
this.params = { | ||
origin: from[1] + "," + from[0], | ||
destination: to[1] + "," + to[0], | ||
output: "json", | ||
key: this.key | ||
} | ||
|
||
|
||
this.url = this.url + "direction/driving"; | ||
}, | ||
callback: function (a, b, c) { | ||
debugger; | ||
var steps = b.route.paths[0].steps; | ||
var distance = b.route.paths[0].distance; | ||
var duration = b.route.paths[0].duration; | ||
for (var i in steps) { | ||
this._lineReader(steps[i].polyline).addTo(this.layer); | ||
} | ||
|
||
this.layer._map.fitBounds(this.layer.getBounds()); | ||
|
||
var time = (duration / 60) / 60 | ||
console.log("需要花费:" + time + "小时"); | ||
console.log("距离:" + (distance / 1000) + "公里"); | ||
} | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
L.Routing.Bywalk = L.Routing.Reader.extend({ | ||
initialize: function (layer) { | ||
L.Routing.Reader.prototype.initialize.call(this); | ||
initialize: function (layer, options) { | ||
L.Routing.Reader.prototype.initialize.call(this, options); | ||
this.layer = layer; | ||
}, | ||
makeParams: function (from, to) { | ||
this.params = | ||
"origin=" + from[1] + "," + from[0] + | ||
"&destination=" + to[1] + "," + to[0] + | ||
"&output=json" + | ||
"&key=" + this.key; | ||
setParams: function (from, to) { | ||
this.params = { | ||
origin: from[1] + "," + from[0], | ||
destination: to[1] + "," + to[0], | ||
output: "json", | ||
key: this.key | ||
} | ||
|
||
|
||
this.url = this.url + "walking"; | ||
this.url = this.url + "direction/walking"; | ||
}, | ||
callback: function (a, b, c) { | ||
debugger; | ||
var steps = b.route.paths[0].steps; | ||
var distance = b.route.paths[0].distance; | ||
var duration = b.route.paths[0].duration; | ||
for (var i in steps) { | ||
this._lineReader(steps[i].polyline).addTo(this.layer); | ||
} | ||
|
||
this.layer._map.fitBounds(this.layer.getBounds()); | ||
|
||
var time = (duration / 60) / 60 | ||
console.log("需要花费:" + time + "小时"); | ||
console.log("距离:" + (distance / 1000) + "公里"); | ||
} | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
L.Routing.Query = L.Routing.Reader.extend({ | ||
|
||
initialize: function (layer, options) { | ||
L.Routing.Reader.prototype.initialize.call(this, options); | ||
this.layer = layer; | ||
}, | ||
setParams: function (keywords, location) { | ||
this.params = { | ||
keywords: keywords, | ||
location: location, | ||
datatype: "poi", | ||
types: "050301", | ||
key: this.key | ||
} | ||
|
||
|
||
this.url = this.url + "assistant/inputtips"; | ||
}, | ||
callback: function (a, b, c) { | ||
var pointsArr = b.tips; | ||
for (var i in pointsArr) { | ||
var marker = this._pointReader(pointsArr[i].location) | ||
marker.addTo(this.layer); | ||
} | ||
this.layer._map.fitBounds(this.layer.getBounds()); | ||
}, | ||
clickCallback: function (e) { | ||
debugger; | ||
alert("Click"); | ||
} | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,78 @@ | ||
L.Routing.Reader = L.Class.extend({ | ||
initialize: function (key) { | ||
initialize: function (options) { | ||
this.key = L.Routing.Conf.key; | ||
this.url = L.Routing.Conf.url; | ||
this.dictionary = L.Routing.Conf.dictionary; | ||
|
||
L.setOptions(this, options); | ||
}, | ||
_getRoute: function () { | ||
getRoute: function () { | ||
|
||
L.Request.get(this.url, this.params, this.callback, this); | ||
L.Request.JSONP(this.url, this.params, this.callback, this); | ||
}, | ||
getPOI: function () { | ||
this.getRoute(); | ||
}, | ||
|
||
_lineReader: function (lineString) { | ||
debugger; | ||
var line = lineString.split(";"); | ||
var lineArray = []; | ||
for (var i in line) { | ||
var lng = Number(line[i].substr(0, line[i].indexOf(","))); | ||
var lat = Number(line[i].substr(line[i].indexOf(",") + 1)); | ||
var gpsLatlng = L.ChinaProj.gcj_To_Gps84(lat, lng); | ||
var latlng = new L.LatLng(gpsLatlng[0], gpsLatlng[1]); | ||
var latlng = this._transform(lat, lng); | ||
|
||
lineArray.push(latlng) | ||
} | ||
var polyline = L.polyline(lineArray); | ||
if (this.options.colorfulLine) { | ||
var polyline = L.polyline(lineArray, { | ||
color: this._getRandomColor(), | ||
weight: 5, | ||
opacity: 0.8 | ||
}); | ||
} else { | ||
var polyline = L.polyline(lineArray); | ||
} | ||
polyline.on('click', this.clickCallback); | ||
|
||
return polyline; | ||
}, | ||
_transform: function (lat, lng) { | ||
debugger; | ||
switch (this.options.transform) { | ||
case "WGS84": | ||
var gpsLatlng = L.ChinaProj.gcj_To_Gps84(lat, lng); | ||
var latlng = new L.LatLng(gpsLatlng[0], gpsLatlng[1]); | ||
break; | ||
case "BD09": | ||
var gpsLatlng = L.ChinaProj.gcj02_To_Bd09(lat, lng); | ||
var latlng = new L.LatLng(gpsLatlng[0], gpsLatlng[1]); | ||
break; | ||
case "NONE": | ||
var latlng = new L.LatLng(lat, lng); | ||
break; | ||
} | ||
return latlng; | ||
}, | ||
_pointReader: function (pointsString) { | ||
var lng = Number(pointsString.substr(0, pointsString.indexOf(","))); | ||
var lat = Number(pointsString.substr(pointsString.indexOf(",") + 1)); | ||
var latlng = this._transform(lat, lng); | ||
var marker = new L.marker(latlng); | ||
marker.on('click', this.clickCallback); | ||
return marker; | ||
|
||
}, | ||
|
||
_getRandomColor: function () { | ||
|
||
return '#' + | ||
(function (color) { | ||
return (color += '0123456789abcdef'[Math.floor(Math.random() * 16)]) | ||
&& (color.length == 6) ? color : arguments.callee(color); | ||
})(''); | ||
} | ||
|
||
}); | ||
}); | ||
|
Oops, something went wrong.