PDA

View Full Version : GoogleMap: Chage or add/remove Marker after map renderering?



parsbin
7 May 2011, 11:26 PM
Hi
Can i change or any control map`s marker in Gmap after map rendering by command(example: button)?
Please explain that.
I can`t find good documentation or topic related to this.

http://030.img98.net/out.php/i304775_marker.JPG

Thanks

friend
9 May 2011, 9:04 AM
There's lots of good info in Google Map's Javascript API docs:

http://code.google.com/apis/maps/documentation/javascript/controls.html

http://code.google.com/apis/maps/documentation/javascript/overlays.html#AddingOverlays
(http://code.google.com/apis/maps/documentation/javascript/overlays.html#AddingOverlays)

kaendsle
9 May 2011, 11:56 AM
If you are using the Ext.ux.GMapPanel or Ext.ux.GMapPanel3 extensions...

Assuming that myMapPanel is your GMapPanel instance you can do the following things:



var myMap = myMapPanel.getMap(); // Get the Map itself and use the Google Maps API directly
if (myMap.getZoom() < 10) {myMap.setZoom(12);} // Zoom in if the map is zoomed out too far
myMap.setCenter(new google.maps.LatLng(someLatitude, someLongitude)); // Center your map on a location
myMapPanel.hideMarkers(); // Hide (remove) all markers on the map
myMap.fitBounds(new google.maps.LatLngBounds(swCoords, neCoords)); // Fit your map extent to at least two markers
myMapPanel.addMarkers(arrayOfMarkers); // Add an Array of marker objects to your map


Marker objects should look something like this.


someMarker = {
marker: {
infoWindow: {
content: '' // Any text markup (HTML)
},
animation: google.maps.Animation.DROP // Add animation to your points!
},
lat: lat, // A Float latitude
lng: lng // A Float longitude
};
arrayOfMarkers.push(someMarker); // Add it to an array of markers to be added
myMapPanel.addMarkers(arrayOfMarkers);