我有点担心再次保存折线可编辑。目前我已将点存储在mysql数据库中,并且我能够使用自定义标记再次显示路径/折线。
现在我喜欢折线再次可编辑,为此我正在研究: http://www.birdtheme.org/useful/v3tool.html
我有的问题:
目前我的启动功能如下:
function startEditing(){
if(editing === true){
stopediting();
}else{
routeCoords = theRoute.getPath();
//remove custom icons
//setAllMap(null);
if(routeCoords.length > 0){
for(var i = 0; i < routeCoords.length; i++) {
var marker = setmarkers(routeCoords.getAt(i));
//alert("marker: "+marker);
markers.push(marker);
/*if(i > 0) {
var midmarker = setmidmarkers(routeCoords.getAt(i));
midmarkers.push(midmarker);
}*/
}
editing = true;
jQuery('#btnEditing').removeClass('green');
jQuery('#btnEditing').val('Stop Editing').addClass('red');
}
}
}
和函数setmarkers看起来像
function setmarkers(point){
var marker = new google.maps.Marker({
position: point,
map: map,
icon: imageNormal,
raiseOnDrag: false,
draggable: true
});
google.maps.event.addListener(marker, "mouseover", function() {
marker.setIcon(imageHover);
});
google.maps.event.addListener(marker, "mouseout", function() {
marker.setIcon(imageNormal);
});
google.maps.event.addListener(marker, "drag", function() {
for (var i = 0; i < markers.length; i++) {
if (markers[i] === marker) {
theRoute.getPath().setAt(i, marker.getPosition());
movemidmarker(i);
//movemarker(i);
break;
}
}
routeCoords = theRoute.getPath();
var stringtobesaved = marker.getPosition().lat().toFixed(6) + ',' + marker.getPosition().lng().toFixed(6);
pointsArray.splice(i,1,stringtobesaved);
});
////#end markers van DB
google.maps.event.addListener(marker, "click", function() {
for (var i = 0; i < markers.length; i++) {
if (markers[i] === marker && markers.length !== 1) {
marker.setMap(null);
markers.splice(i, 1);
theRoute.getPath().removeAt(i);
removemidmarker(i);
break;
}
}
routeCoords = theRoute.getPath();
if(markers.length > 0) {
pointsArray.splice(i,1);
}
});
return marker;
}
有什么建议吗?
答案 0 :(得分:1)
使几何图形可编辑的最简单方法是设置属性editable: true
。当您希望可以编辑形状时,可以快速迭代矢量图层中的每个几何体(点,多边形等)并设置editable = true。请查看此处的示例https://developers.google.com/maps/documentation/javascript/examples/user-editable-shapes
另一个例子here
这会给你那些盒子/锚点,以后你可以简单地在每个geomtery上将editable设置为false。
要拖动标记,请查看here。 的段强>
// Update current position info.
updateMarkerPosition(latLng);
geocodePosition(latLng);
// Add dragging event listeners.
google.maps.event.addListener(marker, 'dragstart', function() {
updateMarkerAddress('Dragging...');
});
google.maps.event.addListener(marker, 'drag', function() {
updateMarkerStatus('Dragging...');
updateMarkerPosition(marker.getPosition());
});
google.maps.event.addListener(marker, 'dragend', function() {
updateMarkerStatus('Drag ended');
geocodePosition(marker.getPosition());
});