Class JBMap

java.lang.Object
com.jbstrap.core.messagebus.MessageBus
com.jbstrap.ui.Component<JBMap>
com.jbstrap.jbmap.JBMap
All Implemented Interfaces:
com.jbstrap.ui.Animatable<JBMap>, com.jbstrap.ui.CanDrop<JBMap>, com.jbstrap.ui.Draggable<JBMap>, com.jbstrap.ui.HandleMouseEvents<JBMap>

public class JBMap extends com.jbstrap.ui.Component<JBMap> implements com.jbstrap.ui.Animatable<JBMap>, com.jbstrap.ui.CanDrop<JBMap>, com.jbstrap.ui.Draggable<JBMap>, com.jbstrap.ui.HandleMouseEvents<JBMap>

Interactive map component created using the Leaflet JavaScript library.

The interactive map displays POIs with images, popups and HTML content. You can place shapes (circle, rectangle, line) or a freeform shape on the map. These shapes are called layers.

The map is based on the geographical system of longitudes and latitudes. The tile layer (the map layer itself) is placed on this coordinate system. You can use various map service providers to access this layer. To access the map service, you have to extend the BaseMapLayer class. By default, the OpenStreetMap map provider is used. OpenStreetMapLayer

You can add layers to the map using the LayerGroup. That is, you can add layers to layer groups and add layer groups to the map.

You can use the geolocation feature to identify the user's location by using the getLocation(LocationFoundHandler) method.

The JBMap offers a built-in geocoding service OSMGeoCoding. Use it to search for an address or coordinate. If you want to use a different service provider, you can do so by extending the GeoCodingBase class. Supported events of the map component:

MapClickHandler AnimationStart, AnimationEnd, MouseDown, MouseLeave, MouseMove, MouseOver, MouseOut, MouseUp, Wheel, TouchCancel, TouchEnd, TouchMove, TouchStart, Drop, DragStart, DragEnd

