最近我一直盯着 openlayers 和 openstreetmap 工作。我想要做的是画一条线,然后从那里得到最近的起点和终点的经度和纬度位置。我能够得到以下点的经度和纬度是它的脚本。
<script type="text/javascript">
var map, layer;
function init(){
var
map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
// allow testing of specific renderers via "?renderer=Canvas", etc
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer]:OpenLayers.Layer.Vector.prototype.renderers;
var vectors = new OpenLayers.Layer.Vector("Vector Layer", {
renderers: renderer
});
vectors.events.on({
'featureselected': function(feature) {
$('counter').innerHTML = this.selectedFeatures.length;
},
'featureunselected': function(feature) {
$('counter').innerHTML = this.selectedFeatures.length;
}
});
map.addLayers([layer, vectors]);
line = new OpenLayers.Control.DrawFeature(
vectors, OpenLayers.Handler.Path
);
line.events.register('featureadded', line, handleMapClick);
map.addControl(line);
map.setCenter(
new OpenLayers.LonLat(-71.147, 42.472).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 15
);
}
function handleMapClick(evt)
{
// create a WKT reader/parser/writer
var wkt = new OpenLayers.Format.WKT();
// write out the feature's geometry in WKT format
var out = wkt.write(evt.feature);
alert(out);
}
但我无法获得它最近的位置。