deleting multiple polylines using mvcArray

465 views
Skip to first unread message

Marcvp

unread,
Sep 28, 2010, 10:24:24 AM9/28/10
to Google Maps JavaScript API v3
Hi,

I need help with the mvcArray.I'm making for practise a map where
flights available between cities are shown when you put the mouse over
one city marker. So I'm creating some polylines at the "same time" on
my map triggered by an mouseover event. I'm creating the polylines
with this function below:

The lato and lono are the origin cordinates (always the same, the
cordinates of the city marker you are hovering.
The latd and lond are the destiny cordinates (which change according
to the diferrent available destiny cities).

function createLine(lato,lono,latd,lond) {
flightPath = new google.maps.Polyline({
path: [new google.maps.LatLng(lato, lono), new
google.maps.LatLng(latd, lond)],
strokeColor: "#FF0000",
strokeOpacity: 0.5,
strokeWeight: 4
});
flightPath.setMap(map1);
}

So various polylines are created fine when I do my hover. But they
don't disapear when I mouseout. My question is: how can I use the
mvcArray to remove those polylines? After looking at the tutorials at
"code.google" I've seen something it may help:
- mvcArray.getAt(i).removeAt()

Then I tried on my code:

google.maps.event.addListener(cityMarker, 'mouseout', function() {
mvcArray.getAt(1).removeAt(); // the 1 is to try the
array(which has more than 2 polylines)
}

I tought all the polylines where collected by that mvcArray, but when
I call it, firebug tells me it's not defined. So, I may have to define
it, how can I do it correctly?

Thanks!

geoco...@gmail.com

unread,
Sep 28, 2010, 5:00:19 PM9/28/10
to Google Maps JavaScript API v3
On Sep 28, 7:24 am, Marcvp <marcvp1...@gmail.com> wrote:
> Hi,
>
> I need help with the mvcArray.I'm making for practise a map where
> flights available between cities are shown when you put the mouse over
> one city marker. So I'm creating some polylines at the "same time" on
> my map triggered by an mouseover event. I'm creating the polylines
> with this function below:
>
> The lato and lono are the origin cordinates (always the same, the
> cordinates of the city marker you are hovering.
> The latd and lond are the destiny cordinates (which change according
> to the diferrent available destiny cities).
>
> function createLine(lato,lono,latd,lond) {
>                                 flightPath = new google.maps.Polyline({
>                                         path: [new google.maps.LatLng(lato, lono), new
> google.maps.LatLng(latd, lond)],
>                                         strokeColor: "#FF0000",
>                                         strokeOpacity: 0.5,
>                                         strokeWeight: 4
>                                 });
>                                 flightPath.setMap(map1);
>                         }

How about flightPath.setMap(null)?
(you probably will need to keep references to _all_ the polylines, not
just the last one)

-- Larry

Nathan Raley

unread,
Sep 28, 2010, 5:12:35 PM9/28/10
to google-map...@googlegroups.com
Yea, I was going to recommend what Larry recommended.  Your best off just removing the polylines from the map itself.

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Reply all
Reply to author
Forward
0 new messages