Since:
4.0
See Also:
  • Field Details

  • Constructor Details

    • JBMap

      public JBMap()
      Creates the map component.
    • JBMap

      public JBMap(BaseMapLayer<?> baseMapLayer)
      Creates the map component by setting a default tile layer. You can read more about how to create this layer in the BaseMapLayer class.
      Parameters:
      baseMapLayer - The tile layer instance; If null, the default layer is OpenStreetMapLayer
    • JBMap

      public JBMap(String id)
      Creates the map with a unique ID.
      Parameters:
      id - Unique component ID The ID specified here will appear in the HTML tag as an ID attribute.
    • JBMap

      public JBMap(String id, BaseMapLayer<?> baseMapLayer)
      Creates the map with a unique ID by setting a default tile layer. You can read more about how to create this layer in the BaseMapLayer class.
      Parameters:
      id - Unique component ID The ID specified here will appear in the HTML tag as an ID attribute.
      baseMapLayer - The tile layer instance; If null, the default layer is OpenStreetMapLayer
    • JBMap

      public JBMap(String id, String language)
      Creates the map with a unique ID by specifying a language.
      Parameters:
      id - Unique component ID The ID specified here will appear in the HTML tag as an ID attribute.
      language - The client language code. If specified as null, the component will use the default language.The default language is set in the JBStrap parameter JBStrapParamType.DEFAULT_LANGUAGE_CODE.
      Throws:
      IllegalStateException - - If the component is set to be both Private and Public.
    • JBMap

      public JBMap(String id, String language, BaseMapLayer<?> baseMapLayer)
      Creates the map with a unique ID by specifying a language and setting a default tile layer. You can read more about how to create this layer in the BaseMapLayer class.
      Parameters:
      id - Unique component ID The ID specified here will appear in the HTML tag as an ID attribute.
      language - The client language code. If specified as null, the component will use the default language.The default language is set in the JBStrap parameter JBStrapParamType.DEFAULT_LANGUAGE_CODE.
      baseMapLayer - The tile layer instance; If null, the default layer is OpenStreetMapLayer
      Throws:
      IllegalStateException - - If the component is set to be both Private and Public.
  • Method Details

    • addBaseMapLayer

      public JBMap addBaseMapLayer(BaseMapLayer<?> baseMapLayer)
      Adds a unique tile layer to the map. You can read more about how to create this layer in the BaseMapLayer class.
      Parameters:
      baseMapLayer - Tile layer instance
      Returns:
      JBMap instance
    • getBaseMapLayerByName

      public BaseMapLayer<?> getBaseMapLayerByName(String name)
      Gets a tile layer from the map by its name.
      Parameters:
      name - Tile layer unique name
      Returns:
      Tile layer instance If no tile layer was found based on the name parameter, null is returned.
    • removeBaseMapLayer

      public JBMap removeBaseMapLayer(BaseMapLayer<?> baseMapLayer)
      Deletes a tile layer from the map.
      Parameters:
      baseMapLayer - Tile layer instance
      Returns:
      JBMap instance
    • removeAllBaseMapLayer

      public JBMap removeAllBaseMapLayer()
      Removes all tile layers from the map.
      Returns:
      JBMap instance
    • init

      public void init() throws com.jbstrap.core.websocket.JavaScriptLoadError
      Overrides:
      init in class com.jbstrap.ui.Component<JBMap>
      Throws:
      com.jbstrap.core.websocket.JavaScriptLoadError
    • runOnHideOnLayer

      protected final void runOnHideOnLayer(com.jbstrap.ui.Component<?> layerComponent)
      Parameters:
      layerComponent - Layer component
    • writeHTML

      public boolean writeHTML(StringWriter writer)
      Specified by:
      writeHTML in class com.jbstrap.ui.Component<JBMap>
    • setHeight

      public JBMap setHeight(Integer height)
      Sets the map container height. By default, the map height is automatically calculated.
      Parameters:
      height - Map height in pixels If the specified height is 0 or smaller than 0, the map height is automatically calculated.
      Returns:
      JBMap component instance
    • getHeight

      public Integer getHeight()
      Gets the set map height.
      Returns:
      Map height in pixels or null, if the map height is not specified
    • setShowBorder

      public JBMap setShowBorder(boolean showBorder)
      Sets if a border should be displayed on the map container. The default setting is that the border is not displayed.
      Parameters:
      showBorder - If true is specified, the border is displayed on the map container Otherwise the border is not displayed.
      Returns:
      JBMap component instance
    • isShowBorder

      public boolean isShowBorder()
      Checks if the border is displayed on the map container.
      Returns:
      If true, the border is displayed on the map container Otherwise the border is not displayed.
    • setShowShadow

      public JBMap setShowShadow(boolean showShadow)
      Sets if there should be a shadow on the map container. The default setting is that no shadow is displayed on the map container.
      Parameters:
      showShadow - If true is specified, a shadow is displayed on the map container If false, no shadow is displayed.
      Returns:
      JBMap component instance
    • isShowShadow

      public boolean isShowShadow()
      Checks if the shadow is visible on the map container.
      Returns:
      If true, the shadow is displayed on the map container Otherwise the shadow is not visible.
    • getTitleParams

      protected com.jbstrap.core.Parameters getTitleParams()
      Returns:
      Parameter class containing map title settings
    • setTitle

      public JBMap setTitle(String title)
      Sets the map title.
      Parameters:
      title - Map title If null or an empty string is specified, the map title is not displayed.
      Returns:
      JBMap component instance
    • getTitle

      public String getTitle()
      Gets the map title.
      Returns:
      Map title or null, if no map title is specified
    • setTitleFontColor

      public JBMap setTitleFontColor(String color)
      Sets the map title color.
      Parameters:
      color - Map title color. If no color is specified or null, the map title is displayed using the grey theme color. Use the parameter to specify any color in the CSS3 format.
      Returns:
      JBMap component instance
    • getTitleFontColor

      public String getTitleFontColor()
      Get the map title color.
      Returns:
      Map title color or null, if no color is specified
    • setTitlePosition

      public JBMap setTitlePosition(MapTitlePosition titlePosition)
      Sets the map title position. The map title, if specified correctly, is displayed aligned to the center above the map.
      Parameters:
      titlePosition - Map title position If null is specified, the map title is displayed aligned to the center above the map. Available positions are listed in MapTitlePosition.
      Returns:
      JBMap component instance
    • getTitlePosition

      public MapTitlePosition getTitlePosition()
      Gets the map title position.
      Returns:
      Map title position
    • setTitleFontSize

      public JBMap setTitleFontSize(String fontSize)
      Sets the map title font size. The default map title font size is 14 pixels.
      Parameters:
      fontSize - Map title font size in the CSS3 format
      Returns:
      JBMap component instance
    • getTitleFontSize

      public String getTitleFontSize()
      Gets the map title font size.
      Returns:
      Map title font size in the CSS3 format
    • setTitleFontWeight

      public JBMap setTitleFontWeight(FontWeight fontWeight)
      Sets the map title font weight. By default, the map title is displayed with a bold font.
      Parameters:
      fontWeight - Map title font weight Available font weights are listed in the enum FontWeight.
      Returns:
      JBMap component instance
    • getTitleFontWeight

      public FontWeight getTitleFontWeight()
      Gets the map title font weight.
      Returns:
      Map title font weight
    • setShowTitle

      public JBMap setShowTitle(boolean showTitle)
      Sets if the map title should be displayed on the map. By default, if the specified title is not null or an empty string, it is displayed on the map.
      Parameters:
      showTitle - If true is specified, the title is displayed on the map, otherwise not
      Returns:
      JBMap component instance
    • isShowTitle

      public boolean isShowTitle()
      Checks if the map title is displayed.
      Returns:
      If true, the map title is displayed on the map container, otherwise false
    • setCenterCoordinates

      public JBMap setCenterCoordinates(Coordinates coordinates)
      Sets the map to a specified coordinate. The coordinate value is set to be in the center of the map.
      Parameters:
      coordinates - Map center coordinates
      Returns:
      The JBMap component instance
    • getCenterCoordinates

      public Coordinates getCenterCoordinates()
      Gets the specified center coordinate of the map.
      Returns:
      The specified center coordinate of the map
    • setZoom

      public JBMap setZoom(int zoom)
      The map's zoom setting.
      Parameters:
      zoom - Map zoom setting
      Returns:
      The JBMap component instance
    • getZoom

      public int getZoom()
      Gets the map's zoom setting.
      Returns:
      Map zoom setting
    • flyTo

      public JBMap flyTo(Coordinates coordinates, Integer zoom)
      "Flying to a point" on the map. The map "flies to" the set coordinates and zooms in using animation.
      Parameters:
      coordinates - Map center coordinates
      zoom - New map zoom setting
      Returns:
      The JBMap component instance
    • getLocation

      public JBMap getLocation(LocationFoundHandler handler)
      Gets the user's location and sets the location found event handler. This handler is executed if the user's location is found.
      Parameters:
      handler - LocationFoundHandler implementation
      Returns:
      JBMap instance
    • getLocationFoundHandler

      public final LocationFoundHandler getLocationFoundHandler(String id)
      Parameters:
      id - LocationFoundHandler unique ID
      Returns:
      LocationFoundHandler
    • addClickHandler

      public JBMap addClickHandler(MapClickEventHandler handler)
      Adds a map click event handler to the map. This handler is executed if the user clicks once on the map.
      Parameters:
      handler - A MapClickEventHandler implementation
      Returns:
      JBMap instance
    • removeClickHandler

      public JBMap removeClickHandler(MapClickEventHandler handler)
      Removes a map click event handler from the list of map click event handlers. The removed event handler does not apply to the event.
      Parameters:
      handler - TheMapClickEventHandler to be removed
      Returns:
      JBMap component instance
    • getClickHandlers

      public List<com.jbstrap.core.event.handlers.BrowserEventHandler> getClickHandlers()
      Gets a list of map click event handlers.
      Returns:
      A list of map click event handlers assigned to the map
    • setScaleShow

      public JBMap setScaleShow(boolean scaleShow)
      Sets the scale visibility in the lower left corner of the map.
      Parameters:
      scaleShow - Map visibility; If true, the map is visible, otherwise not.
      Returns:
      JBMap instance
    • isScaleShow

      public boolean isScaleShow()
      Gets the map scale visibility setting.
      Returns:
      Map scale visibility
    • setZoomControlVisible

      public JBMap setZoomControlVisible(boolean zoomControlVisible)
      Sets the map zoom controls' visibility.
      Parameters:
      zoomControlVisible - Map zoom controls' visibility
      Returns:
      JBMap instance
    • isZoomControlVisible

      public boolean isZoomControlVisible()
      Gets the map zoom controls' visibility setting.
      Returns:
      Map zoom controls' visibility setting; If true, it is visible, otherwise not.
    • setZoomInText

      public JBMap setZoomInText(String zoomInText)
      Sets the map's "zoom in" button content. The default setting is "+".
      Parameters:
      zoomInText - The "zoom in" button's content
      Returns:
      JBMap instance
    • getZoomInText

      public String getZoomInText()
      Gets the map's "zoom in" button content.
      Returns:
      The "zoom in" button content The default setting is "+".
    • setZoomInTitle

      public JBMap setZoomInTitle(String zoomInTitle)
      Sets the "zoom in" button's tooltip content. The default setting is "Zoom in".
      Parameters:
      zoomInTitle - The "zoom in" button's tooltip content
      Returns:
      JBMap instance
    • getZoomInTitle

      public String getZoomInTitle()
      Gets the "zoom in" button's tooltip content.
      Returns:
      The "zoom in" button's tooltip content The default setting is "Zoom in".
    • setZoomOutText

      public JBMap setZoomOutText(String zoomOutText)
      Sets the "zoom out" button content. The default setting is "-".
      Parameters:
      zoomOutText - The "zoom out" button content
      Returns:
      JBMap instance
    • getZoomOutText

      public String getZoomOutText()
      Gets the "zoom out" button content.
      Returns:
      The "zoom out" button content The default setting is "-".
    • setZoomOutTitle

      public JBMap setZoomOutTitle(String zoomOutTitle)
      Sets the "zoom out" button's tooltip content. The default setting is "Zoom out".
      Parameters:
      zoomOutTitle - The "zoom out" button's tooltip content
      Returns:
      JBMap instance
    • getZoomOutTitle

      public String getZoomOutTitle()
      Gets the "zoom out" button's tooltip content.
      Returns:
      The "zoom out" button's tooltip content The default setting is "Zoom out".
    • setMinZoom

      public JBMap setMinZoom(int minZoom)
      Sets the minimum zoom value.
      Parameters:
      minZoom - Minimum zoom value The default setting is 0.
      Returns:
      JBMap instance
    • getMinZoom

      public int getMinZoom()
      Gets the minimum zoom value.
      Returns:
      The minimum zoom value The default setting is 0.
    • setMaxZoom

      public JBMap setMaxZoom(int maxZoom)
      Sets the maximum zoom value.
      Parameters:
      maxZoom - The maximum zoom value The default setting is 18.
      Returns:
      JBMap instance
    • getMaxZoom

      public int getMaxZoom()
      Gets the maximum zoom value.
      Returns:
      The maximum zoom value The default setting is 18.
    • setDoubleClickZoom

      public JBMap setDoubleClickZoom(boolean doubleClickZoom)
      Sets the double click zoom feature on the map.
      Parameters:
      doubleClickZoom - Double click zoom feature The default setting is true. If you double click on the map, a zoom event happens.
      Returns:
      JBMap instance
    • isDoubleClickZoom

      public boolean isDoubleClickZoom()
      Checks if the double click zoom is enabled.
      Returns:
      If true, the double click zoom is enabled, otherwise not The default setting is true.
    • setDragging

      public JBMap setDragging(boolean dragging)
      Sets the dragging feature. This feature enables you to drag the map by pressing the mouse button. The default setting is true.
      Parameters:
      dragging - Map dragging
      Returns:
      JBMap instance
    • isDragging

      public boolean isDragging()
      Gets the dragging feature.
      Returns:
      Map dragging The default setting is true.
    • setScrollWheelZoom

      public JBMap setScrollWheelZoom(boolean scrollWheelZoom)
      Sets the mouse scrolling zoom feature. The default setting is true.
      Parameters:
      scrollWheelZoom - Enables or disable the mouse scrolling zoom feature
      Returns:
      JBMap instance
    • isScrollWheelZoom

      public boolean isScrollWheelZoom()
      Checks if the mouse scrolling zoom is enabled.
      Returns:
      true if the mouse scrolling zoom is enabled, otherwise not The default setting is true.
    • setZoomAnimation

      public JBMap setZoomAnimation(boolean zoomAnimation)
      Sets the zoom animation feature. The default setting is true.
      Parameters:
      zoomAnimation - Enables or disable the zoom animation feature
      Returns:
      JBMap instance
    • isZoomAnimation

      public boolean isZoomAnimation()
      Checks if the zoom animation is enabled.
      Returns:
      true if the zoom animation is enabled; Otherwise not enabled. The default setting is true.
    • setBoxZoom

      public JBMap setBoxZoom(boolean boxZoom)

      Enables the box zoom feature.

      If the box zoom feature is enabled, a rectangular selection can be created by pressing the Shift key and pressing the mouse button.

      By releasing the mouse button, the map zooms in on the selected area.

      Parameters:
      boxZoom - Box zoom enabled setting The default setting is true.
      Returns:
      JBMap instance
    • isBoxZoom

      public boolean isBoxZoom()
      Checks if the box zoom is enabled.
      Returns:
      The box zoom is enabled. If true, it is enabled, otherwise not
    • setClosePopupOnClick

      public JBMap setClosePopupOnClick(boolean closePopupOnClick)
      Enables the automatic closing of popups when the user clicks on the map. The default setting is true.
      Parameters:
      closePopupOnClick - Enables the automatic closing of popups when the user clicks on the map
      Returns:
      JBMap instance
    • isClosePopupOnClick

      public boolean isClosePopupOnClick()
      Checks if the automatic closing of popups is enabled when the user clicks on the map.
      Returns:
      If true, popups automatically close on the map if the user clicks; otherwise not The default setting is true.
    • setTrackResize

      public JBMap setTrackResize(boolean trackResize)
      "Tracking resize" feature of the map. The map fits to the available space in the window and its center is always the container's center.
      Parameters:
      trackResize - Tracking resize setting The default setting is true.
      Returns:
      JBMap instance
    • isTrackResize

      public boolean isTrackResize()
      Checks if the "tracking resize" feature of the map is enabled.
      Returns:
      If true, the tracking resize feature is enabled, otherwise not The default setting is true.
    • setZoomDelta

      public JBMap setZoomDelta(double zoomDelta)
      Controls how much the map's zoom level will change after pressing + or - on the keyboard, or using the zoom controls. Values smaller than 1 (e.g. 0.5) allow for greater granularity.
      Parameters:
      zoomDelta - Zoom delta setting The default setting is 1.
      Returns:
      JBMap instance
    • getZoomDelta

      public double getZoomDelta()
      Gets the zoom delta's set value.
      Returns:
      Zoom delta value
    • setZoomSnap

      public JBMap setZoomSnap(double zoomSnap)
      Forces the map's zoom level to always be a multiple of this, particularly right after a fitBounds() or a pinch-zoom. By default, the zoom level snaps to the nearest integer; lower values (e.g. 0.5 or 0.1) allow for greater granularity. A value of 0 means the zoom level will not be snapped after fitBounds or a pinch-zoom.
      Parameters:
      zoomSnap - Zoom snap value The default setting is 1.
      Returns:
      JBMap instance
    • getZoomSnap

      public double getZoomSnap()
      Gets the zoom snap value.
      Returns:
      Zoom snap value
    • setLayerGroups

      public JBMap setLayerGroups(List<LayerGroup> layerGroups)
      Sets the map layer group LayerGroup.
      Parameters:
      layerGroups - The new layer group list
      Returns:
      JBMap instance
    • setLayerGroups

      public JBMap setLayerGroups(LayerGroup... layerGroups)
      Sets the layer group. LayerGroup
      Parameters:
      layerGroups - The new layer group array
      Returns:
      JBMap instance
    • addLayerGroup

      public JBMap addLayerGroup(LayerGroup layerGroup)
      Adds a new layer group to the map. LayerGroup
      Parameters:
      layerGroup - The new layer group
      Returns:
      JBMap instance
      Throws:
      IllegalArgumentException - Thrown if the name of a layer group is the same as the layer group to be added
    • addLayerGroups

      public JBMap addLayerGroups(LayerGroup... layerGroups)
      Adds one or more layer groups to the map. LayerGroup
      Parameters:
      layerGroups - The new layer group array
      Returns:
      JBMap instance
      Throws:
      IllegalArgumentException - Thrown if the name of a layer group is the same as the layer group to be added
    • addLayerGroups

      public JBMap addLayerGroups(List<LayerGroup> layerGroups)
      Adds a list of layer groups to the map. LayerGroup
      Parameters:
      layerGroups - A list of layer groups
      Returns:
      JBMap instance
      Throws:
      IllegalArgumentException - Thrown if the unique name of a layer group is the same as the layer group to be added
    • getLayerGroups

      public List<LayerGroup> getLayerGroups()
      Gets the specified layer groups in a list. LayerGroup
      Returns:
      A list of the specified layer groups
    • getLayerGroupByName

      public LayerGroup getLayerGroupByName(String layerGroupName)
      Gets a layer group by its unique name. LayerGroup
      Parameters:
      layerGroupName - The new layer group's unique name
      Returns:
      Layer group
    • removeLayerGroup

      public JBMap removeLayerGroup(LayerGroup layerGroup)
      Removes a layerGroup from the map.
      Parameters:
      layerGroup - layerGroup instance
      Returns:
      The created JBMap instance
    • addDivLayer

      public JBMap addDivLayer(DivLayer divLayer)
      Adds a divLayer to the map. DivLayer
      Parameters:
      divLayer - The divLayer instance
      Returns:
      JBMap instance
    • setDivLayers

      public JBMap setDivLayers(List<DivLayer> divLayers)
      Sets the divLayer by passing a list of divLayers. DivLayer
      Parameters:
      divLayers - A list of divLayers
      Returns:
      JBMap instance
    • setDivLayers

      public JBMap setDivLayers(DivLayer... divLayers)
      Sets the divLayers by passing an array of divLayers. DivLayer
      Parameters:
      divLayers - divLayers array
      Returns:
      JBMap instance
    • addLayerStyle

      protected JBMap addLayerStyle(LayerStyle layerStyle)
      Adds a LayerStyle to the JBMap.
      Parameters:
      layerStyle - The LayerStyle instance
      Returns:
      JBMap instance
    • setLayerStyles

      protected JBMap setLayerStyles(List<LayerStyle> layerStyles)
      Adds a list of LayerStyles to the JBMap.
      Parameters:
      layerStyles - A list of LayerStyle instances
      Returns:
      JBMap instance
    • setLayerStyles

      protected JBMap setLayerStyles(LayerStyle... layerStyles)
      Adds a LayerStyle array to the JBMap.
      Parameters:
      layerStyles - An array of LayerStyles
      Returns:
      JBMap instance
    • addPointImage

      protected JBMap addPointImage(PointImage pointImage)
      Adds a PointImage to the JBMap.
      Parameters:
      pointImage - The PointImage instance
      Returns:
      JBMap instance
    • setPointImages

      protected JBMap setPointImages(List<PointImage> pointImages)
      Sets a list of PointImages in the JBMap.
      Parameters:
      pointImages - A list of PointImage instances
      Returns:
      JBMap instance
    • setPointImages

      protected JBMap setPointImages(PointImage... pointImages)
      Sets a PointImage array in JBMap.
      Parameters:
      pointImages - An array of PointImage instances
      Returns:
      JBMap instance
    • getParams

      protected com.jbstrap.core.Parameters getParams()
      Gets the JBMap parameters.
      Returns:
      The JBMap parameters
    • getComponents

      public List<com.jbstrap.ui.Component<?>> getComponents()
      Gets a list of components added to all layers.
      Overrides:
      getComponents in class com.jbstrap.ui.Component<JBMap>
    • runJS

      protected void runJS(String script)
      Executing JavaScript for all JBMap containers.
      Parameters:
      script -
    • runJSMap

      protected void runJSMap(String script)
      Executing JavaScript for the JBMap.
      Parameters:
      script -
    • afterDraw

      public void afterDraw()
      Automatically fetches LayerGroups from a DataDescriptor if the return value of the LayerGroup.isAutoFetchData() method is true.
      Overrides:
      afterDraw in class com.jbstrap.ui.Component<JBMap>
    • onShow

      public void onShow()
      Overrides:
      onShow in class com.jbstrap.ui.Component<JBMap>