javascript - 为什么我在活动中保存的信息会丢失
问题描述
早上好我正在尝试使用 Leaflet 绘制图像并保存数字,我创建了以下方法来启动地图:
initmap()
{
var url = 'http://kempe.net/images/newspaper-big.jpg';
var bounds = [[-26.5,-25], [1021.5,1023]];
var image = L.imageOverlay(url, bounds);
var map = new L.Map('image-map', {layers: [image], crs: L.CRS.Simple, minZoom : -5});
map.fitBounds(bounds);
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
position: 'topright',
draw: {
polyline: true,
polygon: false,
circle: false,
marker: true
},
edit: {
featureGroup: drawnItems,
remove: true
}
});
map.addControl(drawControl);
map.on(L.Draw.Event.CREATED, function (e) {
var type = e.layerType,
layer = e.layer;
if (type === 'marker') {
layer.bindPopup('A popup!');
}
drawnItems.addLayer(layer);
var type = e.layerType
var shape = layer.toGeoJSON()
var shape_to_json = JSON.stringify(shape);
this.currentMap = shape_to_json;
});
map.on(L.Draw.Event.EDITED, function (e) {
var layers = e.layers;
var countOfEditedLayers = 0;
layers.eachLayer(function (layer) {
countOfEditedLayers++;
});
});
}
正如您所看到的,当有人在绘图时,有一个事件定义,( map.on(L.Draw.Event.CREATED, function (e)
) 关键是我记录了该方法,并使用 console.log 检查保存的内容
this.currentMap = shape_to_json;
如你看到的:
shape_to_json
installations-management.component.ts:120 {"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[421.202413,315.527832],[421.202413,756.416626],[988.101415,756.416626],[988.101415,315.527832],[421.202413,315.527832]]]}}
一切似乎都很好。但是当我点击保存按钮时,this.currentMap的数据丢失了,并且没有其他任何地方被修改。那么,我是保存错误还是因为事件而在某处修改?谢谢你们 !
解决方案
推荐阅读
- c# - C# Google 存储客户端 - 上传文件 - 如果已存在则失败
- ios - URLSession 使用内部回调在回退时重试连接
- mysql - MySQL 将数据附加到 JSON 数组中的每个 JSON 对象
- javafx - Java FX 使用 fxml 文件创建自定义对话框。如何设置或从中获取结果?
- asp.net - 模态弹出表单验证在 onclick 函数中不起作用
- inno-setup - 如何根据 Inno Setup 中的 Windows 版本添加/不添加卸载程序的快捷方式?
- node.js - 在生产环境中使用socket.io?
- vue.js - axios使用vue请求跨域错误
- flutter - Flutter如何添加选择选项
- python - 在 Django 数据库模型中创建一个数组字段