2014년 8월 8일 금요일

Instantiating Map Markers

Instantiating Map Markers

Add markers to a map by instantiating the google.maps.Marker() class as illustrated below:
 
  • code
  • source
Ext.define('MyApp.view.MyMap', {
 extend: 'Ext.Map',
 config: {
  mapOptions: {
   center: new google.maps.LatLng (38.909027,-77.037165),
   mapTypeId: google.maps.MapTypeId.ROADMAP,
   zoom: 15
  }
 },
 initialize: function() {
   var gMap = this.getMap();
   
   // add traffic layer
   var trafficLayer = new google.maps.TrafficLayer();
   trafficLayer.setMap(gMap);
   
   // add panoramio layer
   var panoramioLayer = new google.maps.panoramio.PanoramioLayer();
   panoramioLayer.setMap(gMap);
   
   // drop map marker
   var marker = new google.maps.Marker({
    map: gMap,
    animation: google.maps.Animation.DROP,
    position: new google.maps.LatLng (38.909027,-77.037165),
    icon: 'resources/images/jogging.png'
   });
 }
});

The following configuration properties are typically used to change marker behavior:
Config PropertyDescription
positionLatLng. Location of the marker (required)
mapMap. The Map on which to place the marker.
animationAnimation. The animation to play when the marker is added to the map. Valid options:
  • google.maps.Animation.BOUNCE
  • google.maps.Animation.DROP
draggableBoolean. If true, marker can be dragged.
iconstring|icon|symbol. The image to display for the marker.
visibleBoolean. Determines if the marker is displayed.

Removing Map Markers

Store references to all of your map markers in an array. Then you can simply loop through that array, invoking the marker.setMap(null) method in order to remove them from your map:
  • code
  • source
Ext.define('MyApp.view.MyMap', {
 extend: 'Ext.Map',
    
 mapMarkers : [], // store all markers
    
 config: {
  mapOptions: {
   center: new google.maps.LatLng (38.909027,-77.037165),
   mapTypeId: google.maps.MapTypeId.ROADMAP,
   zoom: 17
  }
 },
    
 // remove all markers
 clearMarkers: function() {
  for (var i=0; i<this.mapMarkers.length; i++) {
    this.mapMarkers[i].setMap(null);   
  }
  this.mapMarkers = new Array();
 },
    
 initialize: function() {
  var gMap = this.getMap();
  var trafficLayer = new google.maps.TrafficLayer();
  trafficLayer.setMap(gMap);
        
  var panoramioLayer = new google.maps.panoramio.PanoramioLayer();
  panoramioLayer.setMap(gMap);
        
  this.mapMarkers.push(
   new google.maps.Marker({
    map: gMap,
    animation: google.maps.Animation.DROP,
    position: new google.maps.LatLng (38.909027,-77.037165),
    icon: 'resources/images/jogging.png'
   })
  );
        
  // remove all markers after 5 seconds
  Ext.Function.defer(this.clearMarkers,5000,t

댓글 없음:

댓글 쓰기