Skip to main content

Marker Plugin

Easy To Integrate Maps & Location APIs & SDKs For Web & Mobile Applications

Powered with India's most comprehensive and robust mapping functionalities. Now Available for 200+ nations and territories accross the world.

Getting Access​

Before using the Plugin in the your solution, please ensure that the related access is enabled in the Mappls Console, in the same project you set up for the Maps SDK.

  1. Copy and paste the generated access token from your API keys available in the dashboard in the sample code for interactive map development.
    • This APIs follow OAuth2 based security.
    • Access Token can be generated using Token Generation API.
    • To know more on how to create your access tokens, please use our authorization API URL. More details available here
    • The access token is a valid by default for 24 hours from the time of generation. This can be configured by you in the API console.
  2. The sample codes are provided on our domain to help you understand the very basic functionality of Mappls Marker Plugin. See Sample Codes here

Introduction​

A simple plugin to render places on map as markers. The Marker plugin for Mappls Web Maps JS library is provided as a means to enable rendering of searched Places via eLoc as markers top of Mappls Maps.

The plugin can be used in combination with our Interactive Map JS libraries.

The SDK offers the following basic functionalities:

  1. Ability to render places directly using eLoc on Mappls Maps SDK.
  2. A Mappls.elocMarker() method to initiate rendering of Places on the map specified with eLoc(s) on the map.
  3. Ability to add listeners on marker events, remove markers, customize icons and get fitbounds of the markers.
  4. Ability to make markers draggable and add annotations (info popups + customizable popups).

Live Demo​

Visit the samples for assistance to create a sample implementation with your own keys.

The above implementation uses Mappls Interactive Map JS library as map rendering framework showcasing integration of marker plugin.

Implementation​

Adding the Marker plugin script​

Script URL​

<script src="https://apis.mappls.com/advancedmaps/api/{access_token}/map_sdk_plugins?v=3.0"></script>

Initializing the Marker plugin​

Method​

mappls.pinMarker()

/*marker plugin initialization*/
var markerOptions={
map:map,
pin:[β€˜mmi000’,’123zrr’],
popupHtml:[β€œ<h1>MMI</h1>”,”<h1>Agra</h1>”],
html:[β€œ1”,”2”],
icon:{url:’2.png’,width:30,height:45}
}

mappls.pinMarker(markerOptions,callback);

OR

mappls.pinMarker({map:map,pin:'mmi000',popupHtml="<h1>MMI</h1>"});

Mandatory Parameters​

  1. map: object > vector map or raster map object from respective Mappls Map JS.
  2. pin: array of strings containing the eLoc(s) which need to be showcased on the map. e.g.
    [β€˜mmi000’,’123zrrr’]

Optional Parameters​

  1. html: (string or html) Text which needs to be written over the marker or if there is a need for further customization, then this param can also take in HTML div.
    e.g.

    ```html
    'mappls'
    ```
    OR
    ```
    [β€œ<b>MMI</b>”,”<b>AGRA</b>”]
    ```
  2. popupHtml: (string or HTML) What needs to be displayed when marker is clicked.
    e.g.

    ```
    [β€œ<h1>Mappls</h1>”,”<p>Agra</p>”]
    ```
  3. popupOptions: (object) if the popup/annotation needs to be customized further. The following are the sub-params for the object:

    - `className`: the class name of the annotation object.
    - `offset`: the offset positioning from the marker.
    - `openPopup`: (boolean) indicating if the pop needs to be open on addition of marker or not as default.
    e.g.
    ```js
    {
    className:'myClass',
    offset:{},
    openPopup:true //open popup as default with add marker
    }
    ```
  4. icon: (object) the customized marker icon options. The following are the sub-params for the object:

    • url: the URL specifying the marker image.
    • width: width of the marker icon.
    • height: height of the marker icon.
    • offset: offset positioning of the marker's anchor.
    • popupAnchor: positioning of the marker popup's anchor.

    e.g.

    {
    url:'https://apis.mappls.com/map_v3/2.png',
    width:30,
    height:40,
    offset:[20,40],
    popupAnchor:[-5,-40]
    }
  5. draggable: (boolean) to set the marker(s) as draggable or not.

Method for getting all markers to fit in a viewbound​

Method​

fitbounds()

obj.fitbounds(options); //options are optional e.g. {padding:100}
  • padding: option can be used to setup a padding around the viewbound to fit the markers in.

Method for removing markers with callback​

Method​

remove()

obj.remove();

Method for adding event listeners on the marker​

Method​

addListener()

obj.addListener(event,callback);

Example:

obj.addListener(β€˜click’,function(data){console.log(data);});

Method for removing event listeners on the marker​

Method​

removeListener()

obj.removeListener(event);

Example:

obj.removeListener(β€˜click’);

Method for setting icons for markers​

Method​

setIcon()

obj.setIcon(β€˜url.png’); //replaces all marker's icon.

OR

obj.setIcon(β€˜url.png’,’mmi000’); //replaces single marker's icon for the provided eLoc.

Method for setting pophtml for markers​

Method​

setPopup()

obj.setPopup({content:"<h1>Mappls</h1>"}); //replaces all marker's pop up values.

OR

obj.setPopup({content:"<h1>Agra</h1>",pin:'123zrr'}); //replaces single marker's popup value for the provided Pin.