Switchable Map APIs with Drupal

57
Engr. Ranel O. Padon [email protected] | https://github.com/ranelpadon Switchable Map APIs with Drupal

Transcript of Switchable Map APIs with Drupal

Page 1: Switchable Map APIs with Drupal

Engr. Ranel O. Padon

[email protected] | https://github.com/ranelpadon

Switchable Map APIs with Drupal

Page 2: Switchable Map APIs with Drupal

About Me

•  Software Engineer at Kite Systems (Hong Kong-based company)–  full-time Drupal developer for CNN Travel (our client)

•  part-time Python lecturer in University of the Philippines•  involved with programming for 9 years (Python, Java, etc)

•  involved in Drupal for the last 4 years

•  projects: http://github.com/ranelpadon•  plays competitive football/futsal

Page 3: Switchable Map APIs with Drupal

Topics •  Background– Use Case– Mapstraction JS Library and Drupal Module

– Design Patterns•  Strategy Design Pattern

•  CNN Travel Maps System– APIs: Google Maps, HERE Maps, MapBox– Map Widget

– Service Info

Page 4: Switchable Map APIs with Drupal

Background

•  we want to inject maps and custom texts in ournode pages (via CKEditor) and term pages (via Drupal blocks)

•  we will need to have a modular/flexible architecture for integrating maps since our partners will vary

from time to time.

Page 5: Switchable Map APIs with Drupal

Mapstraction JS Library

Page 6: Switchable Map APIs with Drupal

Mapstraction JS Library

Page 7: Switchable Map APIs with Drupal

Mapstraction JS Library

Page 8: Switchable Map APIs with Drupal

Mapstraction Drupal Module

Page 9: Switchable Map APIs with Drupal

Mapstraction Drupal Module

Page 10: Switchable Map APIs with Drupal

Mapstraction

•  “Mapstraction is a Javascript library that provides a single, common interface for a wide variety of Javascript map APIs.”

•  “It’s designed to enable a developer to switch from one maps API to another as smoothly and as quickly as possible.”

Page 11: Switchable Map APIs with Drupal

Mapstraction

•  codebase is huge/heavy and complex

•  outdated or not well-maintained

•  we decided to create a custom library/module for our needs

Page 12: Switchable Map APIs with Drupal

Design Patterns

Page 13: Switchable Map APIs with Drupal

Design Patterns

•  “I’ve been struck by one of the underlying principles that leads to better designs: remove duplication. So, avoiding repetition is a simple principle

that leads to good design.”–  Martin Fowler

–  http://martinfowler.com/ieeeSoftware/repetition.pdf

Page 14: Switchable Map APIs with Drupal

Design Patterns

•  “Identify what is common and what varies, find a way to isolate the common stuff from thevariations, then remove the redundancy in the

common stuff.”

Page 15: Switchable Map APIs with Drupal

Design Patterns

•  Software design patterns are proven/reusable solutions for usual programming problems

•  “.. are formalized best practices that the programmer can use to solve common problems when designing an application or system.”

•  “.. can speed up the development process by providing tested, proven development paradigms.”

Page 16: Switchable Map APIs with Drupal

Design Patterns

•  they are language-agnostic (Java, PHP, Python, …)

•  usually in the context of OOP

(Object-Oriented Programming)

Page 17: Switchable Map APIs with Drupal

Design Patterns

Page 18: Switchable Map APIs with Drupal

Design Patterns

Page 19: Switchable Map APIs with Drupal

Design Patterns

Page 20: Switchable Map APIs with Drupal

Design Patterns

Page 21: Switchable Map APIs with Drupal

Strategy Design Pattern

•  We used the Strategy Design Pattern before using PHP in our advertisement blocks rendering.

•  Advertisement content changes dynamically depending on its region info/context in the page.

•  This design pattern is used in some parts of jQuery core components and in the Controller components/mechanisms of MVC JavaScript frameworks like AngularJS.

Page 22: Switchable Map APIs with Drupal

Strategy Design Pattern

