UGC Techdocs
  • Introduction
  • Guides
    • Analytics
      • Tracking UGC on Adobe Analytics
      • Tracking Widget interactions with Google Analytics
    • Direct Uploader
      • How to add Custom Data to Direct Uploader
      • How to capture Custom Data on Direct Uploader
      • How to automatically tag data on Direct Uploader
      • How to Customize error messages on Direct Uploader
      • How to Track Direct Uploader form submissions with Google Analytics (Universal & GA 4)
    • Data Templates
      • Creating a Data Template
    • Rights via Registration
      • Capture Custom Data on Rights by Registration Form
      • Styling Rights via Registration Form
    • REST API
      • Caching REST API results for optimization
      • Posting content into Nosto via Tile API
      • Posting images into Nosto via Tile API
    • Onsite Widgets (2.0)
      • Blank Canvas
        • How to Use the Blank Canvas to Create a Twitter Count Widget
        • Creating an Auto-Scrolling Carousel using Blank Canvas
        • Creating Gallery Widget by Using the Blank Canvas Widget
        • Creating a simple Hover effect using Blank Canvas
        • Creating a Word Cloud using Blank Canvas
        • Creating Your Widget by Using the Blank Canvas
      • Bind your own Events
      • Creating a Grid Widget from Waterfall
      • Create a Q&A Widget using Data Templates
      • Displaying a Widget in a Mobile App
      • Dynamically Specify Products to Display in Widget
      • Dynamically specify what Tile to display in a Widget
      • How to add a title / subtitle to a widget
      • How to localize the load more button on widgets
      • How to overlay existing Google Map with the UGC Map Widget
      • Styling cross-sellers on Grid and Carousel Widgets
      • How to Load External JS and CSS into Widgets
      • Profiling Widget Performance
      • Re-targeting with Widgets and Facebook Pixel
      • Render Widget filters dynamically
      • Styling Carousel Widget
      • Styling Grid Widget
      • Styling Masonry Widget
      • Styling Waterfall Widget
      • Styling Widget Expanded Tile
      • Styling Widget Shopspots
      • Using Web Fonts in Widgets
    • Digital Screens
      • Customizing Carousel Event Screen
      • Customizing Mosaic Event Screen
      • Customizing Scrollwall Event Screen
      • Customizing the Mosaic Event Screen to Have 9 Even Tiles
    • Email
      • Adding Location to an Email Tile
      • Styling the Email Widget
    • Integrations
      • DoubleClick
        • UGC Ads with Nosto and Google DoubleClick
      • Zapier
        • Consuming UGC Webhooks via Zapier
      • Mailchimp
        • Bring Social Content into a Mailchimp Campaign
    • Webhooks
      • Trigger notifications when content is in the moderation queue
  • Widgets
  • API Docs
    • JavaScript API
      • Widgets
        • Introduction
        • API Reference for Content Widgets
        • API Reference for Blank Canvas
        • API Reference for Map Widget
      • Digital Screens
        • Introduction
        • API Reference
    • Content API
      • Reference
    • REST API
      • Reference
        • Filters API
        • Moderation Views API
        • Tags API
        • Terms API
        • Tiles API
        • Users API
        • Widgets API
        • Automation Rules API
        • REST API Reference Widgets style and config
      • Best Practices
    • Webhooks
  • Enterprise Tools
    • Automation Rules
      • Triggers
      • Actions
      • Samples
    • Data Templates
    • User Access Control (UAC)
    • Single Sign On (SSO)
    • Enterprise Admin User Interface (EAUI)
    • Zapier
  • Commerce Tools
    • Product Feeds
    • Widget Implementation
    • Reporting
    • Integrations
      • Google Tag Manager
      • Magento
      • SalesForce Commerce Cloud
      • Shopify
      • Shopify Add To Cart
        • Global Variant Mapping for Add to Cart
        • Customise Add to Cart Widget Experience
  • Analytics
    • Google Analytics 4
      • Getting Started
      • Widgets Events
      • E-commerce Events
      • Email Events
  • Terms of Use
