API

Javascript API

/ Getting Started with the MapLarge Javascript API

Content

Getting Started

The MapLarge Javascript API is a client side library used to create maps and layers. The API interacts with MapLarge web services and runs on top of many other mapping APIs including Google Maps, Leaflet, and ESRI.

Simple Getting Started Example

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="http://my.maplarge.com/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function() {
  6. var map = ml.map("mapDiv");
  7. });
  8. </script>
  9. </head>
  10. <body>
  11. <div id="mapDiv" style="width:100%;height:100%;"></div>
  12. </body>
  13. </html>

Loading the MapLarge API

To load the MapLarge API, simply include the MapLarge javascript file.

In the script tag is a URL with the location of the file that contains the MapLarge JS API. This script tag is required.

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="http://my.maplarge.com/JS"></script>
  4.  

Note: If directed to a specific MapLarge server, specify it in the URL.

Creating JSON with Map Editor

Almost all MapLarge API calls can also be configured without coding by using the advanced MapEditor.

Use MapEditor to create and edit maps and layers or for capturing code snippets for use in custom JavaScript.

Open MapEditor by adding ?showeditor=true to the map URL. MapEditor can also be opened by pressing CTRL + BACKSPACE.

Note: Replace my.maplarge.com with your server if hosted in another location.

The JSON object shown in the Map or Layer JSON editor is simply a valid options object that may be passed into the constructor for a map or layer.The Map JSON Includes attributes including the basemap, zoom level, map center position and all included Layers. The Layer JSON only includes JSON relevant to that specific layer.Access the JSON by pressing the View/Edit JSON button on a Map or Layer in MapEditor.

Creating a Map

This example shows how to create a map with a specific latitude, longitude, and zoom. The map object is used in the examples below. More details about map options can be found here.

Creating a Map Example

  1. <script type="text/javascript" src="/JS"></script>
  2. <script type="text/javascript">
  3. //ml.onload only runs after DOM is loaded
  4. ml.onload(function() {
  5.  
  6. //DOM element where map will be craeted
  7. var divID = 'mapDiv';
  8.  
  9. //Map options
  10. var options = {
  11. lat: 33.709,
  12. lng: -84.404,
  13. z: 9
  14. };
  15.  
  16. //Create the map
  17. var map = new ml.map(divID, options);
  18. });
  19. </script>
  20. <body>
  21. <div id="mapDiv" style="width:100%;height:100%;"></div>
  22. </body>

Example Map

Creating a Layer

Layers also have their own set of options, similar to maps. This example creates a dot layer from the table "hms/hotels".

Creating a Layer Example

  1. //Configure the data the layer will visualize
  2. var layerOptions = {
  3. "query": {
  4. "select": {
  5. "type": "geo.dot"
  6. },
  7. "where": [],
  8. "table": {
  9. "name": "hms/hotels"
  10. }
  11. }
  12. };
  13.  
  14. //Add the layer to your map
  15. var layer = new ml.layer(map, layerOptions);
  16.  
  17. //Show the layer
  18. layer.show();

Example Map

Filtering Layer Data

This is the same layer object but now filtering options have been added. This layer will only show hotels with a cost less than $50.

Learn more about the MapLarge Where Clause.

Creating a Layer with Filtering

  1. var layerOptions = {
  2. "query": {
  3. "select": {
  4. "type": "geo.dot"
  5. },
  6. "where": [
  7. [{
  8. "col": "LowRate",
  9. "test": "Less",
  10. "value": "50"
  11. }]
  12. ],
  13. "table": {
  14. "name": "hms/hotels"
  15. }
  16. }
  17. };
  18.  
  19. //Add the layer to your map
  20. var layer = new ml.layer(map, layerOptions);
  21.  
  22. //Show the layer
  23. layer.show();

Example Map

Styling Layer Data

Styling options can be added to a layer. This example shows hotels under $100 as red points and hotels over $100 as blue points.

