如何使用 GeoJSON 对象 Openlayers 绘制多行字符串

发布于 2025-01-15 08:33:38 字数 1528 浏览 3 评论 0原文

我试图通过持有 GeoJSON 对象来绘制线串。但是当绘制过程开始时,可​​以在地图上的任何地方选择指针。我的目的是在 GeoJSON 对象上选择指针

这是一些代码。

var jsonSource = new ol.source.Vector({
  url: 'https://raw.githubusercontent.com/Kardelennkayaa/ankr_tdelay/main/KAMAN.json',
  format: new ol.format.GeoJSON(),
});

var vector = new ol.layer.Vector({
  source: jsonSource,
  background: 'white',
});
map.addLayer(vector)

var jsonSource_ank = new ol.source.Vector({
  url: 'https://raw.githubusercontent.com/Kardelennkayaa/heroku_app/main/ankara_road.json',
  format: new ol.format.GeoJSON(),
});

var vector_ank = new ol.layer.Vector({
  source: jsonSource_ank,
  background: 'white',
});
map.addLayer(vector_ank)

var draw_lineString = new ol.interaction.Draw({
    type : 'LineString',
    //source:drawSource_ls
    source:jsonSource
})
draw_lineString.on('drawstart', function(evt){
    drawSource_ls.clear()
    //select.setActive(true);
})
draw_lineString.on('drawend',function(evt){
    // alert('point is added')
    clickedCoord_lineString = evt.feature.getGeometry().getCoordinates()
    
    $('#ls_adding').modal('show');
    console.log('clicked at', evt.feature.getGeometry().getCoordinates())
    map.removeInteraction(draw_lineString)
})

function startDrawing_lineString(){
map.addInteraction(draw_lineString)
}

这是 Web 界面

目标是单击添加 LineString 时,折线可以使用相对的 GeoJSON 对象来绘制。我怎样才能做到这一点?提前致谢。

I am trying to draw linestring by holding the GeoJSON object. But when drawing process starts, the pointer can be selected everywhere on the map. My purpose is the pointer just be selected on the GeoJSON object

Here is some of the code.

var jsonSource = new ol.source.Vector({
  url: 'https://raw.githubusercontent.com/Kardelennkayaa/ankr_tdelay/main/KAMAN.json',
  format: new ol.format.GeoJSON(),
});

var vector = new ol.layer.Vector({
  source: jsonSource,
  background: 'white',
});
map.addLayer(vector)

var jsonSource_ank = new ol.source.Vector({
  url: 'https://raw.githubusercontent.com/Kardelennkayaa/heroku_app/main/ankara_road.json',
  format: new ol.format.GeoJSON(),
});

var vector_ank = new ol.layer.Vector({
  source: jsonSource_ank,
  background: 'white',
});
map.addLayer(vector_ank)

var draw_lineString = new ol.interaction.Draw({
    type : 'LineString',
    //source:drawSource_ls
    source:jsonSource
})
draw_lineString.on('drawstart', function(evt){
    drawSource_ls.clear()
    //select.setActive(true);
})
draw_lineString.on('drawend',function(evt){
    // alert('point is added')
    clickedCoord_lineString = evt.feature.getGeometry().getCoordinates()
    
    $('#ls_adding').modal('show');
    console.log('clicked at', evt.feature.getGeometry().getCoordinates())
    map.removeInteraction(draw_lineString)
})

function startDrawing_lineString(){
map.addInteraction(draw_lineString)
}

And here is the web interface

The goal is when clicking on the Add LineString, the polyline can be drawn with the relative GeoJSON object. How can I do that? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文