Powered by GitBook
On this page
  • Background
  • Geohash
  • Execution flows
  • Methods
  • .initialize(options)
  • .createMap()
  • .createLayer(style)
  • .handleMarkerClick(event
  • .handleMoveEnd()
  • .createMarkerBySummary(summary)
  • .on(eventName, handler)
  • .getAggregatedDataByBounds(sw, ne, numGeohashPerView)
  • Exported methods
  • .getAggregatedDataByBounds(sw, ne, numGeohashPerView)
  • Customization examples
  • Add logic before/after map widget starts.
  • Initialize Leaflet with custom options
  • Use a different map layer (e.g. Google Maps)

Was this helpful?

  1. API Docs
  2. JavaScript API
  3. Widgets

API Reference for Map Widget

JavaScript API for Map Widget

PreviousAPI Reference for Blank CanvasNextDigital Screens

Was this helpful?

Background

The Map plugin’s purpose is to provide a visualization of where content is happening. This adds value when the location of content is as important as the content itself.

  • The Mapping Widget overlays geo-filtered content as Pins on a map;

  • The user sets the initial viewing area

  • The user can choose from various mapping providers – Google Maps, Mapzen, CartoDB and OpenStreetMap

  • They can customize the appearance of the Map based on which provider they choose

  • Each Pin reflects a Tile or a cluster (group) of Tiles

  • The Pin size is relative to the cluster size. The bigger the Pin, the more content that it represents.

  • The user can zoom in and out on the map to see a more refined location of the Pins

Geohash

Tiles in the Maps Widget are grouped into clusters using Geohash. Geohash is a string representation of coordinates.

Geohash is a geocoding system invented by Gustavo Niemeyer and placed into the public domain. It is a hierarchical spatial data structure which subdivides space into buckets of grid shape, which is one of the many applications of what is known as a Z-order curve, and generally space-filling curves.

Execution flows

Map widget creation

  1. MapWidget is created. var widget = new MapWidget()

  2. Custom JS code is executed // custom javascript

  3. The widget is initialized. widget.initialize()

    1. Leaflet map is created. var map = widget.createMap()

    2. Map layer is created. map.setLayer(widget.createLayer())

On map move

  1. On move, the end is called. widget.handleMoveEnd()

    1. Get all tile summaries for the current visible area. var summaries = widget.getAggregatedDataByBounds()

    2. Render the fetched summaries. widget.renderSummaries(summaries)

On marker clicked

  1. On marker, click is called. widget.handleMarkerClick()

Methods

.initialize(options)

Initialize the map widget.

Parameters

Name
Type
Description

options

`Object`

Options

Return Promise A promise that resolves when initialization completes.

.createMap()

Creates a Leaflet Map object.

Return L.Map The created map object.

.createLayer(style)

Creates a Leaflet Map object.

Parameters

Name
Type
Description

style

`Object`

Style object

Return L.Layer The created map object.

.handleMarkerClick(event

Parameters

Name
Type
Description

event

`Event`

Click event

Return void

Example usage

widget.handleMarkerClick = function (event) {
    var $dom = $(event.originalEvent.target);
    // do something

    // call parent method (optional)
    Widget.prototype.handleMarkerClick.call(widget, event);
};

.handleMoveEnd()

Handles map panning, resizing and zooming.

Return void

.createMarkerBySummary(summary)

Creates a Leaflet Map object.

Parameters

Name
Type
Description

summary

geohash:String,––
quantity:Integer,
avg_location:{
    longitude:Float,
    latitude:Float
}

} | Summary object |

Return L.Marker The marker object.

.on(eventName, handler)

Listens to an event.

Parameters

Name
Type
Description

eventName

`String`

Event name

handler

`Function(data:Object):void`

A handler function

Return MapWidget The current map widget object.

Example usage

// Event 'marker:click' might not emit if handleMoveEnd() or handleMarkerClick() is overrode.
widget.on('marker:click', function (summary) {
    console.log('Geohash: ' + summary.geohash);
    console.log('Quantity: ' + summary.quantity);
    console.log('Average longitude: ' + summary.avg_location.longitude);
    console.log('Average latitude: ' + summary.avg_location.latitude);
});

.getAggregatedDataByBounds(sw, ne, numGeohashPerView)

Listens to an event.

Parameters

Name
Type
Description

sw

`{lat:Float, lng:Float}`

South west coordinates

ne

`{lat:Float, lng:Float}`

North east coordinates

numGeohashPerView

`Integer`

(Optional) Max number of geohashes to generate in the given view. Default: `32`

Return Promise<Summary[]> A promise that resolves to summaries.

Exported methods

Exported methods can be called in parent window.

.getAggregatedDataByBounds(sw, ne, numGeohashPerView)

Example usage (own Google Maps)

    var map; // Google Map instance
    // get the map widget by ID
    var mapWidget = Stackla.WidgetManager.getWidgetInstanceByWidgetId(1234);
    map.addListener('bounds_changed', function () {
        var bounds = map.getBounds();
        var sw = bounds.getSouthWest();
        var ne = bounds.getNorthEast();
        mapWidget.getAggregatedDataByBounds(
            {lat: sw.lat(), lng: sw.lng()},
            {lat: ne.lat(), lng: ne.lng()},
            16
        ).then(function (summaries) {
    
        }).catch(function (ex) {
            console.error(ex);
        });
    });

Customization examples

Add logic before/after map widget starts.

widget.initialize = function (options) {
        (new Promise(function (resolve, reject) {
            try {
                // perform necessary options before widget initialization starts.
                // ...
                // ...

                // at the end, call resolve()
                resolve();
            } catch (ex) {
                reject(ex);
            }
        }).then(function () {
            return MapWidget.prototype.initialize.call(widget, options);
        }).then(function () {
            // then perform actions after widget initialization is completed.
        }).catch(function (ex) {
            // catch error/exception
            console.error(ex);
        });
    };

Initialize Leaflet with custom options

// Leaflet options @see http://leafletjs.com/reference-1.0.0.html#map-factory
    widget.createMap = function () {
        var map = L.map('map', {
            maxBounds: [
                [-85.0, -180.0],
                [85.0, 180.0]
            ],
            scrollWheelZoom: false
        });
        return map;
    };

Use a different map layer (e.g. Google Maps)

// You can create your own Google Map style here https://mapstyle.withgoogle.com/
    widget.createLayer = function (style) {
        return L.gridLayer.googleMutant({
            styles: styles,
            type: 'roadmap'
        });
    };

Reference

Handles marker click. The default implementation is updates the content list if it is connected to a content widget. Otherwise, it only emits the ‘marker:click’ event which can be listen using

See

It is possible to add logic before and after the widget initializes. Below is an example using .

{
Wikipedia: Geohash
Promise
Background
Geohash
Execution flows
Methods
.initialize(options)
.createMap()
.createLayer(style)
.handleMarkerClick(event)
.handleMoveEnd()
.createMarkerBySummary(summary)
.on(eventName, handler)
.getAggregatedDataByBounds(sw, ne, numGeohashPerView)
Exported methods
.getAggregatedDataByBounds(sw, ne, numGeohashPerView)
Customization examples
Add logic before/after the map widget starts
Initialize Leaflet with custom options
Use a different map layer (e.g. Google Maps)
.on
.getAggregatedDataByBounds(sw, ne, numGeohashPerView)