Logo

Overview

Schema

This image explains how Mapeed works. Your application uses Google Maps to display images maps (Map/Satellite) and uses Mapeed to display markers.
We need to have to have all POI coordinates (latitude/longitude) on our servers to perform our fast clustering algorithm.
So you need to synchronize your data using our web interface or web API.
Then you need to add few line of JavaScript using our API as describe below.

How to integrate Mapeed plugin (step by step)

Description Map

The simplest javascript code to display markers and clusters using Mapeed.

  1. Include Mapeed JavaScript file after Google Maps JavaScript file.
    <script src="http://mapeed.com/api/beta/MAP_KEY/embed.js" type="text/javascript"></script>
    You will find your MAP_KEY in your dashboard when you are logged in.
  2. Include our CSS to handle default markers and clusters design.
    <link href="http://mapeed.com/stylesheets/cluster.css" rel="stylesheet" type="text/css" />
  3. Attach your Google Map to Mapeed.
    var mapeedMap = new Mapeed.Map(map); // map is a GMap2 object
    View full code

With only two lines of code, you have the Mapeed plugin on your map with default Mapeed behavior: When you click on a cluster, Mapeed adapts zoom and position of the to display cluster content.

Now, let's see how we can bind a behavior on the click event.

View full code

How to bind actions on click for clusters and markers.

There are two callbacks on Mapeed.Map object called when a user clicks on a marker or a cluster when zoom in is not possible anymore (markers at the same address).

Those callbasks are :

  • onMarkerClicked(marker)
  • onZoomMaxClusterClicked(cluster)

Here is how to use them to open an infoWindow :

var mapeedMap = new Mapeed.Map(map, {
  onMarkerClicked: function(marker, id) {
    // marker: is an instance of Mapeed.Marker
    // id:     is the id you set for this marker in your CSV file
    marker.getGMarker().openInfoWindowHtml('ID = ' + id);
  },
  onZoomMaxClusterClicked: function(cluster, ids) {
    // cluster: is an instance of Mapeed.Cluster
    // ids:     is an Array of all ids you set in your CSV file that are included in this cluster
    cluster.getGMarker().openInfoWindowHtml('IDS = ' + ids);
  }
});
View full code

Now, your map is interactive. Let's see how to customize window's content.

View full code

Set info window content by Ajax.

Actions are the same as the example above but it runs an Ajax request to get window content.
Info window will be open after receiving server response.

The code is based on Prototype JavaScript Framework but can be done with any JavaScript framework.

var mapeedMap = new Mapeed.Map(map, {
  onMarkerClicked: function(marker, id) {
    // marker: is an instance of Mapeed.Marker
    // id:     is the id you set for this marker in your CSV file
  
    // Use Ajax.Request prototype Object (you can use any JS framework)
    // Set id as parameter of the request. 
    // Open info window with response as content when receive response
    return new Ajax.Request("/api_ajax_content/", {
      method: 'GET',
      parameters: {id: id},
      onComplete: function(response) {
        marker.getGMarker().openInfoWindowHtml(response.responseText);
      }
    });
  },
  onZoomMaxClusterClicked: function(cluster, ids) {
    // ...
  }
});
View full code

Well done ! Your map is now enhanced by the Mapeed plugin. Enjoy this unique readability !

View full code

Optional step : customize the design.

Mapeed provides default images for markers and clusters as you can see on our demos.
Of course, you can change them exactly as you would do with Google Maps.
To be able to change them, you need to use callbacks onMarkerReceived/onClusterReceived.
Those callbacks are called before creating GMarker (Google Marker) and let you create your own GMarker.

var myMarker = new GIcon({ image:            "/images/maps.theme1/marker-pink.png",
                           iconSize:         new GSize(20, 30),
                           iconAnchor:       new GPoint(10, 30),
                           infoWindowAnchor: new GPoint(10, 10),
                           infoShadowAnchor: new GPoint(10, 30)                             
                          });

var mapeedMap = new Mapeed.Map(map, {
  onMarkerReceived: function(marker) {
    marker.createGMarker({ icon : myMarker });
    // You can also bind any Google Map event on the GMarker like this
    // GEvent.bind(marker.getGMarker(), "click", this, function() {...});
    // 
    // http://code.google.com/apis/maps/documentation/reference.html
  },  
});
View full code

View full code

Client Side API (JavaScript)

Mapeed.Map Class

The Mapeed plugin gives you the ability to trigger server-side operations, by simply invoke some javascript methods on the Mapeed JS Classes.

Function Description
Constructor
new Mapeed.Map(gmap, options)
Constructeur of the main Mapeed object.
Paramters are:
gmap: Google map object (GMap2 class)
options: Hash map of options. Currently it's only 4 callbacks describe in above section "How to integrate Mapeed plugin"
isZoomMax() Returns true if map cannot be zoom in
getMarkers() Returns an Array of Mapeed.Marker/Mapeed.Cluster visible on the map.
getMarkerCount() Returns numbers of markers visible on the map.
getMarkerForId(id, function(marker)) Returns marker (or cluster) visible on the map for an specific id. Callback is called after marker search. marker parameter is false if not found.
Mapeed.Marker Class
Function Description
getId() Returns your ID associated with this Mapeed marker.
getGLatLng() Returns a google GLatLng object representing latitude/longitude of this Mapeed marker.
getGMarker() Returns a google GMarker associated with this Mapeed marker.
setGMarker(gMarker) Set GMarker (google marker) for this Mapeed marker. Use to change marker image.
Mapeed.Cluster Class
Function Description
getCount() Returns number of markers included in the cluster.
getGLatLngBounds() Returns a google GLatLngBounds object representing area covered by the cluster.
zoomIn(gMap) gmap: Google map object (GMap2 class)
Update center and zoom of the google map to display all markers included in the cluster.

How to upload to your personal datastore.

Using our web interface

After having created your account, you will be able to log in to manage your account.
On the tab "My map", you will be able to upload tour CSV file. The result will appear after our processing.

Using our web service

Markers can be sent by HTTP using our API with HTTP authentication

Authenticating is done with an authentication token. You will get it on your dashboard when you are logged in.

You have to use this token as login and just X as password.

URL is to post your file is like this: http://www.mapeed.com/api/beta/YOUR_MAP_KEY/import
YOUR_MAP_KEY is also available on your dashboard page. You have two keys, one for your production map, one for you development map.

If your plan supports https, you can use https instead of http to use this upload API.

A complete curl command:

curl -u YOUR_AUTHENTICATION_TOKEN:X -X PUT http://www.mapeed.com/api/beta/YOUR_MAP_KEY/import -T YOUR_CSV_FILE -H 'Content-Type: text/csv'

You can inspect reponse header ad body (add -v to curl command to get request/response content)

Description Status Response Body
Import succeeded 200 OK
<?xml version="1.0" encoding="UTF-8"?>
<import>
  <status>succeeded</status>
</import>
Import failed because an import is already scheduled or running 409 Conflict
<?xml version="1.0" encoding="UTF-8"?>
<import>
  <status>failed</status>
  <message>
    an import is already scheduled or running
  </message>
</import>
Import failed because have reached number of uploads per hour or per day according to your plan. 409 Conflict
<?xml version="1.0" encoding="UTF-8"?>
<import>
  <status>failed</status>
  <message>
    next available import in XX mn
  </message>
</import>


Development Xilinus | Design Webalys