我正在制作传单地图,我想使用leaflet.draw插件为用户提供绘制矢量和标记的选项。接下来,我想向用户提供将矢量/标记保存到他们的计算机的选项(例如,作为geojson)。我正在寻找指针和示例如何实现这一点。
答案 0 :(得分:1)
如果您可以将所有功能都添加到LayerGroup
,那么您可以在其上调用toGeoJSON()
- 请参阅http://leafletjs.com/reference.html#layergroup-togeojson。然后可以将结果发送到FileSaver.js进行客户端下载,例如
var blob = new Blob([JSON.stringify(result)], {type: "application/json;charset=utf-8"});
saveAs(blob, "features.json");
答案 1 :(得分:0)
editCoord <- function(){
pgn <- NULL
if(length(input$map_draw_all_features$features) != 0) {
if(unique(unlist(lapply(input$map_draw_all_features$features, function(x){x$geometry$type}))) == "Polygon") {
for(j in 1:length(input$map_draw_all_features$features)){
geo <- unlist(lapply(input$map_draw_all_features$features[j], function(x){x$geometry$coordinates}))
v <- seq(1, length(geo), 2)
n <- length(geo)/2
for (i in 1:n) {
xy <- c(geo[v[i]], geo[i*2])
if (i == n) break()
pgn <- c(pgn, paste0(xy[1]," ",xy[2],","))
}
pgn <- c(pgn, paste0(xy[1]," ",xy[2]))
}
cat(pgn, "\n", file=paste0("f", input$usertext))
readLines(paste0("f", input$usertext))
}
}
}
editPlot <- function(){
db <- dbConnect(MySQL(), dbname = "watsan", host = options()$rds$host,
port = options()$rds$port, user = options()$rds$user,
password = options()$rds$password)
# Construct the update query
query <- paste0('UPDATE plots SET `geom_plot`= ST_GeomFromText("POLYGON((',"",Coord(),"",'))") WHERE `parcel_id`=',"'", ID() ,"'",';')
query <- gsub('\"', "'", query)
# Submit the fetch query and disconnect
dbGetQuery(db, query)
dbDisconnect(db)
}