Gis 如何在Openlayer中绘制一条线并在其上绘制一个点?
如何在openlayer上绘制直线,并在穿过英里的直线上绘制点Gis 如何在Openlayer中绘制一条线并在其上绘制一个点?,gis,openlayers-3,Gis,Openlayers 3,如何在openlayer上绘制直线,并在穿过英里的直线上绘制点 我可以在openlayer上画一条线,但我不知道如何根据距离在线绘制点。绘制线,然后将绘制的线序列化为GeoJSON(使用ol.format.GeoJSON,然后沿使用Turf库,然后重用此Turf函数返回的点,将其添加到OpenLayers // GeoJSON sample line var geojson = { "type": "Feature", "properties": {}, "geometry": {
我可以在openlayer上画一条线,但我不知道如何根据距离在线绘制点。绘制线,然后将绘制的线序列化为GeoJSON(使用
ol.format.GeoJSON
,然后沿使用Turf库,然后重用此Turf函数返回的点,将其添加到OpenLayers
// GeoJSON sample line
var geojson = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
0.142822265625,
48.03769224746972
],
[
-0.230712890625,
47.73562905149295
],
[
-0.3131103515625,
47.55428670127958
],
[
-0.98876953125,
47.42065432071318
],
[
-1.6149902343749998,
47.21956811231547
],
[
-1.1370849609375,
46.558860303117164
],
[
-0.340576171875,
46.34692761055676
],
[
-0.6756591796875,
45.78284835197676
],
[
-0.494384765625,
45.10454630976873
],
[
-0.5877685546875,
44.78183504339988
]
]
}
};
// Convert GeoJSON feature line to OpenLayers feature
var lineFeature = (new ol.format.GeoJSON()).readFeature(geojson);
// Convert OpenLayers line feature to GeoJSON feature, you may want later
// to change reproject coordinates to display it on the map
var geojsonFromLineFeature = (new ol.format.GeoJSON()).writeFeature(lineFeature);
// Calculate point position 85 miles away from the point
// coordinates beginning along the line
var pointFrom85Miles = turf.along(line1, 85, {units: 'miles'});
// Convert GeoJSON point to OpenLayers point feature
var pointFrom85MilesFeature = (new ol.format.GeoJSON()).write(pointFrom85Miles);
我尝试过使用OpenLayersgetCoordinateAtM
,但结果确实与Turf不一致。
下面,我已经计算了GeoJSON线的长度,它们太不一样了,所以使用GetCoordinateTM
插值并不更好…(可能是因为它在投影平面上工作)
绘制线,然后将绘制的线序列化为GeoJSON(使用ol.format.GeoJSON
),然后沿
使用Turf库,然后重用此Turf函数返回的点将其添加到OpenLayers
// GeoJSON sample line
var geojson = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
0.142822265625,
48.03769224746972
],
[
-0.230712890625,
47.73562905149295
],
[
-0.3131103515625,
47.55428670127958
],
[
-0.98876953125,
47.42065432071318
],
[
-1.6149902343749998,
47.21956811231547
],
[
-1.1370849609375,
46.558860303117164
],
[
-0.340576171875,
46.34692761055676
],
[
-0.6756591796875,
45.78284835197676
],
[
-0.494384765625,
45.10454630976873
],
[
-0.5877685546875,
44.78183504339988
]
]
}
};
// Convert GeoJSON feature line to OpenLayers feature
var lineFeature = (new ol.format.GeoJSON()).readFeature(geojson);
// Convert OpenLayers line feature to GeoJSON feature, you may want later
// to change reproject coordinates to display it on the map
var geojsonFromLineFeature = (new ol.format.GeoJSON()).writeFeature(lineFeature);
// Calculate point position 85 miles away from the point
// coordinates beginning along the line
var pointFrom85Miles = turf.along(line1, 85, {units: 'miles'});
// Convert GeoJSON point to OpenLayers point feature
var pointFrom85MilesFeature = (new ol.format.GeoJSON()).write(pointFrom85Miles);
我尝试过使用OpenLayersgetCoordinateAtM
,但结果确实与Turf不一致。
下面,我已经计算了GeoJSON线的长度,它们太不一样了,所以使用GetCoordinateTM
插值并不更好…(可能是因为它在投影平面上工作)