Styling Data Example

  1. "style": {
  2. "borderColorOffset": "75",
  3. "dropShadow": "false",
  4. "fillColor": "255-0-127-255",
  5. "height": "8",
  6. "shape": "round",
  7. "width": "8"
  8. },
  9. "where": [
  10. [
  11. {
  12. "col": "LowRate",
  13. "test": "Greater",
  14. "value": "100"
  15. }
  16. ]
  17. ]
  18. },
  19. {
  20. "style": {
  21. "borderColorOffset": "75",
  22. "dropShadow": "false",
  23. "fillColor": "255-255-0-0",
  24. "height": "8",
  25. "shape": "round",
  26. "width": "8"
  27. },
  28. "where": [
  29. [
  30. {
  31. "col": "LowRate",
  32. "test": "LessOR",
  33. "value": "100"
  34. }
  35. ]
  36. ]
  37. }
  38. ],
  39. "colorTransform": {
  40. "alpha": 1
  41. }
  42. },

Example Map

Complete Code Example with Filters and Styles

More Examples

Looking at examples is a great way to get more comfortable with what is possible with our API. You can press ctrl + M on any of these example maps to open up Map Editor so you can look at the JSON that was used to create that map.

Maps

/ Maps - Quick Start

Map Container

Each map is contained within a div (or other block level element) on the page.

<div id="mapDiv" style="width: 500px; height: 400px"></div>

Note: Width and height must be set for the container because the map object itself has no minimum width or height and will stretch to fill the container. When a container has no width or height the map will not appear.

Map Object

A map object is the data object that controls all the properties of a displayable map, including starting locations, zoom levels, rendering options, underlaying map tiles, and more.

The first parameter can either be an ID or DOM element. The second parameter is a map's options object.

var map = new ml.map('divID', { lat: 33.70606265, lng: -84.4171367, z: 10, api: 'LEAFLET’ });

Create Javascript map object and pass to the div element.

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function() {
  6. var map = new ml.map('mapDiv', { lat: 33.709, lng: -84.404, z: 9 });
  7. });
  8. </script>
  9. </head>
  10. <body>
  11. <div id="mapDiv" style="width:100%;height:100%;"></div>
  12. </body>
  13. </html>

Example Map

Note: If the map container element is being created statically on the page then using a div is not necessary. Use the following to create the actual map data object:

document.getElementById('yourMapDivID')

Basemaps

MapLarge is drop in compatible with other mapping providers. If no API is defined in the map options, the default basemap is Leaflet. Each API has various baselayer options. For example, Leaflet provides the baselayers:

Color
OSM Dark
Blue Marble
Aerial
Satellite
Blank (white)

var map = new ml.map('mapDiv', { lat: 33.70606265, lng: -84.4171367, z: 10, api: 'LEAFLET', baseLayer: 'color' });

Creating a Map Example

Accessing the Underlying Mapping API

In addition to the options provided by the MapLarge Map object, the underlying mapping provider API options and features are also available (Google, Leaflet, or ESRI). These can be referenced by using map.getInternalMap().

  1. //create a MapLarge map which uses the ESRI API
  2. var mlmap = ml.map(div,{ api:'ESRI' });
  3. //return the internal ESRI map object
  4. var esrimap = mlmap.getInternalMap();

Alternative Advanced Constructor

The MapLarge API can also attach to a Google or other map that already exists on the page.
//maplarge.com/googlemapsapi.

Maps

/ Map Constructor Options

Each map is contained within a div (or other block level element) on the page.

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="http://my.maplarge.com/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function() {
  6. var map = ml.map("mapDiv");
  7. });
  8. </script>
  9. </head>
  10. <body>
  11. <div id="mapDiv" style="width:100%;height:100%;"></div>
  12. </body>
  13. </html>

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Maps - Quick Start

Mapping Platform for Big Data Visualization, Analytics & Publishing