Stuck with making a saved polyline editable again?

181 views
Skip to first unread message

123gotoandplay

unread,
Jun 4, 2013, 5:07:46 AM6/4/13
to google-map...@googlegroups.com
Hi,

I am bit stuck with making a saved polyline editable again. At the moment i have stored the points in a mysql database and i am able to show the route/polyline again with custom markers.

Now i like the polyline to be editable again and for this i was looking into:

Issues i have:
1/ i can't get the already saved points to be drag and drop
2/ i don't want the midmarkers, just the ability to move markers, add and delete markers

At the moment my startediting function looks like:

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');
                       }
                        
                }
        }

and function setmarkers looks like
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() {
                alert("lengte "+length);
                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;

        }


Any suggestions?

geoco...@gmail.com

unread,
Jun 4, 2013, 4:46:07 PM6/4/13
to Google Maps JavaScript API v3
On Jun 4, 2:07 am, 123gotoandplay <wesweatyous...@gmail.com> wrote:
> Hi,
>
> I am bit stuck with making a saved polyline editable again. At the moment i
> have stored the points in a mysql database and i am able to show the
> route/polyline again with custom markers.
>
> Now i like the polyline to be editable again and for this i was looking
> into:http://www.birdtheme.org/useful/v3tool.html
>
> Issues i have:
> 1/ i can't get the already saved points to be drag and drop

If you read and follow the posting guidelines and post a link to a map
that exhibits the problem you are asking about rather than an
unreadable code dump, you would stand a better chance of getting a
useful answer here. Or you could try posting your question on
stackoverflow, the "official" place for programming questions (they
like code rather than links there).

> 2/ i don't want the midmarkers, just the ability to move markers, add and
> delete markers

The DrawingManager does what the DrawingManager does (creates the
handles at that midpoints of the edges to let them be modified), if
you don't want that behavior, you will need to code the behavior you
want.

See this website for some options:
http://www.wolfpil.de

Here is one:
http://www.wolfpil.de/v3/flexible-polygon.html

-- Larry
Reply all
Reply to author
Forward
0 new messages