•  enables an algorithm's behavior to be selected at runtime:–  defines a family of algorithms,–  encapsulates each algorithm, and

–  makes the algorithms interchangeable within that family.

Page 23: Switchable Map APIs with Drupal

Strategy Design Pattern

Page 24: Switchable Map APIs with Drupal

Strategy Design Pattern

Page 25: Switchable Map APIs with Drupal

Strategy Design Pattern

•  test the performance of different sorting algorithms to an array of numbers: shell sort, heap sort, bubble sort, quicksort, etc.

•  Strategy pattern allows the test program to loop through all algorithms, simply by changing them at runtime and test each of these against the array.

•  All method signatures must be the same so that they can vary without the client program knowing about it.

Page 26: Switchable Map APIs with Drupal

Strategy Design Pattern

•  product order that needs to be shipped from a warehouse to a customer.

•  Shipping is the Context and the 3 shipping companies UPS, USPS, and Fedex are the Strategies.

Page 27: Switchable Map APIs with Drupal

Strategy Design Pattern

•  The map code logic will not not be tightly coupled to the TripAdvisor/Booking.com data for better modularity.

•  We could easily switch between HERE Maps API and Google Maps API and other APIs.

•  We could add/remove Map APIs as needed with minimal code adjustments.

Page 28: Switchable Map APIs with Drupal

Strategy Design Pattern

•  Likewise, the same Strategy Design Pattern could be applied when we expand later our data/content partners/providers (TripAdvisor, Booking.com, etc).

Page 29: Switchable Map APIs with Drupal

Typical Use Case/Construct

Page 30: Switchable Map APIs with Drupal

Strategy Design Pattern

better, extendable solution

Page 31: Switchable Map APIs with Drupal

Strategy Design Pattern

OOP solution

Page 32: Switchable Map APIs with Drupal

Strategy Design Pattern

Page 33: Switchable Map APIs with Drupal

Strategy Design Pattern

Page 34: Switchable Map APIs with Drupal

Strategy Design Pattern

Page 35: Switchable Map APIs with Drupal

CNN Travel Maps System

Page 36: Switchable Map APIs with Drupal

CNN Travel Maps | Markup

Page 37: Switchable Map APIs with Drupal

CNN Travel Maps | HERE Maps

Page 38: Switchable Map APIs with Drupal

CNN Travel Maps | GMaps

Page 39: Switchable Map APIs with Drupal

CNN Travel Maps | Mapbox

Page 40: Switchable Map APIs with Drupal

CNN Travel Maps | Service Info

Page 41: Switchable Map APIs with Drupal

CNN Travel Maps | Service Info

Page 42: Switchable Map APIs with Drupal

CNN Travel Maps | Service Info

Partner Hotel

Page 43: Switchable Map APIs with Drupal

CNN Travel Maps | Service Info

Partner Hotel

Page 44: Switchable Map APIs with Drupal

CNN Travel Maps | Service Info

TripAdvisor Reviews

Page 45: Switchable Map APIs with Drupal

CNN Travel Maps | Service Info

TripAdvisor Photos

Page 46: Switchable Map APIs with Drupal

CNN Travel Maps JS

Page 47: Switchable Map APIs with Drupal
Page 48: Switchable Map APIs with Drupal
Page 49: Switchable Map APIs with Drupal
Page 50: Switchable Map APIs with Drupal

CNN Travel Maps | Form API

Page 51: Switchable Map APIs with Drupal

CNN Travel Maps System

Page 52: Switchable Map APIs with Drupal

CNN Travel Maps System

Page 53: Switchable Map APIs with Drupal

CNN Travel Maps System

Page 54: Switchable Map APIs with Drupal

CNN Travel Maps System

Page 55: Switchable Map APIs with Drupal

Recommendation

•  One of the best resources about Design Patterns:•  https://sourcemaking.com/design_patterns•  https://sourcemaking.com/design-patterns-book

Page 56: Switchable Map APIs with Drupal

Special Thanks

•  CNN Travel (http://travel.cnn.com) for the ideas and inspiration for this presentation.

Page 57: Switchable Map APIs with Drupal