我对 osm 真的很陌生。考虑到我的代码,我想问一个问题。目前,我的代码使 pgrouting 在两点之间工作。起点由地理位置选择,终点我手动将其写为lonFinal,latFinal。我想要的是在geolaciton(已经完成)选择的点和地图上的点击点之间建立一条路线。实际上问题是我将如何选择点击点作为终点。提前致谢。
<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -->
<html>
<head>
<meta http-equiv="content-type" content="TEXT/HTML; CHARSET=UTF-8">
<meta lang="de">
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script >
var map;
function init() {
var proj = new OpenLayers.Projection("EPSG:4326");
var mapproj = new OpenLayers.Projection("EPSG:3857");
var bounds = new OpenLayers.Bounds(
16.1536311, 48.106509,16.6148645, 48.3433243
).transform(proj, mapproj);
var options = {
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.KeyboardDefaults(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Scale(),
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.MousePosition(),
],
maxExtent: bounds,
projection: new OpenLayers.Projection("EPSG:3857")
};
map = new OpenLayers.Map("map", options);
var osmBaseLayer = new OpenLayers.Layer.OSM();
map.addLayer(osmBaseLayer);
var lonStart = 16.36864;
var latStart = 48.19779;
var lonFinal = 16.36893;
var latFinal = 48.19638;
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}else{
alert("Geolocation is not supported by this browser.");
}
var lonStart = 16.36864;
var latStart = 48.19779;
var lonFinal = 16.36893;
var latFinal = 48.19638;
var startCoord = new OpenLayers.LonLat(lonStart,latStart).transform(
proj, map.getProjectionObject());
map.setCenter(startCoord, 14);
};
function showPosition(position)
{
var lonFinal = 16.36759;
var latFinal = 48.19629;
lonStart=position.coords.longitude;
latStart=position.coords.latitude;
var Style = {strokeColor: "red", strokeWidth:4}
var vector_layer= new OpenLayers.Layer.Vector("pgrouting",
{projection: new OpenLayers.Projection("EPSG:4326"),
style: Style,
strategies: [new OpenLayers.Strategy.BBOX()],
protocol: new OpenLayers.Protocol.HTTP({
url:"http://localhost/geoinfo/pgrouting.php",
params: {'lonStart': lonStart,
'latStart': latStart,
'lonEnd': lonFinal,
'latEnd': latFinal},
format: new OpenLayers.Format.GeoJSON()
})
});
map.addLayer(vector_layer);
var vector_layer= new OpenLayers.Layer.Vector("Kaiserstrasse",
{projection: new OpenLayers.Projection("EPSG:4326"),
strategies: [new OpenLayers.Strategy.BBOX()],
protocol: new OpenLayers.Protocol.HTTP({
url:"http://localhost/geoinfo/kaiser.php",
format: new OpenLayers.Format.GeoJSON()
}),
fillColor: 'green',
strokeColor: 'green',
strokeWidth: 10});
map.addLayer(vector_layer);
}
</script>
</head>
<body onload="init();">
<div id="map" class='divMap'></div>
</body>
</html>