1. Home >
  2. Documentation >
  3. Misc >
  4. get
 

get

This function retrieves an object or a list of objects.

Usage

Explanation

Each time a function is called to create a google map object, objects and parameters are stored in an internal storage. This function allows you to retrieve theses objects in order to use their methods.

Objects can be retrieved thanks to either their ids (user specified or automatically generated), their storage name (marker, rectangle, ...) or their tags.

Parameters

  • all {bool} Returns an array containing each object filtered (optional)
  • first {bool} Returns the first object added (optional)
  • full {bool} The return contains either the simple google object or the object with its user properties (optional) (default=false)
  • id {string|array of string} Filter on object id (optional)
  • last {bool} Return the last object added (optional) (default)
  • name {string|array of string} Filter on object name (map, marker, rectangle, ...) (optional)
  • tag {function(tag):bool|string|array of string} Filter on user tag (optional)

Note

  • By default, this function targets the last object created, even if the only filter property is tag. Use "all" to get all objects
  • If name or id are an array of values, result is an array
  • if id is defined, name is ignored
  • if full is true, each result embeds the following data
    • object {object} The google object
    • id {string} The object id
    • name {string} The object name
    • tag {mixed} The tag property
    • data {mixed} The data property

Example

$(function(){
  $("#test").gmap3({
    map:{
      options:{
        center:[46.578498,2.457275],
        zoom: 5
      }
    },
    marker:{
      values:[
        {latLng: [48.8620722, 2.352047], tag:"green"},
        {latLng: [46.59433,0.342236], tag:"green"},
        [42.704931, 2.894697],
      ]
    }
  });
  setTimeout(function(){
    $("#test").gmap3({
      get: {
        name:"marker",
        tag: "green",
        all: true,
        callback: function(objs){
          $.each(objs, function(i, obj){
            obj.setIcon("http://maps.google.com/mapfiles/marker_green.png");
          });
        }
      }
    });
  }, 2000);
  
  setTimeout(function(){
    $("#test").gmap3({
      get: {
        name:"marker",
        callback: function(marker){
          marker.setIcon("http://maps.google.com/mapfiles/marker_purple.png");
        }
      }
    });
  }, 3000);
});

Direct get

Explanation

get can be used synchronously if it is the only key of the request and if it doesn't have a callback.

Note

  • if a single string is set to get, get will first search an object with the corresponding id before using it as a name
  • if no parameters are set, get will return the map

Example

$(function(){
  $("#test").gmap3({
    map:{
      options:{
        center:[46.578498,2.457275],
        zoom: 5
      }
    },
    marker:{
      values:[
        {latLng: [48.8620722, 2.352047], tag:"green"},
        {latLng: [46.59433,0.342236], tag:"green"},
        [42.704931, 2.894697],
      ]
    }
  });
  
  // direct call to get all markers with a tag
  setTimeout(function(){
    var markers = $("#test").gmap3({
      get: {
        name:"marker",
        tag: "green",
        all: true
      }
    });
    
    $.each(markers, function(i, marker){
      marker.setIcon("http://maps.google.com/mapfiles/marker_green.png");
    });
  }, 2000);
  
  // direct call using default parameters
  setTimeout(function(){
    var marker = $("#test").gmap3({get:"marker"});
    var map = $("#test").gmap3("get");
    
    marker.setIcon("http://maps.google.com/mapfiles/marker_purple.png");
    map.panTo(marker.getPosition());
    
  }, 3000);
});
Close