Logo

Overview

Schema

This image explains how Maptimize works. Your application uses Google Maps to display images maps (Map/Satellite) and uses Maptimize to display markers.
We need 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 Server API.
Then you need to add few line of JavaScript using our Client API as described below.

How to integrate Maptimize service (step by step)

Description Map

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

  1. Include Maptimize JavaScript file after Google Maps JavaScript file.
    <script src="http://maptimize.com/api/v1/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://maptimize.com/stylesheets/cluster.css" rel="stylesheet" type="text/css" />
  3. Attach your Google Map to Maptimize.
    var maptimizeMap = new Maptimize.Map(map); // map is a GMap2 object
    View full code

With only two lines of code, you have the Maptimize service on your map with default Maptimize behavior: When you click on a cluster, Maptimize 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 Maptimize.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 maptimizeMap = new Maptimize.Map(map, {
  onMarkerClicked: function(marker, id) {
    // marker: is an instance of Maptimize.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 Maptimize.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 maptimizeMap = new Maptimize.Map(map, {
  onMarkerClicked: function(marker, id) {
    // marker: is an instance of Maptimize.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 Maptimize service. Enjoy this unique readability !

View full code

Optional step : customize the design.

Maptimize 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.
In V1 version, we have introduced a map theme. A theme is a Javascript object that implements two methods:

  • createMarker: function(marker)
  • createCluster: function(cluster)
that returns a GOverlay.
To create your own design, just a create a theme object and set it in Maptimize.Map options. We use LabeledMarker library for cluster rendering (for having an string over an image). The class is embed in your javascript.
Later we will provide a vectorial library to creates rich cluster/marker design. Much more than what you can do today with PNG.

// Create my own theme using GIcon class, see Google Map documentation
var theme = {
  markerOptions: {icon: 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)                             
                            })},
  clusterOptions: {icon: new GIcon({ image:            "/images/maps.theme1/3.png",
                              iconSize:         new GSize(62, 62),
                              iconAnchor:       new GPoint(31, 31),
                              infoWindowAnchor: new GPoint(31, 31),
                              infoShadowAnchor: new GPoint(31, 31)                             
                             }),
                    labelClass: 'maptimize_cluster_0', 
                    labelOffset: new GSize(-24, -24)},
                             
  createMarker: function(marker) {
    return new GMarker(marker.getGLatLng(), theme.markerOptions);
  },

  createCluster: function(cluster) {
    var options = theme.clusterOptions;
    options.labelText = cluster.getCount();
    return new Maptimize.LabeledMarker(cluster.getGLatLng(), theme.clusterOptions);
  }
}

// Attach maptimize service
var maptimizeMap = new Maptimize.Map(map, {
  theme: theme,
  ...
});
View full code

View full code

Client Side API (JavaScript) - V1

Maptimize.Map Class

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

Function Description
Constructor
new Maptimize.Map(gmap, options)
Constructor of the main Maptimize Map object.
Parameters are:
gmap: Google Map object (GMap2 instance)
options: Hash map of options. Currently it's only 4 callbacks describe in above section "How to integrate Maptimize service"
isMaxZoom() Returns true if maximum zoom level is reached.
isZoomMax() Deprecated: use isMaxZoom instead. Returns true if maximum zoom level is reached.
getMarkers() Returns an Array of Maptimize.Marker/Maptimize.Cluster visible on the map.
getPointsCount() Returns numbers of points clustered on the map.
getMarkerCount() Deprecated: use getPointsCount instead. Returns numbers of points clustered on the map.
filterAnyLabels(labels) Request for clustering points having one of the given labels, then draws markers on the map.
When labels is the empty array, no marker are retrieved.
Parameters are:
labels: Array of integers representing labels.
filterAllLabels(labels) Request for clustering points having all given labels, then draws markers on the map.
When labels is the empty array, all markers are retreived.
Parameters are:
labels: Array of integers representing labels.
Maptimize.Marker Class
Function Description
getId() Returns your ID associated with this Maptimize marker.
getGLatLng() Returns a Google GLatLng object representing latitude/longitude of this Maptimize marker.
getGMarker() Returns a Google GMarker associated with this Maptimize marker.
setGMarker(gMarker) Set Google GMarker for this Maptimize marker. Use to change marker image.
hasLabel(label) Returns true if point represented by this marker has given label, false otherwise.
Parameters are:
label: Integer representing label.
getLabels() Returns an array of all labels attributed to the point represented by this marker.
Maptimize.Cluster Class
Function Description
getPointsCount() Returns number of markers included in the cluster.
getCount() Deprecated: use getPointsCount instead. Returns number of markers included in the cluster.
getGLatLngBounds() Returns a Google GLatLngBounds object representing area covered by the cluster.
zoomIn() Update center and zoom of the Google map to display all markers included in the cluster.
getPointsCountForLabel(label) Returns number of points clustered in this cluster having given label.
Parameters are:
label: Integer representing label.

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.maptimize.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.maptimize.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