API Docs for: 0.1.1
Show:

flatworld.extensions.mapZoom Class

Core plugin for the engine. Handles zooming for the map. Core plugins can always be overwrote if needed. Zooming happens when the user scrolls the mousewheel or in mobile, pinches the screen.

Methods

_calculateCenterMoveCoordinates

() private static

_isOverZoomLimit

() private static

_isOverZoomLimit

_zoom

() private static

handleZoomEventDesktop

(
  • map
)

Setup desktop zoomEvent by currying. Internally: Sets up correct scale + moves map accordingly to zoom to the current center coordinates

Parameters:

  • map Map

    Map instance

handleZoomEventMobile

(
  • e
)

handleZoomEventMobile

Parameters:

init

(
  • mapObj
)

Required init functions for the plugin

Parameters:

  • mapObj Map

    instantiated Map class object

setZoomLimits

(
  • farther
  • closer
)

How much can be zoomed in maximum and minimum

Parameters:

  • farther Number

    (>1) How much one mouse wheel step zooms out

  • closer Number

    (0 - 1) How much one mouse wheel step zooms in

setZoomModifier

(
  • amount
)

How much one mouse wheel step zooms

Parameters:

  • amount Number

    How much one mouse wheel step zooms. Needs to be in between 0 - 0.5

unifiedEventCB

(
  • e
  • delta
  • deltaX
  • deltaY
)

This starts the correct eventListener for the current environment. Mousewheel and pinch differ quite dramatically so we keep them as separate functions.

Parameters:

  • e Event

    Event object

  • delta Integer

    Hamster.js provided delta

  • deltaX Integer

    Hamster.js provided delta

  • deltaY Integer

    Hamster.js provided delta

zoomIn

(
  • amount
)

Zoom in to the map

Parameters:

  • amount Number

    how much map is zoomed in

zoomOut

(
  • amount
)

Zoom out of the map

Parameters:

  • amount Number

    how much map is zoomed out

Attributes

zoomLimit

farther: Number, closer: Number

Maximum and minimum amount, the player can zoom the map

Fires event zoomLimitChange

Fires when the value for the configuration attribute zoomLimit is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.

zoomModifier

Number

How much one step of zooming affects

Fires event zoomModifierChange

Fires when the value for the configuration attribute zoomModifier is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.