参考示例改了代码,出现了以下问题:
1.这个随机点生成的位置并不在我指定的浮点数范围里,我想要能在我的地图范围中生成随机点这应该怎么修改。
2.只出现了maker,但是不能让这个maker在地图上生成真正的点并添加到我发布的rest数据服务中,这个是我发布的数据有什么问题的原因吗?
以下是我的代码:
function add(){
var xmax = 118.82349554, xmin = 118.80992062, ymax = 32.08487901, ymin = 32.07325265
var point = [];
if (!marker || !featureGroup.hasLayer(marker)) {
point = [
Math.floor(Math.random() * (ymax - ymin + 1) + ymin),
Math.floor(Math.random() * (xmax - xmin + 1) + xmin)
];
marker = L.circleMarker(point, {color: "blue"});
featureGroup.addLayer(marker);
featureGroup.addTo(map);
map.flyTo(point, 18);
} else {
featureGroup.clearLayers();
point = [
Math.floor(Math.random() * (ymax - ymin + 1) + ymin),
Math.floor(Math.random() * (xmax - xmin + 1) + xmin)
];
marker = L.circleMarker(point, {color: "blue"});
featureGroup.addLayer(marker);
featureGroup.addTo(map);
map.flyTo(point, 18);
}
if (marker && featureGroup.hasLayer(marker)) {
marker = marker.toGeoJSON();
marker.properties = {POP: 1, CAPITAL: 'test'};
var addFeatureParams = new L.supermap.EditFeaturesParameters({
dataSourceName: "siy",
dataSetName: "zwd",
features: marker,
editType: "add",
returnContent: true
});
featureService.editFeatures(addFeatureParams, function (serviceResult) {
if (serviceResult.result.succeed) {
featureGroup.clearLayers();
marker = null;
if (resultLayer) {
map.removeLayer(resultLayer);
resultLayer = null;
}
widgets.alert.showAlert(resources.msg_submitSuccess, true);
}
});
} else {
widgets.alert.showAlert(resources.msg_addMarker, false);
}
}