Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.yotta.horizon.mapping.presenters;
- import com.google.gwt.core.client.JavaScriptObject;
- import com.yotta.horizon.base.Horizon;
- import com.yotta.horizon.mapbuilder.shared.ItemStyleRule;
- import com.yotta.horizon.mapbuilder.shared.RenderSource;
- import com.yotta.horizon.mapping.shared.SectionItem;
- import com.yotta.horizon.mapping.shared.SectionItemImagesMap;
- import com.yotta.horizon.mapping.shared.events.SectionItemReadyEvent;
- import com.yotta.horizon.shared.gmaps.LatLng;
- import com.yotta.horizon.shared.gmaps.MVCArray;
- import com.yotta.horizon.shared.gmaps.Map;
- import com.yotta.horizon.shared.gmaps.PolyLineOptions;
- import com.yotta.horizon.shared.resources.HorizonResources;
- import com.yotta.horizon.shared.resources.config.HorizonConfigFlags;
- import com.yotta.horizon.shared.resources.config.HorizonConfigResource;
- /**
- * Represents a chainage group which boxes section items into a more friendly ui
- * @author cmcnicholas
- */
- class SectionItemPresenterChainageGroup extends JavaScriptObject {
- private static final PolyLineOptions ITEM_ACTIVE = PolyLineOptions.create(false, 2,
- HorizonConfigResource.INSTANCE.chainageGroupColourActive(), 1);
- private static final PolyLineOptions ELBOW_ACTIVE = PolyLineOptions.create(false, 2,
- HorizonConfigResource.INSTANCE.chainageGroupColourActive(), 1);
- private static final PolyLineOptions ITEM_DEFAULT = PolyLineOptions.create(false, 2,
- HorizonConfigResource.INSTANCE.chainageGroupColour(), 1);
- private static final PolyLineOptions ELBOW_DEFAULT = PolyLineOptions.create(false, 2,
- HorizonConfigResource.INSTANCE.chainageGroupColour(), 1);
- private static final JavaScriptObject CONSTRUCTOR = SectionItemPresenterChainageGroup.setup();
- protected SectionItemPresenterChainageGroup() {}
- /**
- * Creates a new chainage group instance
- * @param map the map to create the chainage group on
- * @param minLevel the min level for the element to be active on
- * @param maxLevel the max level for the element to be active on
- * @param lowerChainage the lower chainage value of the group
- * @param upperChainage the upper chainage value of the group
- * @param chainagePath the path that the group controls the items of
- * @param isLeft whether to display on the left of the road or right
- * @return a chainage group instance
- */
- public static final native SectionItemPresenterChainageGroup create(Map map, int minLevel, int maxLevel,
- int lowerChainage, int upperChainage, MVCArray<LatLng> chainagePath, boolean isLeft) /*-{
- var SectionItemPresenterChainageGroup = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::CONSTRUCTOR;
- return new SectionItemPresenterChainageGroup(map, minLevel, maxLevel,
- lowerChainage, upperChainage, chainagePath, isLeft);
- }-*/;
- /**
- * Gets the polyline item active options
- * @return a set of polyline options
- */
- public static final PolyLineOptions getItemActivePolyLineOptions() {
- return ITEM_ACTIVE;
- }
- /**
- * Gets the polyline elbow active options
- * @return a set of polyline options
- */
- public static final PolyLineOptions getElbowActivePolyLineOptions() {
- return ELBOW_ACTIVE;
- }
- /**
- * Gets the polyline item default options
- * @return a set of polyline options
- */
- public static final PolyLineOptions getItemDefaultPolyLineOptions() {
- return ITEM_DEFAULT;
- }
- /**
- * Gets the polyline elbow default options
- * @return a set of polyline options
- */
- public static final PolyLineOptions getElbowDefaultPolyLineOptions() {
- return ELBOW_DEFAULT;
- }
- /**
- * Gets the upper chainage value this box controls
- * @return a chainage value
- */
- public final native int getUpperChainage() /*-{
- return this.getUpperChainage();
- }-*/;
- /**
- * Gets the lower chainage value this box controls
- * @return a chainage value
- */
- public final native int getLowerChainage() /*-{
- return this.getLowerChainage();
- }-*/;
- /**
- * Disposes of the chainage group and releases resources
- */
- public final native void dispose() /*-{
- this.dispose();
- }-*/;
- /**
- * Method to add a section item to the control of the chainage group, the
- * item will not be immediately drawn in the box
- * @param item the item to add
- */
- public final native void addItem(SectionItem item) /*-{
- this.addItem(item);
- }-*/;
- /**
- * Method to hover an item MANUALLY!!!
- * @param item the item to hover
- * @param over whether to hover over or out
- */
- public final native void manualHoverItem(SectionItem item, boolean over) /*-{
- if (this.getBoxes() == null) {
- return;
- }
- var key = @com.yotta.horizon.mapping.shared.SectionItemMap::getKey(Lcom/yotta/horizon/mapping/shared/SectionItem;)(item);
- for (var i = 0, s = this.getBoxes().length; i < s; i++) {
- var box = this.getBoxes()[i];
- for (var j = 0, size = this.getBoxes()[i].getItems().length; j < size; j++) {
- var currentItem = this.getBoxes()[i].getItems()[j];
- var currentKey = @com.yotta.horizon.mapping.shared.SectionItemMap::getKey(Lcom/yotta/horizon/mapping/shared/SectionItem;)(currentItem);
- if (key == currentKey) {
- if (this.getBoxes()[i].getPopout().style.display != 'none'
- && this.getBoxes()[i].getBoxDrawer() != null
- && this.getBoxes()[i].getBoxDrawer().isVisible()) {
- $wnd.google.maps.event.trigger(this.getBoxes()[i]
- .getBoxDrawer().getBoxes()[j].getElement(),
- over ? 'mouseover' : 'mouseout', {
- manual : true,
- item : currentItem
- });
- } else {
- // Pass edge as fix for editable polylines which cause issues if an empty object is passed
- $wnd.google.maps.event.trigger(box.getElement(),
- over ? 'mouseover' : 'mouseout', {
- manual : true,
- item : currentItem
- });
- }
- }
- }
- }
- }-*/;
- /**
- * Method to remove a section item from the chainage group, the item will
- * not be immediately removed from the box
- * @param item the item to remove
- */
- public final native void removeItem(SectionItem item) /*-{
- this.removeItem(item);
- }-*/;
- /**
- * Method to clear all the items from the chainage group
- */
- public final native void clearItems() /*-{
- this.clearItems();
- }-*/;
- private static final String generateImage(String text, String colourHex) {
- return SectionItemImagesMap.generateImage(text, colourHex);
- }
- /**
- * Gets the image url from the map
- * @param item Section item for which to get the image
- * @return url string
- */
- private static final String getImageUrl(SectionItem item) {
- return SectionItemImagesMap.INSTANCE.get(item);
- }
- /**
- * Gets the cropped image url from the map (Used to display the centre of
- * diagrams)
- * @param item Section item for which to get the cropped image
- * @return url string
- */
- private static final String getCropUrl(SectionItem item) {
- return SectionItemImagesMap.INSTANCE.getCrop(item);
- }
- /**
- * Returns cropped image url if it's present, otherwise returns normal image
- * url
- * @param item Section item for which to get the image
- * @return url string
- */
- private static final String getExistingUrl(SectionItem item) {
- if(SectionItemImagesMap.INSTANCE.hasCropImage(item)) {
- return getCropUrl(item);
- }
- return getImageUrl(item);
- }
- /**
- * Sets the image url
- * @param item Section item for which to set the image url
- * @param url string url of the image
- */
- private static final void setImageUrl(SectionItem item, String url) {
- SectionItemImagesMap.INSTANCE.set(item, url);
- }
- /**
- * Sets the cropped image url
- * @param item Section item for which to set the cropped image url
- * @param url string url of the cropped image
- */
- private static final void setCropUrl(SectionItem item, String url) {
- SectionItemImagesMap.INSTANCE.setCrop(item, url);
- }
- /**
- * Method to update the chainage group ui and draw active items
- * @param forceUpdate method to force an update even if we think internal
- * state has not changed
- */
- public final native void update(boolean forceUpdate) /*-{
- if (forceUpdate) {
- this.setDoUpdate(true);
- }
- this.update();
- }-*/;
- /**
- * Gets the chainage group style name
- * @return a style name
- */
- private static final String getChainageGroupStyleName() {
- return HorizonResources.INSTANCE.horizonCss().chainageGroup();
- }
- /**
- * Gets the chainage group horizontal style name
- * @return a style name
- */
- private static final String getChainageGroupHorizontalStyleName() {
- return HorizonResources.INSTANCE.horizonCss().chainageGroupHorizontal();
- }
- /**
- * Gets the chainage group item style name
- * @return a style name
- */
- private static final String getChainageGroupItemStyleName() {
- return HorizonResources.INSTANCE.horizonCss().chainageGroupItem();
- }
- /**
- * Gets the chainage group item no diagram style name
- * @return a style name
- */
- private static final String getChainageGroupItemNoDiagramStyleName() {
- return HorizonResources.INSTANCE.horizonCss().chainageGroupItemNoDiagram();
- }
- /**
- * Gets the chainage group item popout style name
- * @return a style name
- */
- private static final String getChainageGroupItemPopoutStyleName() {
- return HorizonResources.INSTANCE.horizonCss().chainageGroupItemPopout();
- }
- /**
- * Gets the chainage group item active style name
- * @return a style name
- */
- private static final String getChainageGroupItemActiveStyleName() {
- return HorizonResources.INSTANCE.horizonCss().chainageGroupItemActive();
- }
- /**
- * Gets the chainage group item hovered style name
- * @return a style name
- */
- private static final String getChainageGroupItemHoveredStyleName() {
- return HorizonResources.INSTANCE.horizonCss().chainageGroupItemHovered();
- }
- /**
- * Gets the lollipop item counter bubble style name
- * @return a style name
- */
- private static final String getLollipopBubbleStyleName() {
- return HorizonResources.INSTANCE.horizonCss().lollipopBubble();
- }
- /**
- * Gets the lollipop item counter bubble style name for firefox
- * @return a style name
- */
- private static final String getLollipopBubbleFFStyleName() {
- return HorizonResources.INSTANCE.horizonCss().lollipopBubbleBottom();
- }
- /**
- * Gets the chainage group item small style name
- * @return a style name
- */
- private static final String getChainageGroupItemSmallStyleName() {
- return HorizonResources.INSTANCE.horizonCss().chainageGroupItemSmall();
- }
- private static final void fireItemReady(int renderSourceId, int itemId, boolean raisedByDrawer) {
- Horizon.getApp().getEventBus().fireEvent(new SectionItemReadyEvent(renderSourceId, itemId, raisedByDrawer));
- }
- /**
- * Gets the acronym of a style set name for the given section item
- * @param item SectionItem for which to get the style name acronym
- * @return acronym string
- */
- private static final String getAcronymName(SectionItem item) {
- final RenderSource rg = Horizon.getApp().getUser().getRenderGroups().get(item.getRenderGroupId());
- if(rg != null && rg.getHiLodItemStyleRuleSet() != null) {
- for(final ItemStyleRule isr : rg.getHiLodItemStyleRuleSet().getItemStyleRules().values()) {
- if(isr.getItemStyleRuleId() == item.getGeometry().getStyleRuleId()) {
- if(isr.getShortCode() != null) {
- return isr.getShortCode();
- }
- final StringBuilder labelBuilder = new StringBuilder(5);
- for(int i = 0, j = 0; i < isr.getDescription().length() && j < 5; i++) {
- if(Character.isUpperCase(isr.getDescription().charAt(i))) {
- labelBuilder.append(isr.getDescription().charAt(i));
- j++;
- }
- }
- isr.setShortCode(labelBuilder.toString());
- return labelBuilder.toString();
- }
- }
- }
- return item.getGeometry().getFeatureCode();
- }
- /**
- * Creates the constructor for a chainage group
- * @return a javascript function
- */
- private static final native JavaScriptObject setup() /*-{
- // Constructor for direction enumeration
- var ChainageGroupDirection = function() {};
- ChainageGroupDirection.EAST = new ChainageGroupDirection();
- ChainageGroupDirection.SOUTH = new ChainageGroupDirection();
- ChainageGroupDirection.WEST = new ChainageGroupDirection();
- ChainageGroupDirection.NORTH = new ChainageGroupDirection();
- // Method to calculate which direction to use given the orientation of the road and the heading
- ChainageGroupDirection.calculate = function(isLeft, heading) {
- if(heading < 0) {
- throw "heading cannot be less than zero!";
- }
- if(heading >= 360) {
- throw "heading cannot be greater than or equal to 360!";
- }
- if(heading >= 315 || heading < 45) {
- return isLeft ? ChainageGroupDirection.WEST : ChainageGroupDirection.EAST;
- } else if(heading >= 45 && heading < 135) {
- return isLeft ? ChainageGroupDirection.NORTH : ChainageGroupDirection.SOUTH;
- } else if(heading >= 135 && heading < 225) {
- return isLeft ? ChainageGroupDirection.EAST : ChainageGroupDirection.WEST;
- } else if(heading >= 225 && heading < 315) {
- return isLeft ? ChainageGroupDirection.SOUTH : ChainageGroupDirection.NORTH;
- } else {
- throw "Heading value not handled";
- }
- };
- // Constructor for anchor enumeration
- var ChainageGroupAnchor = function() {};
- ChainageGroupAnchor.TOP_LEFT = new ChainageGroupAnchor();
- ChainageGroupAnchor.TOP_RIGHT = new ChainageGroupAnchor();
- ChainageGroupAnchor.BOTTOM_LEFT = new ChainageGroupAnchor();
- ChainageGroupAnchor.BOTTOM_RIGHT = new ChainageGroupAnchor();
- // Method to calculate which anchor to use given the orientation of the road and the heading
- ChainageGroupAnchor.calculate = function(isLeft, heading) {
- if(heading < 0) {
- throw "heading cannot be less than zero!";
- }
- if(heading >= 360) {
- throw "heading cannot be greater than or equal to 360!";
- }
- if(heading >= 0 && heading < 90) {
- return isLeft ? ChainageGroupAnchor.BOTTOM_RIGHT : ChainageGroupAnchor.TOP_LEFT;
- } else if(heading >= 90 && heading < 180) {
- return isLeft ? ChainageGroupAnchor.BOTTOM_LEFT : ChainageGroupAnchor.TOP_RIGHT;
- } else if(heading >= 180 && heading < 270) {
- return isLeft ? ChainageGroupAnchor.TOP_LEFT : ChainageGroupAnchor.BOTTOM_RIGHT;
- } else if(heading >= 270 && heading < 360) {
- return isLeft ? ChainageGroupAnchor.TOP_RIGHT : ChainageGroupAnchor.BOTTOM_LEFT;
- } else {
- throw "Heading value not handled";
- }
- };
- // Constants
- var PIXEL_OFFSET = 100;
- var PIXEL_OFFSET_ELBOW = 50;
- var MAX_ITEMS_PER_ROW = 8;
- var POLYLINE_ELBOW_DEFAULT = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::ELBOW_DEFAULT;
- var POLYLINE_ELBOW_ACTIVE = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::ELBOW_ACTIVE;
- var POLYLINE_ITEM_DEFAULT = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::ITEM_DEFAULT;
- var POLYLINE_ITEM_ACTIVE = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::ITEM_ACTIVE;
- // Retains a pointer to the last box selected
- var lastBoxSelected;
- // Retains a pointer to the last box draw open
- var lastBoxDrawerSelected;
- // Retains a pointer to the throttle of hover events
- var itemHoverThrottle;
- // CONSTRUCTOR ChainageGroupBox
- // Represents the window boxes that display signs and diagrams
- var ChainageGroupBox = function(map, elbowPolyline, elbowLatLng, sectionItem, key, isSmall, direction, sectionHeading) {
- var me = this; // Reference to self
- // Set variables
- this.color_ = null;
- this.map_ = map;
- this.key_ = key;
- this.element_ = $doc.createElement('div');
- this.popout_ = $doc.createElement('div');
- this.itemCounterBubble_ = $doc.createElement('div');
- this.popoutCounterBubble_ = $doc.createElement('div');
- this.elbowPolyline_ = elbowPolyline;
- this.selected_ = false;
- this.elementMouseOverListener_ = null;
- this.elementMouseOutListener_ = null;
- this.popoutMouseOutListener_ = null;
- this.popoutBubbleMouseOutListener_ = null;
- this.popoutClickListener_ = null;
- this.sectionItemMouseOutListeners_ = [];
- this.sectionItemMouseOverListeners_ = [];
- this.sectionItemSelectedListener_ = null;
- this.direction_ = direction;
- this.sectionHeading_ = sectionHeading;
- this.sectionItems_ = [sectionItem];
- this.polylines_ = [];
- this.boxDrawer_ = null;
- this.isSmall_ = isSmall;
- // Get image urls
- var hasDiagram = @com.yotta.horizon.mapping.shared.SectionItemUtils::getSectionItemDiagramId(Lcom/yotta/horizon/mapping/shared/SectionItem;)(sectionItem) != null;
- var cropUrl = @com.yotta.horizon.mapping.shared.SectionItemUtils::getSectionItemImageUrlCropped(Lcom/yotta/horizon/mapping/shared/SectionItem;Z)(sectionItem, isSmall);
- var imageUrl = @com.yotta.horizon.mapping.shared.SectionItemUtils::getSectionItemImageUrl(Lcom/yotta/horizon/mapping/shared/SectionItem;Z)(sectionItem, isSmall);
- var color = @com.yotta.horizon.mapping.shared.SectionItemUtils::getSectionItemColor(Lcom/yotta/horizon/mapping/shared/SectionItem;)(sectionItem);
- this.setColor(color);
- // Setup element
- var element = this.getElement();
- element.style.width = isSmall ? '16px' : '32px';
- element.style.height = isSmall ? '16px' : '32px';
- element.style.backgroundColor = color;
- element.style.position = 'relative';
- $wnd.jQuery(element).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemStyleName());
- if(isSmall) {
- $wnd.jQuery(element).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemSmallStyleName());
- }
- // Setup item counter bubble for the element
- var itemCounterBubble = this.getBubble();
- $wnd.jQuery(itemCounterBubble).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getLollipopBubbleStyleName());
- itemCounterBubble.style.fontWeight = 'bolder';
- if(isSmall) {
- itemCounterBubble.style.right = '-8px';
- itemCounterBubble.style.bottom = '-4px';
- } else {
- $wnd.jQuery(itemCounterBubble).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getLollipopBubbleFFStyleName());
- }
- element.appendChild(itemCounterBubble);
- // Setup item counter bubble for the popout
- var popoutBubble = this.getPopoutBubble();
- $wnd.jQuery(popoutBubble).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getLollipopBubbleStyleName());
- $wnd.jQuery(popoutBubble).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getLollipopBubbleFFStyleName());
- popoutBubble.style.fontWeight = 'bolder';
- this.setBubbleVisible(false);
- // Setup popout
- var popout = this.getPopout();
- popout.style.width = isSmall ? '16px' : '32px';
- popout.style.height = isSmall ? '16px' : '32px';
- popout.style.backgroundColor = color;
- popout.style.position = 'relative';
- popout.style.borderColor = color;
- $wnd.jQuery(popout).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemPopoutStyleName());
- popout.appendChild(popoutBubble);
- element.appendChild(popout);
- // Setup polyline to elbow if enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- var polyline = new $wnd.google.maps.Polyline($wnd.jQuery.extend({
- map: map,
- path: [
- this.getFirstItem().setIcon ? // Marker or polyline/polygon
- this.getFirstItem().getPosition() :
- @com.yotta.horizon.shared.gmaps.MapMath::getNearestLatLngOnPath(Lcom/yotta/horizon/shared/gmaps/MVCArray;Lcom/yotta/horizon/shared/gmaps/LatLng;)(this.getFirstItem().getPath(), elbowLatLng),
- elbowLatLng
- ]
- }, POLYLINE_ITEM_DEFAULT));
- this.polylines_.push(polyline);
- }
- // Preload image if there is one
- var mapImage = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getExistingUrl(Lcom/yotta/horizon/mapping/shared/SectionItem;)(this.getFirstItem());
- if(mapImage != null) {
- element.style.background = color + ' url("'+ mapImage +'") no-repeat center center';
- element.style.backgroundSize = isSmall ? "16px" : "32px";
- } else if(hasDiagram) {
- var imageElement = new $wnd.Image();
- imageElement.style.visibility = 'hidden';
- imageElement.style.width = '1px';
- imageElement.style.height = '1px';
- imageElement.onload = function() {
- element.style.background = color + ' url("' + cropUrl + '") no-repeat center center';
- element.removeChild(imageElement);
- imageElement = null;
- };
- @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::setImageUrl(Lcom/yotta/horizon/mapping/shared/SectionItem;Ljava/lang/String;)(me.getFirstItem(), imageUrl);
- @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::setCropUrl(Lcom/yotta/horizon/mapping/shared/SectionItem;Ljava/lang/String;)(me.getFirstItem(), cropUrl);
- imageElement.src = cropUrl;
- element.appendChild(imageElement);
- } else {
- var dimension = isSmall ? 16 : 32;
- var imageText = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getAcronymName(Lcom/yotta/horizon/mapping/shared/SectionItem;)(this.getFirstItem());
- var dataUrl = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::generateImage(Ljava/lang/String;Ljava/lang/String;)(imageText, color);
- var imageElement = new $wnd.Image();
- imageElement.style.width = dimension + "px";
- imageElement.style.height = dimension + "px";
- imageElement.onload = function() {
- element.style.background = color + ' url("'+ dataUrl +'") no-repeat center center';
- element.style.backgroundSize = isSmall ? "16px" : "32px";
- element.removeChild(imageElement);
- imageElement = null;
- };
- @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::setImageUrl(Lcom/yotta/horizon/mapping/shared/SectionItem;Ljava/lang/String;)(this.getFirstItem(), dataUrl);
- imageElement.src = dataUrl;
- element.appendChild(imageElement);
- }
- // Add listener for mouse over to highlight the path to the item
- this.elementMouseOverListener_ = $wnd.google.maps.event.addDomListener(element, 'mouseover', function(e) {
- if(me.getItems().length > 1 && me.getBoxDrawer().isVisible()) {
- if(me.getPopout().style.display != 'none') {
- return;
- } else if(!me.getSelected()) {
- me.getBoxDrawer().hide();
- }
- }
- // Highlight paths if enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- if(!e.item) {
- for(var i = 0, size = me.getItems().length; i < size; i++) {
- me.getPolylines()[i].setOptions(POLYLINE_ITEM_ACTIVE);
- }
- me.getElbow().setOptions(POLYLINE_ELBOW_ACTIVE);
- } else {
- for(var i = 0, size = me.getItems().length; i < size; i++) {
- if(e.item == me.getItems()[i]) {
- me.getPolylines()[i].setOptions(POLYLINE_ITEM_ACTIVE);
- break;
- }
- }
- me.getElbow().setOptions(POLYLINE_ELBOW_ACTIVE);
- }
- }
- // Add hovered class
- $wnd.jQuery(me.getElement()).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemHoveredStyleName());
- // Highlight the items
- if(!e.cancelItemMouseOver && !e.item) {
- // Pass edge as fix for editable polylines which cause issues if an empty object is passed
- for(var i = 0, size = me.getItems().length; i < size; i++) {
- $wnd.google.maps.event.trigger(me.getItems()[i], 'mouseover', { edge: 0, notSimpleEvent: true });
- }
- } else if(e.manual && e.item) {
- $wnd.google.maps.event.trigger(e.item, 'mouseover', {edge: 0, notSimpleEvent: true});
- } else if(e.cancelItemMouseOver && e.item && me.getItems().length > 1) {
- var selected = false;
- for(var i = 0, s = me.getBoxDrawer().getItems().length; i < s; i++) {
- if(me.getBoxDrawer().getBoxes()[i].getSelected()) {
- selected = true;
- break;
- }
- }
- if(selected) {
- $wnd.google.maps.event.trigger(me.getPopout(), 'click', { zoom: true });
- }
- }
- // Load background image from the map
- var jqPopout = $wnd.jQuery(popout);
- var mapImage = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getImageUrl(Lcom/yotta/horizon/mapping/shared/SectionItem;)(me.getFirstItem());
- if(mapImage != null) {
- jqPopout.css({
- backgroundImage: 'url("'+ mapImage +'")',
- backgroundSize: me.isSmall() ? "32px" : "64px",
- backgroundRepeat: 'no-repeat'
- });
- }
- // Show popout
- jqPopout.stop(true).show().animate({
- width: isSmall ? '32px' : '64px',
- height: isSmall ? '32px' : '64px',
- top: isSmall ? '-8px' : '-16px',
- left: isSmall ? '-8px' : '-16px',
- opacity: 1
- }, 400, 'easeOutExpo').css('overflow', 'visible');
- // Trigger hover
- if(itemHoverThrottle) {
- clearTimeout(itemHoverThrottle);
- itemHoverThrottle = null;
- }
- if(!e.manual && me.getItems().length == 1) {
- itemHoverThrottle = setTimeout(function() {
- if(me.getFirstItem()) {
- $wnd.google.maps.event.trigger(me.getFirstItem(), 'hover', { over: true });
- }
- }, 50);
- }
- });
- // Add listener for mouse out to unhighlight the path to the item
- this.elementMouseOutListener_ = $wnd.google.maps.event.addDomListener(element, 'mouseout', function(e) {
- // Dont animate if selected
- if(me.getSelected()) {
- return;
- }
- // Reset polyline if enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- for(var i = 0, size = me.getPolylines().length; i < size; i++) {
- me.getPolylines()[i].setOptions(POLYLINE_ITEM_DEFAULT);
- }
- // Only unhighlight the elbow if it is not the same reference elbow as the current item
- if(!lastBoxSelected || lastBoxSelected.getElbow() != me.getElbow()) {
- me.getElbow().setOptions(POLYLINE_ELBOW_DEFAULT);
- }
- }
- if(!e.cancelItemMouseOut && !e.item) {
- // Pass edge as fix for editable polylines which cause issues if an empty object is passed
- for(var i = 0, size = me.getItems().length; i < size; i++) {
- $wnd.google.maps.event.trigger(me.getItems()[i], 'mouseout', { edge: 0, notSimpleEvent: true });
- }
- } else if(e.manual && e.item) {
- $wnd.google.maps.event.trigger(e.item, 'mouseout', { edge: 0 });
- }
- // Remove hovered class
- $wnd.jQuery(me.getElement()).removeClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemHoveredStyleName());
- // Trigger hover
- if(itemHoverThrottle) {
- clearTimeout(itemHoverThrottle);
- itemHoverThrottle = null;
- }
- if(!e.manual) {
- itemHoverThrottle = setTimeout(function() {
- if(me.getItems()) {
- for(var i = 0, size = me.getItems().length; i < size; i++) {
- $wnd.google.maps.event.trigger(me.getItems()[i], 'hover', { over: false });
- }
- }
- }, 50);
- }
- });
- // Add listener for popout mouseout to remove popout
- this.popoutMouseOutListener_ = $wnd.google.maps.event.addDomListener(popout, 'mouseout', function(e) {
- // Dont animate if selected
- if(me.getSelected()) {
- return;
- }
- var jqPopout = $wnd.jQuery(popout);
- if(!e.stopAnimation) {
- jqPopout.animate({
- width: isSmall ? '16px' : '32px',
- height: isSmall ? '16px' : '32px',
- top: '0px',
- left: '0px',
- opacity: 'initial'
- }, 200, 'easeOutExpo',
- function() {
- jqPopout.css({
- backgroundColor : color,
- borderColor : color
- });
- jqPopout.hide();
- }
- );
- } else {
- jqPopout.stop(true).animate({
- width: isSmall ? '16px' : '32px',
- height: isSmall ? '16px' : '32px',
- top: '0px',
- left: '0px',
- opacity: 0
- }, 200, 'easeOutExpo',
- function() {
- jqPopout.css({
- backgroundColor: color,
- borderColor: color
- });
- jqPopout.hide();
- }
- );
- }
- });
- var completeFunction = function() {
- me.setSelected(false);
- };
- // Add listener for selection of the popout image
- this.popoutClickListener_ = $wnd.google.maps.event.addDomListener(popout, 'click', function(e) {
- // If BoxDrawer is available
- if(me.getItems().length > 1) {
- var container = me.getBoxDrawer().getContainer();
- // If clicked to hide the box drawer
- if(me.getBoxDrawer().isVisible()) {
- var mapImage = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getImageUrl(Lcom/yotta/horizon/mapping/shared/SectionItem;)(me.getFirstItem());
- if(hasDiagram) {
- $wnd.jQuery(me.getPopout()).css({
- backgroundImage : 'url("' + imageUrl + '")'
- });
- } else if(mapImage != null) {
- $wnd.jQuery(me.getPopout()).css({
- backgroundImage : 'url("'+ mapImage +'")',
- backgroundSize : me.isSmall() ? "32px" : "64px"
- });
- }
- if(me.getBoxDrawer().isHorizontalUp()) {
- $wnd.jQuery(container).hide("slide", { direction : "down" }, 250, completeFunction);
- } else if(me.getBoxDrawer().isHorizontalDown()) {
- $wnd.jQuery(container).hide("slide", { direction : "up" }, 250, completeFunction);
- } else if(me.getBoxDrawer().isVerticalLeft()) {
- $wnd.jQuery(container).hide("slide", { direction : "right" }, 250, completeFunction);
- } else if(me.getBoxDrawer().isVerticalRight()) {
- $wnd.jQuery(container).hide("slide", { direction : "left" }, 250, completeFunction);
- }
- for(var i = 0, size = me.getBoxDrawer().getBoxes().length; i < size; i++) {
- var currentBox = me.getBoxDrawer().getBoxes()[i];
- if(currentBox.getSelected()) {
- currentBox.setSelected(false);
- $wnd.google.maps.event.trigger(currentBox.getItem(), 'deselect');
- }
- }
- $wnd.jQuery(me.getPopout()).animate({
- backgroundColor: color,
- borderColor: color
- });
- lastBoxDrawerSelected = null;
- // Clicked to show the box drawer
- } else {
- $wnd.google.maps.event.trigger(me.getElement(), 'mouseover', { cancelItemMouseOver: true } );
- if(me.getBoxDrawer().isHorizontalUp()) {
- $wnd.jQuery(container).css('visibility', 'visible').show().hide().show("slide", { direction : "down" }, 250);
- } else if(me.getBoxDrawer().isHorizontalDown()) {
- $wnd.jQuery(container).css('visibility', 'visible').show().hide().show("slide", { direction : "up" }, 250);
- } else if(me.getBoxDrawer().isVerticalLeft()) {
- $wnd.jQuery(container).css('visibility', 'visible').show().hide().show("slide", { direction : "right" }, 250);
- } else if(me.getBoxDrawer().isVerticalRight()) {
- $wnd.jQuery(container).css('visibility', 'visible').show().hide().show("slide", { direction : "left" }, 250);
- }
- for(var i = 0, size = me.getItems().length; i < size; i++) {
- $wnd.google.maps.event.trigger(me.getItems()[i], 'mouseout', { edge: 0 });
- }
- // Close the last open box drawer if possible
- if(lastBoxDrawerSelected != null
- && lastBoxDrawerSelected != me
- && lastBoxDrawerSelected.getBoxDrawer().isVisible()) {
- $wnd.google.maps.event.trigger(lastBoxDrawerSelected.getPopout(), 'click');
- }
- if(e && e.zoom) {
- setTimeout(function() {
- $wnd.jQuery(me.getPopout()).css({
- backgroundImage: 'url(images/cross.png)',
- backgroundSize: 'auto',
- backgroundColor: '#cf3f0f',
- borderColor: '#cf3f0f'
- });
- }, 50);
- } else {
- $wnd.jQuery(me.getPopout()).css({backgroundImage: 'url(images/cross.png)', backgroundSize: 'auto'});
- $wnd.jQuery(me.getPopout()).animate({
- backgroundColor: '#cf3f0f',
- borderColor: '#cf3f0f'
- });
- }
- me.setSelected(true);
- }
- // Single element clicked
- } else {
- // Close the last open box drawer if possible
- if(lastBoxDrawerSelected != null
- && lastBoxDrawerSelected != me
- && lastBoxDrawerSelected.getBoxDrawer().isVisible()) {
- $wnd.google.maps.event.trigger(lastBoxDrawerSelected.getPopout(), 'click');
- }
- $wnd.google.maps.event.trigger(me.getFirstItem(), 'click', {
- edge: undefined,
- path: undefined,
- vertex: undefined
- });
- me.setSelected(true);
- }
- });
- // Check if linking chainage items and section items is enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isSectionItemsLinked()()) {
- // Add listener for section item mouseover events incase the user hovers over a section item
- this.createSectionItemListeners(this, this.getFirstItem());
- }
- // Add listener for section item selected events incase the selected item changes
- this.sectionItemSelectedListener_ = $wnd.google.maps.event.addListener(map, 'section_item_selected', function(e) {
- if(lastBoxSelected != null) {
- $wnd.google.maps.event.trigger(lastBoxSelected, 'deselect');
- }
- var match = false;
- for(var i = 0, size = me.getItems().length; i < size; i++) {
- if(me.getItems()[i] == e.item) {
- match = true;
- if(me.getItems().length > 1 && !me.getBoxDrawer().isVisible()) {
- for(var j = 0, s = me.getBoxDrawer().getBoxes().length; j < s; j++) {
- var currentBox = me.getBoxDrawer().getBoxes()[j];
- if(currentBox.getItem() == e.item) {
- $wnd.google.maps.event.trigger(me.getPopout(), 'click');
- currentBox.setSelected(true);
- break;
- }
- }
- }
- break;
- }
- }
- me.setSelected(match);
- });
- // Check if the item is selected?
- for(var i = 0, size = this.getItems().length; i < size; i++) {
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isSectionItemSelected(Lcom/yotta/horizon/mapping/shared/SectionItem;)(this.getItems()[i])) {
- setTimeout(function() { // Needs timeout so it can be attached to the DOM
- me.setSelected(true)
- }, 0);
- }
- }
- };
- // Gets the dom element
- ChainageGroupBox.prototype.getElement = function() {
- return this.element_;
- };
- // Gets the item key
- ChainageGroupBox.prototype.getKey = function() {
- return this.key_;
- };
- // Gets the is small boolean flag
- ChainageGroupBox.prototype.isSmall = function() {
- return this.isSmall_;
- };
- // Gets the dom popout element
- ChainageGroupBox.prototype.getPopout = function() {
- return this.popout_;
- };
- // Gets the direction of the Chainage Group
- ChainageGroupBox.prototype.getDirection = function() {
- return this.direction_;
- };
- // Gets the direction in which section is heading
- ChainageGroupBox.prototype.getSectionHeading = function() {
- return this.sectionHeading_;
- };
- // Gets the first section item
- ChainageGroupBox.prototype.getFirstItem = function() {
- if(this.getItems() != null) {
- return this.getItems()[0];
- }
- return null;
- };
- // Gets the section items
- ChainageGroupBox.prototype.getItems = function() {
- return this.sectionItems_;
- };
- // Add a section item to the array
- ChainageGroupBox.prototype.addItem = function(elbowLatLng, sectionItem) {
- var polyline = null;
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- polyline = new $wnd.google.maps.Polyline($wnd.jQuery.extend({
- map: this.getMap(),
- path: [
- sectionItem.setIcon ? // Marker or polyline/polygon
- sectionItem.getPosition() :
- @com.yotta.horizon.shared.gmaps.MapMath::getNearestLatLngOnPath(Lcom/yotta/horizon/shared/gmaps/MVCArray;Lcom/yotta/horizon/shared/gmaps/LatLng;)(sectionItem.getPath(), elbowLatLng),
- elbowLatLng
- ]
- }, POLYLINE_ITEM_DEFAULT));
- this.getPolylines().push(polyline);
- }
- this.getItems().push(sectionItem);
- // Populate the drawer
- if(this.getBoxDrawer() == null) {
- var boxDrawer = new ChainageGroupBoxDrawer(this.getMap(), this.getFirstItem(), this.getPolylines()[0],
- this.getElbow(), this.getColor(), this.getDirection(),
- this.isSmall(), this.getPopout(), this.getSectionHeading());
- this.setBoxDrawer(boxDrawer);
- }
- this.getBoxDrawer().addItem(sectionItem, polyline);
- this.createSectionItemListeners(this, sectionItem);
- this.setBubbleVisible(true);
- this.setBubbleText(""+this.getItems().length);
- };
- // Creates section item mouseover and mouseout listeners for the given item
- ChainageGroupBox.prototype.createSectionItemListeners = function(me, item) {
- var sectionItemMouseOverListener = $wnd.google.maps.event.addListener(item, 'mouseover', function(e) {
- if(!e.notSimpleEvent && (me.getItems().length == 1 || !me.getBoxDrawer().isVisible() || me.getPopout().style.display == 'none')) {
- $wnd.google.maps.event.trigger(me.getElement(), 'mouseover', {
- cancelItemMouseOver: true,
- item: item
- });
- }
- });
- this.sectionItemMouseOverListeners_.push(sectionItemMouseOverListener);
- var sectionItemMouseOutListener = $wnd.google.maps.event.addListener(item, 'mouseout', function(e) {
- if(me.getItems().length == 1 || !me.getBoxDrawer().isVisible() || me.getPopout().style.display == 'none') {
- $wnd.google.maps.event.trigger(me.getElement(), 'mouseout', {
- cancelItemMouseOut: true,
- item: item
- });
- $wnd.google.maps.event.trigger(me.getPopout(), 'mouseout', {
- stopAnimation: (me.getItems().length > 1 && me.getBoxDrawer().isVisible()) ? false : true
- });
- }
- });
- this.sectionItemMouseOutListeners_.push(sectionItemMouseOutListener);
- };
- // Gets the ChainageGroupBoxDrawer
- ChainageGroupBox.prototype.getBoxDrawer = function() {
- return this.boxDrawer_;
- };
- // Sets the ChainageGroupBoxDrawer
- ChainageGroupBox.prototype.setBoxDrawer = function(boxDrawer) {
- this.boxDrawer_ = boxDrawer;
- };
- // Gets the elbow polyline
- ChainageGroupBox.prototype.getElbow = function() {
- return this.elbowPolyline_;
- };
- // Gets the map
- ChainageGroupBox.prototype.getMap = function() {
- return this.map_;
- };
- // Gets the box drawer
- ChainageGroupBox.prototype.getDrawerElement = function() {
- return this.drawerElement_;
- };
- // Gets the items polylines
- ChainageGroupBox.prototype.getPolylines = function() {
- return this.polylines_;
- };
- // Gets the item counter bubble
- ChainageGroupBox.prototype.getBubble = function() {
- return this.itemCounterBubble_;
- };
- // Gets the popout counter bubble
- ChainageGroupBox.prototype.getPopoutBubble = function() {
- return this.popoutCounterBubble_;
- };
- // Sets the item&popout counter bubble text
- ChainageGroupBox.prototype.setBubbleText = function(text) {
- this.getBubble().innerHTML = text;
- this.getPopoutBubble().innerHTML = text;
- };
- // Sets the background colour
- ChainageGroupBox.prototype.setColor = function(color) {
- this.color_ = color;
- };
- // Gest the background colour
- ChainageGroupBox.prototype.getColor = function() {
- return this.color_;
- };
- // Sets the item & popout counter bubble visibility
- ChainageGroupBox.prototype.setBubbleVisible = function(visible) {
- this.getBubble().style.display = visible ? '' : 'none';
- this.getPopoutBubble().style.display = visible ? '' : 'none';
- if (visible) {
- this.getBubble().removeAttribute('aria-hidden');
- this.getPopoutBubble().removeAttribute('aria-hidden');
- } else {
- this.getBubble().setAttribute('aria-hidden', 'true');
- this.getPopoutBubble().setAttribute('aria-hidden', 'true');
- }
- };
- // Gets whether the item is selected
- ChainageGroupBox.prototype.getSelected = function() {
- return this.selected_;
- };
- // Sets whether the item is selected
- ChainageGroupBox.prototype.setSelected = function(selected) {
- var performUpdate = selected != this.selected_; // Flag to determine if update is required
- this.selected_ = selected;
- if(performUpdate) {
- if(selected) {
- lastBoxSelected = this;
- if(this.getItems() != null && this.getItems().length > 1) {
- lastBoxDrawerSelected = this;
- }
- $wnd.jQuery(this.getElement()).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemActiveStyleName());
- if(this.getElement()) {
- $wnd.google.maps.event.trigger(this.getElement(), 'mouseover', {
- cancelItemMouseOver: false
- });
- }
- } else {
- if(lastBoxSelected == this) {
- lastBoxSelected = null;
- }
- if(lastBoxDrawerSelected == this) {
- lastBoxDrawerSelected = null;
- }
- $wnd.jQuery(this.getElement()).removeClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemActiveStyleName());
- if(this.getElement()) {
- $wnd.google.maps.event.trigger(this.getElement(), 'mouseout', {
- cancelItemMouseOut: false,
- stopAnimation: false
- });
- }
- if(this.getPopout()) {
- $wnd.google.maps.event.trigger(this.getPopout(), 'mouseout', {
- stopAnimation: false
- });
- }
- }
- }
- };
- // Dispose of the box and remove it
- ChainageGroupBox.prototype.dispose = function() {
- // Remove listeners
- $wnd.google.maps.event.removeListener(this.elementMouseOverListener_);
- $wnd.google.maps.event.removeListener(this.elementMouseOutListener_);
- $wnd.google.maps.event.removeListener(this.popoutMouseOutListener_);
- $wnd.google.maps.event.removeListener(this.popoutBubbleMouseOutListener_);
- $wnd.google.maps.event.removeListener(this.popoutClickListener_);
- $wnd.google.maps.event.removeListener(this.sectionItemSelectedListener_);
- // Check if linking chainage items and section items is enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isSectionItemsLinked()()) {
- for(var i = 0, size = this.getItems().length; i < size; i++) {
- $wnd.google.maps.event.removeListener(this.sectionItemMouseOutListeners_[i]);
- $wnd.google.maps.event.removeListener(this.sectionItemMouseOverListeners_[i]);
- }
- }
- // Hide the item polyline if enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- for(var i = 0, size = this.getPolylines().length; i < size; i++) {
- this.getPolylines()[i].setMap(null);
- }
- }
- if(this.getItems().length > 1) {
- this.getBoxDrawer().dispose();
- }
- // Remove the element
- if(this.getElement().parentNode) {
- this.getElement().parentNode.removeChild(this.getElement());
- }
- // Remove pointer to last box selected if required
- if(lastBoxSelected == this) {
- lastBoxSelected = null;
- }
- if(lastBoxDrawerSelected == this) {
- lastBoxDrawerSelected = null;
- }
- this.elementMouseOverListener_ = null;
- this.elementMouseOutListener_ = null;
- this.popoutMouseOutListener_ = null;
- this.popoutBubbleMouseOutListener_ = null;
- this.popoutClickListener_ = null;
- this.sectionItemChangedListener_ = null;
- this.sectionItemMouseOutListeners_ = null;
- this.sectionItemMouseOverListeners_ = null;
- this.selected_ = null;
- this.elbowPolyline_ = null;
- this.element_ = null;
- this.sectionItems_ = null;
- this.polylines_ = null;
- this.maps_ = null;
- this.itemCounterBubble_ = null;
- this.boxDrawer_ = null;
- };
- // Method raised when the item container is moused over
- var lastItemMousedOver = null;
- var itemContainerMouseOver = function(e) {
- if(lastItemMousedOver) {
- lastItemMousedOver.style.zIndex = null;
- }
- this.style.zIndex = 1000;
- lastItemMousedOver = this;
- // Stop polylines and markers from mousing over
- e.cancelBubble = true;
- if(e.stopPropagation) {
- e.stopPropagation();
- }
- };
- var itemContainerCancel = function(e) {
- // Stop polylines and markers from mousing over
- e.cancelBubble = true;
- if(e.stopPropagation) {
- e.stopPropagation();
- }
- };
- // CONSTRUCTOR ChainageGroupBoxSimple
- // Simple Section Item box that represents an item inside the drawer
- var ChainageGroupBoxSimple = function(map, sectionItem, polyline, elbow, color, isSmall) {
- var me = this; //self reference
- this.map_ = map;
- this.sectionItem_ = sectionItem;
- this.element_ = $doc.createElement('div');
- this.popout_ = $doc.createElement('div');
- this.polyline_ = polyline;
- this.elbow_ = elbow;
- this.selected_ = false;
- this.isSmall_ = isSmall;
- this.elementMouseOverListener_ = null;
- this.elementMouseOutListener_ = null;
- this.popoutMouseOutListener_ = null;
- this.popoutClickListener_ = null;
- this.sectionItemMouseOutListener_ = null;
- this.sectionItemMouseOverListener_ = null;
- this.sectionItemSelectedListener_ = null;
- // Setup element
- var element = this.getElement();
- element.style.width = isSmall ? '16px' : '32px';
- element.style.height = isSmall ? '16px' : '32px';
- element.style.backgroundColor = color;
- var mapImage;
- var hasDiagram = @com.yotta.horizon.mapping.shared.SectionItemUtils::getSectionItemDiagramId(Lcom/yotta/horizon/mapping/shared/SectionItem;)(this.getItem()) != null;
- if(hasDiagram) {
- mapImage = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getCropUrl(Lcom/yotta/horizon/mapping/shared/SectionItem;)(this.getItem());
- } else {
- mapImage = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getImageUrl(Lcom/yotta/horizon/mapping/shared/SectionItem;)(this.getItem());
- }
- if(mapImage != null) {
- element.style.background = color + " url('" + mapImage + "') no-repeat center center";
- element.style.backgroundSize = isSmall ? "16px" : "32px";
- }
- element.style.position = 'relative';
- $wnd.jQuery(element).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemStyleName());
- if(isSmall) {
- $wnd.jQuery(element).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemSmallStyleName());
- }
- // Setup popout
- var popout = this.getPopout();
- popout.style.width = isSmall ? '16px' : '32px';
- popout.style.height = isSmall ? '16px' : '32px';
- popout.style.backgroundColor = color;
- popout.style.position = 'relative';
- popout.style.borderColor = color;
- $wnd.jQuery(popout).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemPopoutStyleName());
- element.appendChild(popout);
- // Add listener for mouse over to highlight the path to the item
- this.elementMouseOverListener_ = $wnd.google.maps.event.addDomListener(element, 'mouseover', function(e) {
- // Highlight path if enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- me.getPolyline().setOptions(POLYLINE_ITEM_ACTIVE);
- me.getElbow().setOptions(POLYLINE_ELBOW_ACTIVE);
- }
- // Add hovered class
- $wnd.jQuery(me.getElement()).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemHoveredStyleName());
- // Highlight the item
- if(!e.cancelItemMouseOver) {
- // Pass edge as fix for editable polylines which cause issues if an empty object is passed
- $wnd.google.maps.event.trigger(me.getItem(), 'mouseover', { edge: 0 });
- }
- // If there is a diagram begin loading it
- var jqPopout = $wnd.jQuery(popout);
- var mapImage = @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getImageUrl(Lcom/yotta/horizon/mapping/shared/SectionItem;)(me.getItem());
- jqPopout.empty().css({
- backgroundImage: "url('" + mapImage + "')",
- backgroundSize: me.isSmall() ? "32px" : "64px"
- });
- // Show popout
- jqPopout.stop(true).show().animate({
- width: isSmall ? '32px' : '64px',
- height: isSmall ? '32px' : '64px',
- top: isSmall ? '-8px' : '-16px',
- left: isSmall ? '-8px' : '-16px',
- opacity: 1
- }, 400, 'easeOutExpo');
- // Trigger hover
- if(itemHoverThrottle) {
- clearTimeout(itemHoverThrottle);
- itemHoverThrottle = null;
- }
- if(!e.manual) {
- itemHoverThrottle = setTimeout(function() {
- if(me.getItem()) {
- $wnd.google.maps.event.trigger(me.getItem(), 'hover', { over: true });
- }
- }, 50);
- }
- });
- // Add listener for mouse out to unhighlight the path to the item
- this.elementMouseOutListener_ = $wnd.google.maps.event.addDomListener(element, 'mouseout', function(e) {
- // Dont animate if selected
- if(me.getSelected()) {
- return;
- }
- // Reset polyline if enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- me.getPolyline().setOptions(POLYLINE_ITEM_DEFAULT);
- // Only unhighlight the elbow if it is not the same reference elbow as the current item
- if(!lastBoxSelected || lastBoxSelected.getElbow() != me.getElbow()) {
- me.getElbow().setOptions(POLYLINE_ELBOW_DEFAULT);
- }
- }
- if(!e.cancelItemMouseOut) {
- // Pass edge as fix for editable polylines which cause issues if an empty object is passed
- $wnd.google.maps.event.trigger(me.getItem(), 'mouseout', { edge: 0 });
- }
- // Remove hovered class
- $wnd.jQuery(me.getElement()).removeClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemHoveredStyleName());
- // Trigger hover
- if(itemHoverThrottle) {
- clearTimeout(itemHoverThrottle);
- itemHoverThrottle = null;
- }
- if(!e.manual) {
- itemHoverThrottle = setTimeout(function() {
- $wnd.google.maps.event.trigger(me.getItem(), 'hover', { over: false });
- }, 50);
- }
- });
- // Add listener for popout mouseout to remove popout
- this.popoutMouseOutListener_ = $wnd.google.maps.event.addDomListener(popout, 'mouseout', function() {
- // Dont animate if selected
- if(me.getSelected()) {
- return;
- }
- $wnd.jQuery(popout).stop(true).animate({
- width: isSmall ? '16px' : '32px',
- height: isSmall ? '16px' : '32px',
- top: '0px',
- left: '0px',
- opacity: 0
- }, 200, 'easeOutExpo', function() {
- $wnd.jQuery(popout).hide();
- });
- });
- /// Add listener for selection of the popout image
- this.popoutClickListener_ = $wnd.google.maps.event.addDomListener(popout, 'click', function() {
- $wnd.google.maps.event.trigger(me.getItem(), 'click', {
- edge: undefined,
- path: undefined,
- vertex: undefined
- });
- });
- // Check if linking chainage items and section items is enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isSectionItemsLinked()()) {
- // Add listener for section item mouseover events incase the user hovers over a section item
- this.sectionItemMouseOverListener_ = $wnd.google.maps.event.addDomListener(me.getItem(), 'mouseover', function(e) {
- if(!e.notSimpleEvent) {
- $wnd.google.maps.event.trigger(me.getElement(), 'mouseover', {
- cancelItemMouseOver: true,
- item: me.getItem()
- });
- }
- });
- // Add listener for section item mouseout events incase the user hovers over a section item
- this.sectionItemMouseOutListener_ = $wnd.google.maps.event.addDomListener(me.getItem(), 'mouseout', function(e) {
- if(!e.notSimpleEvent) {
- $wnd.google.maps.event.trigger(me.getElement(), 'mouseout', {
- cancelItemMouseOut: true,
- item: me.getItem()
- });
- $wnd.google.maps.event.trigger(me.getPopout(), 'mouseout');
- }
- });
- }
- // Add listener for section item selected events incase the selected item changes
- this.sectionItemSelectedListener_ = $wnd.google.maps.event.addListener(map, 'section_item_selected', function(e) {
- if(lastBoxSelected != null) {
- $wnd.google.maps.event.trigger(lastBoxSelected, 'deselect');
- }
- if(me.getItem() == e.item && lastBoxDrawerSelected != null) {
- var found = false;
- for(var i = 0, size = lastBoxDrawerSelected.getBoxDrawer().getBoxes().length; i < size; i++) {
- if(me == lastBoxDrawerSelected.getBoxDrawer().getBoxes()[i]) {
- found = true;
- break;
- }
- }
- if(!found && lastBoxDrawerSelected.getBoxDrawer().isVisible()) {
- $wnd.google.maps.event.trigger(lastBoxDrawerSelected.getPopout(), 'click');
- }
- }
- me.setSelected(me.getItem() == e.item);
- });
- // Check if the item is selected?
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isSectionItemSelected(Lcom/yotta/horizon/mapping/shared/SectionItem;)(this.getItem())) {
- setTimeout(function() { // Needs timeout so it can be attached to the DOM
- me.setSelected(true)
- }, 0);
- }
- @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::fireItemReady(IIZ)(this.getItem().renderGroupId, this.getItem().geometry.DSIID, true);
- }
- ChainageGroupBoxSimple.prototype = new $wnd.google.maps.OverlayView();
- // Gets the dom element
- ChainageGroupBoxSimple.prototype.getElement = function() {
- return this.element_;
- };
- // Gets the section item
- ChainageGroupBoxSimple.prototype.getItem = function() {
- return this.sectionItem_;
- };
- // Gets the polyline
- ChainageGroupBoxSimple.prototype.getPolyline = function() {
- return this.polyline_;
- };
- // Gets the polyline elbow
- ChainageGroupBoxSimple.prototype.getElbow = function() {
- return this.elbow_;
- };
- // Gets the popout dom element
- ChainageGroupBoxSimple.prototype.getPopout = function() {
- return this.popout_;
- };
- // Gets the 'is small' boolean flag
- ChainageGroupBoxSimple.prototype.isSmall = function() {
- return this.isSmall_;
- };
- // Gets the 'selected' boolean flag
- ChainageGroupBoxSimple.prototype.getSelected = function() {
- return this.selected_;
- };
- // Sets the 'selected' boolean flag
- ChainageGroupBoxSimple.prototype.setSelected = function(selected) {
- var performUpdate = selected != this.selected_; // Flag to determine if update is required
- this.selected_ = selected;
- if(performUpdate) {
- if(selected) {
- lastBoxSelected = this;
- $wnd.jQuery(this.getElement()).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemActiveStyleName());
- if(this.getElement() != null) {
- $wnd.google.maps.event.trigger(this.getElement(), 'mouseover', {
- cancelItemMouseOver: false
- });
- }
- } else {
- if(lastBoxSelected == this) {
- lastBoxSelected = null;
- }
- $wnd.jQuery(this.getElement()).removeClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupItemActiveStyleName());
- $wnd.google.maps.event.trigger(this.getElement(), 'mouseout', {
- cancelItemMouseOut: false
- });
- $wnd.google.maps.event.trigger(this.getPopout(), 'mouseout');
- }
- }
- };
- // Disposes of this object
- ChainageGroupBoxSimple.prototype.dispose = function() {
- $wnd.google.maps.event.removeListener(this.elementMouseOverListener_);
- $wnd.google.maps.event.removeListener(this.elementMouseOutListener_);
- $wnd.google.maps.event.removeListener(this.popoutMouseOutListener_);
- $wnd.google.maps.event.removeListener(this.popoutClickListener_);
- $wnd.google.maps.event.removeListener(this.sectionItemMouseOutListener_);
- $wnd.google.maps.event.removeListener(this.sectionItemMouseOverListener_);
- $wnd.google.maps.event.removeListener(this.sectionItemSelectedListener_);
- // Remove the element
- if(this.getElement().parentNode) {
- this.getElement().parentNode.removeChild(this.getElement());
- }
- this.getPolyline().setMap(null);
- this.map_ = null;
- this.sectionItem_ = null;
- this.element_ = null;
- this.popout_ = null;
- this.polyline_ = null;
- this.elbow_ = null;
- this.selected_ = null;
- this.isSmall_ = null;
- this.elementMouseOverListener_ = null;
- this.elementMouseOutListener_ = null;
- this.popoutMouseOutListener_ = null;
- this.popoutClickListener_ = null;
- this.sectionItemMouseOutListener_ = null;
- this.sectionItemMouseOverListener_ = null;
- this.sectionItemSelectedListener_ = null;
- };
- ChainageGroupBoxDrawer.prototype = new $wnd.google.maps.OverlayView();
- // CONSTRUCTOR ChainageGroupBoxDrawer
- // Element that slides out of the parent element that contains more than 1 item from the same group
- function ChainageGroupBoxDrawer(map, item, polyline, elbow, color, direction, isSmall, parent, sectionHeading) {
- this.map_ = map;
- this.items_ = [item];
- this.polylines_ = [polyline];
- this.elbow_ = elbow;
- this.color_ = color;
- this.direction_ = direction;
- this.boxes_ = [];
- this.isSmall_ = isSmall;
- this.parent_ = parent;
- this.sectionHeading_ = sectionHeading;
- this.setMap(map);
- };
- // Checks whether the section is heading between the start and the end degrees (0 being North)
- ChainageGroupBoxDrawer.prototype.isSectionHeading = function(start, end) {
- if(this.sectionHeading_ >= start && this.sectionHeading_ <= end) {
- return true;
- }
- return false;
- };
- // Checks whether the section is heading North-West or South-East(from North-West)
- ChainageGroupBoxDrawer.prototype.isSectionHeadingNW = function() {
- if(this.isSectionHeading(90, 179) || this.isSectionHeading(270, 359)) {
- return true;
- }
- return false;
- };
- // Checks whether the chainage group is vertical and the drawer has to slide to the left
- ChainageGroupBoxDrawer.prototype.isVerticalLeft = function() {
- if((this.getDirection() == ChainageGroupDirection.NORTH && !this.isSectionHeadingNW())
- || (this.getDirection() == ChainageGroupDirection.SOUTH && this.isSectionHeadingNW())) {
- return true;
- }
- return false;
- };
- // Checks whether the chainage group is vertical and the drawer has to slide to the right
- ChainageGroupBoxDrawer.prototype.isVerticalRight = function() {
- if((this.getDirection() == ChainageGroupDirection.SOUTH && !this.isSectionHeadingNW())
- || (this.getDirection() == ChainageGroupDirection.NORTH && this.isSectionHeadingNW())) {
- return true;
- }
- return false;
- };
- // Checks whether the chainage group is horizontal and the drawer has to slide up
- ChainageGroupBoxDrawer.prototype.isHorizontalUp = function() {
- if((this.getDirection() == ChainageGroupDirection.WEST && !this.isSectionHeadingNW())
- || (this.getDirection() == ChainageGroupDirection.EAST && this.isSectionHeadingNW())) {
- return true;
- }
- return false;
- };
- // Checks whether the chainage group is horizontal and the drawer has to slide dowp
- ChainageGroupBoxDrawer.prototype.isHorizontalDown = function() {
- if((this.getDirection() == ChainageGroupDirection.EAST && !this.isSectionHeadingNW())
- || (this.getDirection() == ChainageGroupDirection.WEST && this.isSectionHeadingNW())) {
- return true;
- }
- return false;
- };
- // Sets the position at which to draw the drawer
- ChainageGroupBoxDrawer.prototype.draw = function() {
- var offset = (this.getItems().length > MAX_ITEMS_PER_ROW ? '-15' : '10') + '%';
- if(this.isVerticalLeft()) {
- if(this.isSmall()) {
- this.getContainer().style.right = '32px';
- } else {
- this.getContainer().style.right = '65px';
- this.getContainer().style.top = offset;
- }
- } else if(this.isVerticalRight()) {
- if(this.isSmall()) {
- this.getContainer().style.left = '34px';
- } else {
- this.getContainer().style.left = '67px';
- this.getContainer().style.top = offset;
- }
- } else if(this.isHorizontalDown()) {
- if(this.isSmall()) {
- this.getContainer().style.top = '34px';
- } else {
- this.getContainer().style.top = '67px';
- this.getContainer().style.left = offset;
- }
- } else if(this.isHorizontalUp()) {
- if(this.isSmall()) {
- this.getContainer().style.bottom = '32px';
- } else {
- this.getContainer().style.bottom = '65px';
- this.getContainer().style.left = offset;
- }
- } else {
- throw "No direction found";
- }
- this.getItemContainer().style.bottom = null;
- this.getItemContainer().style.right = null;
- this.getItemContainer().style.left = '-1px';
- this.getItemContainer().style.top = '-1px';
- this.update();
- };
- // Creates the DOM elements and bubbling listener blockers for the drawer
- ChainageGroupBoxDrawer.prototype.onAdd = function() {
- this.container_ = $doc.createElement('div');
- this.itemContainer_ = $doc.createElement('div');
- // Setup container
- this.getContainer().style.visibility = 'hidden';
- this.getContainer().style.position = 'absolute';
- this.getItemContainer().style.position = 'relative';
- // Setup the item container
- $wnd.jQuery(this.getItemContainer()).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupStyleName());
- this.getContainer().appendChild(this.getItemContainer());
- // Setup listener to move panel to front
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mouseover', itemContainerMouseOver);
- // Setup listeners to stop underlying polylines from mousing over
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'click', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'dblclick', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'rightclick', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mousedown', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mouseup', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mousemove', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mouseout', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mouseenter', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mouseleave', itemContainerCancel);
- this.parent_.appendChild(this.container_);
- };
- // Gets the background colour
- ChainageGroupBoxDrawer.prototype.getColor = function() {
- return this.color_;
- };
- // Creates the table to hold the items and populates it
- ChainageGroupBoxDrawer.prototype.update = function() {
- if(this._cacheItemsCount === this.getItems().length) {
- return;
- }
- this._cacheItemsCount = this.getItems().length;
- // Empty the item container
- this.clearItemContainer();
- // Create the items
- for(var i = 0, size = this.getItems().length; i < size; i++) {
- var item = this.getItems()[i];
- var polyline = this.getPolylines()[i];
- var box = new ChainageGroupBoxSimple(this.getMap(), item, polyline, this.getElbow(), this.getColor(), this.isSmall());
- // Add to array
- this.getBoxes().push(box);
- }
- if(this.getItems().length > 1) {
- // Create the container table
- var table = $doc.createElement('table');
- var direction = this.getDirection();
- if(direction == ChainageGroupDirection.NORTH || direction == ChainageGroupDirection.SOUTH) {
- // Setup class name
- $wnd.jQuery(this.getItemContainer()).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupHorizontalStyleName());
- // Create horizontal list of items
- var row;
- for(var i = 0, s = this.getBoxes().length; i < s; i++) {
- if(i % MAX_ITEMS_PER_ROW == 0) {
- if(row != null) {
- table.appendChild(row);
- }
- row = $doc.createElement('tr');
- }
- var cell = $doc.createElement('td');
- cell.appendChild(this.getBoxes()[i].getElement());
- row.appendChild(cell);
- }
- table.appendChild(row);
- } else if(direction == ChainageGroupDirection.EAST || direction == ChainageGroupDirection.WEST) {
- // Remove class name
- $wnd.jQuery(this.getItemContainer()).removeClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupHorizontalStyleName());
- // Create vertical list of items
- var rows = [];
- for(var i = 0, s = $wnd.Math.min(this.getBoxes().length, MAX_ITEMS_PER_ROW); i < s; i++) {
- var row = $doc.createElement('tr');
- rows.push(row);
- table.appendChild(row);
- }
- for(var i = 0, s = this.getBoxes().length; i < s; i++) {
- var row = rows[i % MAX_ITEMS_PER_ROW];
- var cell = $doc.createElement('td');
- cell.appendChild(this.getBoxes()[i].getElement());
- row.appendChild(cell);
- }
- } else {
- throw "Direction not handled";
- }
- this.getItemContainer().appendChild(table);
- }
- };
- // Gets the 'is small' boolean flag
- ChainageGroupBoxDrawer.prototype.isSmall = function() {
- return this.isSmall_;
- };
- // Adds item to the drawer
- ChainageGroupBoxDrawer.prototype.addItem = function(item, polyline) {
- this.getItems().push(item);
- this.getPolylines().push(polyline);
- };
- // Gets the polylines array for the items
- ChainageGroupBoxDrawer.prototype.getPolylines = function() {
- return this.polylines_;
- };
- // Gets the polyline elbow
- ChainageGroupBoxDrawer.prototype.getElbow = function() {
- return this.elbow_;
- };
- // Gets the map object
- ChainageGroupBoxDrawer.prototype.getMap = function() {
- return this.map_;
- };
- // Gets the DOM container
- ChainageGroupBoxDrawer.prototype.getContainer = function() {
- return this.container_;
- };
- // Shows the Drawer container
- ChainageGroupBoxDrawer.prototype.show = function() {
- if(this.getContainer() != null) {
- this.getContainer().style.visibility = 'visible';
- }
- };
- // Hides the drawer container
- ChainageGroupBoxDrawer.prototype.hide = function() {
- if(this.getContainer() != null) {
- this.getContainer().style.visibility = 'hidden';
- }
- };
- // Checks whether the drawer is visible (does not check the parent)
- ChainageGroupBoxDrawer.prototype.isVisible = function() {
- if(this.getContainer() != null) {
- return this.getContainer().style.visibility == 'visible';
- }
- return false;
- };
- // Gets the DOM item container
- ChainageGroupBoxDrawer.prototype.getItemContainer = function() {
- return this.itemContainer_;
- };
- // Clears the DOM item container
- ChainageGroupBoxDrawer.prototype.clearItemContainer = function() {
- // Remove all items from container (should only be the table)
- if(this.getItemContainer() != null) {
- while(this.getItemContainer().hasChildNodes()) {
- this.getItemContainer().removeChild(this.getItemContainer().firstChild);
- }
- }
- };
- // Gets all section items inside the drawer
- ChainageGroupBoxDrawer.prototype.getItems = function() {
- return this.items_;
- };
- // Gets direction of the chainage group
- ChainageGroupBoxDrawer.prototype.getDirection = function() {
- return this.direction_;
- };
- // Gets boxes that represent items
- ChainageGroupBoxDrawer.prototype.getBoxes = function() {
- return this.boxes_;
- };
- // Disposes of the current element and all child elements
- ChainageGroupBoxDrawer.prototype.dispose = function() {
- $wnd.console.log('ChainageGroupBoxDrawer.dispose()');
- $wnd.console.trace();
- if(this.getItemContainer() != null) {
- $wnd.google.maps.event.clearInstanceListeners(this.getItemContainer());
- }
- for(var i = 0, size = this.getBoxes().length; i < size; i++) {
- this.getBoxes()[i].dispose();
- }
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- for(var i = 0, size = this.getPolylines().length; i < size; i++) {
- this.getPolylines()[i].setMap(null);
- }
- }
- this.clearItemContainer();
- if(this.getContainer() != null && this.getContainer().parentNode) {
- this.getContainer().parentNode.removeChild(this.getContainer());
- }
- this.map_ = null;
- this.items_ = [];
- this.polylines_ = [];
- this.elbow_ = null;
- this.color_ = null;
- this.boxes_ = [];
- this.isSmall_ = null;
- this.sectionHeading_ = null;
- };
- // CONSTRUCTOR SectionItemPresenterChainageGroup
- // Constructor for section item window
- var SectionItemPresenterChainageGroup = function(map, minLevel, maxLevel, lowerChainage, upperChainage, chainagePath, isLeft) {
- this.map_ = map;
- this.chainagePath_ = chainagePath;
- this.minLevel_ = minLevel;
- this.maxLevel_ = maxLevel;
- this.lowerChainage_ = lowerChainage;
- this.upperChainage_ = upperChainage;
- this.isLeft_ = isLeft;
- this.container_ = null;
- this.itemContainer_ = null;
- this.anchorLatLng_ = null;
- this.elbowLatLng_ = null;
- this.anchor_ = null;
- this.direction_ = null;
- this.items_ = {};
- this.boxes_ = [];
- this.polyline_ = new $wnd.google.maps.Polyline($wnd.jQuery.extend({ map: map }, POLYLINE_ELBOW_DEFAULT));
- this.doUpdate_ = true;
- this.sectionHeading_ = null;
- // Show the window
- this.setMap(map);
- };
- // Set to inherit from overlay view
- SectionItemPresenterChainageGroup.prototype = new $wnd.google.maps.OverlayView();
- // Add overlay to map
- SectionItemPresenterChainageGroup.prototype.onAdd = function() {
- this.container_ = $doc.createElement('div');
- this.itemContainer_ = $doc.createElement('div');
- // Setup container
- this.getContainer().style.visibility = 'hidden';
- this.getContainer().style.position = 'absolute';
- // Setup the item container
- $wnd.jQuery(this.getItemContainer()).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupStyleName());
- this.getContainer().appendChild(this.getItemContainer());
- // Setup listener to move panel to front
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mouseover', itemContainerMouseOver);
- // Setup listeners to stop underlying polylines from mousing over
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'click', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'dblclick', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'rightclick', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mousedown', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mouseup', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mousemove', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mouseout', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mouseenter', itemContainerCancel);
- $wnd.google.maps.event.addDomListener(this.getItemContainer(), 'mouseleave', itemContainerCancel);
- // Get the available panes to add to
- this.getPanes().floatPane.appendChild(this.getContainer());
- // Update on next draw
- this.setDoUpdate(true);
- };
- // Reposition and draw the element
- SectionItemPresenterChainageGroup.prototype.draw = function() {
- var projection = this.getProjection();
- // Get start and end line points
- var chainagePathLength = this.getChainagePath().getLength();
- var chainageStartLatLng = this.getChainagePath().getAt(0);
- var chainageEndLatLng = this.getChainagePath().getAt(chainagePathLength - 1);
- var chainageStartPoint = projection.fromLatLngToDivPixel(chainageStartLatLng);
- var chainageEndPoint = projection.fromLatLngToDivPixel(chainageEndLatLng);
- // Get mid point
- var chainageMidPoint = new $wnd.google.maps.Point(
- (chainageStartPoint.x + chainageEndPoint.x) / 2,
- (chainageStartPoint.y + chainageEndPoint.y) / 2);
- // Get heading and adjust according to which side
- var sectionHeading = $wnd.google.maps.geometry.spherical.computeHeading(chainageStartLatLng, chainageEndLatLng);
- sectionHeading = sectionHeading >= 360 ? sectionHeading - 360 : sectionHeading < 0 ? 360 + sectionHeading : sectionHeading;
- var windowHeading = sectionHeading + (this.isLeft() ? -90 : 90);
- windowHeading = windowHeading >= 360 ? windowHeading - 360 : windowHeading < 0 ? 360 + windowHeading : windowHeading;
- var windowHeadingRadians = windowHeading * ($wnd.Math.PI / 180); // Convert to radians
- this.sectionHeading_ = sectionHeading;
- // Calculate offset point
- var offsetPoint = new $wnd.google.maps.Point(
- chainageMidPoint.x + PIXEL_OFFSET * $wnd.Math.sin(windowHeadingRadians),
- chainageMidPoint.y + PIXEL_OFFSET * -$wnd.Math.cos(windowHeadingRadians)
- );
- var offsetLatLng = projection.fromDivPixelToLatLng(offsetPoint);
- this.setAnchorLatLng(offsetLatLng); // Store the anchor lat lng coordinate
- // Calculate offset elbow point if enabled
- var offsetElbowPoint, offsetElbowLatLng;
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- offsetElbowPoint = new $wnd.google.maps.Point(
- chainageMidPoint.x + PIXEL_OFFSET_ELBOW * $wnd.Math.sin(windowHeadingRadians),
- chainageMidPoint.y + PIXEL_OFFSET_ELBOW * -$wnd.Math.cos(windowHeadingRadians)
- );
- offsetElbowLatLng = projection.fromDivPixelToLatLng(offsetElbowPoint);
- this.setElbowLatLng(offsetElbowLatLng); // Store the elbow lat lng coordinate
- }
- // Work out the intersecting perpendicular polyline path segment
- for(var i = 1; i < chainagePathLength; i++) {
- var startLatLng = this.getChainagePath().getAt(i - 1);
- var endLatLng = this.getChainagePath().getAt(i);
- var startPoint = projection.fromLatLngToDivPixel(startLatLng);
- var endPoint = projection.fromLatLngToDivPixel(endLatLng);
- var intersectionPoint = @com.yotta.horizon.shared.gmaps.MapMath::getIntersection(Lcom/yotta/horizon/shared/gmaps/Point;Lcom/yotta/horizon/shared/gmaps/Point;Lcom/yotta/horizon/shared/gmaps/Point;Lcom/yotta/horizon/shared/gmaps/Point;ZZ)(chainageMidPoint, offsetPoint, startPoint, endPoint, true, false);
- if(intersectionPoint != null) {
- // Recalculate the offset and update
- offsetPoint = new $wnd.google.maps.Point(
- offsetPoint.x + (intersectionPoint.x - chainageMidPoint.x),
- offsetPoint.y + (intersectionPoint.y - chainageMidPoint.y)
- );
- offsetLatLng = projection.fromDivPixelToLatLng(offsetPoint);
- this.setAnchorLatLng(offsetLatLng); // Store the anchor lat lng coordinate
- // Recalculate offset elbow and update if enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- offsetElbowPoint = new $wnd.google.maps.Point(
- offsetElbowPoint.x + (intersectionPoint.x - chainageMidPoint.x),
- offsetElbowPoint.y + (intersectionPoint.y - chainageMidPoint.y)
- );
- offsetElbowLatLng = projection.fromDivPixelToLatLng(offsetElbowPoint);
- this.setElbowLatLng(offsetElbowLatLng); // Store the elbow lat lng coordinate
- }
- break;
- }
- }
- // Position container
- this.getContainer().style.left = offsetPoint.x + 'px';
- this.getContainer().style.top = offsetPoint.y + 'px';
- // Get the direction and anchor of the container
- var direction = ChainageGroupDirection.calculate(this.isLeft(), sectionHeading);
- var anchor = ChainageGroupAnchor.calculate(this.isLeft(), sectionHeading);
- this.setDirection(direction); // Store direction
- this.setAnchor(anchor); // Store anchor
- // Change anchor point of child
- if(anchor == ChainageGroupAnchor.TOP_LEFT) {
- this.getItemContainer().style.bottom = null;
- this.getItemContainer().style.right = null;
- this.getItemContainer().style.left = '-1px';
- this.getItemContainer().style.top = '-1px';
- } else if(anchor == ChainageGroupAnchor.TOP_RIGHT) {
- this.getItemContainer().style.bottom = null;
- this.getItemContainer().style.left = null;
- this.getItemContainer().style.right = '-1px';
- this.getItemContainer().style.top = '-1px';
- } else if(anchor == ChainageGroupAnchor.BOTTOM_LEFT) {
- this.getItemContainer().style.top = null;
- this.getItemContainer().style.right = null;
- this.getItemContainer().style.left = '-1px';
- this.getItemContainer().style.bottom = '-1px';
- } else if(anchor == ChainageGroupAnchor.BOTTOM_RIGHT) {
- this.getItemContainer().style.top = null;
- this.getItemContainer().style.left = null;
- this.getItemContainer().style.right = '-1px';
- this.getItemContainer().style.bottom = '-1px';
- } else {
- throw "Anchor position not handled";
- }
- // Update the container items
- this.update();
- };
- // Remove overlay from map
- SectionItemPresenterChainageGroup.prototype.onRemove = function() {
- // Remove the element
- if(this.getContainer() && this.getContainer().parentNode) {
- this.getContainer().parentNode.removeChild(this.getContainer());
- // Remove listener to move panel to front
- $wnd.google.maps.event.clearListeners(this.getItemContainer(), 'mouseover');
- // Remove listeners to stop event propogation to polylines
- $wnd.google.maps.event.clearListeners(this.getItemContainer(), 'click');
- $wnd.google.maps.event.clearListeners(this.getItemContainer(), 'dblclick');
- $wnd.google.maps.event.clearListeners(this.getItemContainer(), 'rightclick');
- $wnd.google.maps.event.clearListeners(this.getItemContainer(), 'mousedown');
- $wnd.google.maps.event.clearListeners(this.getItemContainer(), 'mouseup');
- $wnd.google.maps.event.clearListeners(this.getItemContainer(), 'mousemove');
- $wnd.google.maps.event.clearListeners(this.getItemContainer(), 'mouseout');
- $wnd.google.maps.event.clearListeners(this.getItemContainer(), 'mouseenter');
- $wnd.google.maps.event.clearListeners(this.getItemContainer(), 'mouseleave');
- // Remove all items
- this.clearItemContainer();
- }
- // Destroy elements if enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- this.getPolyline().setMap(null);
- }
- this.container_ = null;
- this.itemContainer_ = null;
- // Destroy global pointer to last moused over
- lastItemMousedOver = null;
- };
- // Method to force update the view
- SectionItemPresenterChainageGroup.prototype.update = function() {
- // Check an update is required
- if(
- //this.getDoUpdate() == false ||
- this.getMap() == null ||
- this.getContainer() == null || this.getItemContainer() == null) {
- return;
- }
- // Check we can show at this level and we have items
- var zoomLevel = this.getMap().getZoom();
- var itemsCount = this.getItemsCount();
- if(zoomLevel < this.getMinLevel() || zoomLevel > this.getMaxLevel() || itemsCount == 0) {
- this.getContainer().style.visibility = 'hidden';
- // TODO hide the inner polylines and objects
- for(var i = 0, s = this.getBoxes().length; i < s; i++) {
- var box = this.getBoxes()[i];
- box.getElbow().setMap(null);
- for(var j = 0, k = box.getPolylines().length; j < k; j++) {
- var polyline = box.getPolylines()[j];
- polyline.setMap(null);
- }
- //for(var c = 0, d = box.getBoxes().length; c < d; c++) {
- // var innerBox = box.getBoxes()[c];
- // for(var p = 0, q = innerBox.getPolylines().length; p < q; p++) {
- // var polyline = innerBox.getPolylines()[p];
- // polyline.setMap(null);
- // }
- //}
- }
- // Hide if enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- this.getPolyline().setMap(null);
- }
- //this.clearItemContainer(); // Empty the item container
- return;
- } else {
- this.getContainer().style.visibility = 'visible';
- for(var i = 0, s = this.getBoxes().length; i < s; i++) {
- var box = this.getBoxes()[i];
- box.getElbow().setMap(this.map_);
- for(var j = 0, k = box.getPolylines().length; j < k; j++) {
- var polyline = box.getPolylines()[j];
- polyline.setMap(this.map_);
- }
- //for(var c = 0, d = box.getBoxes().length; c < d; c++) {
- // var innerBox = box.getBoxes()[c];
- // for(var p = 0, q = innerBox.getPolylines().length; p < q; p++) {
- // var polyline = innerBox.getPolylines()[p];
- // polyline.setMap(this.map_);
- // }
- //}
- }
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- this.getPolyline().setMap(this.map_);
- }
- // TODO make visible the inner polylines and objects
- }
- // Update polyline to point from offset mid point to box if enabled
- if(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::isElbowEnabled()()) {
- this.getPolyline().setPath([this.getElbowLatLng(), this.getAnchorLatLng()]);
- this.getPolyline().setMap(this.getMap());
- this.getPolyline().setOptions(POLYLINE_ELBOW_DEFAULT);
- }
- if(this._cacheItemsCount === itemsCount) {
- return;
- }
- this._cacheItemsCount = itemsCount;
- // Empty the item container
- this.clearItemContainer();
- // Count different item types to see how many boxes need to be created
- var codeList = [];
- for(var itemKey in this.getItems()) {
- var item = this.getItems()[itemKey];
- var itemCode = item.renderGroupId + "," + item.geometry.ISID + "," + item.geometry.DiagId;
- if($wnd.jQuery.inArray(itemCode, codeList)) {
- continue;
- }
- codeList.push(itemCode);
- }
- // Create the items
- for(var itemKey in this.getItems()) {
- var item = this.getItems()[itemKey];
- var found = false;
- for(var i = 0, size = this.getBoxes().length; i < size; i++) {
- var currentBox = this.getBoxes()[i];
- var currentItem = currentBox.getItems()[0];
- if(item.renderGroupId == currentItem.renderGroupId
- && item.geometry.ISID == currentItem.geometry.ISID
- && item.geometry.DiagId == currentItem.geometry.DiagId) {
- currentBox.addItem(this.getElbowLatLng(), item);
- found = true;
- break;
- }
- }
- if(!found) {
- var box = new ChainageGroupBox(this.getMap(), this.getPolyline(), this.getElbowLatLng(), item, itemKey, codeList.length > 6, this.getDirection(), this.getSectionHeading());
- // Add to array
- this.getBoxes().push(box);
- }
- }
- // Create the container table
- var table = $doc.createElement('table');
- var direction = this.getDirection();
- if(direction == ChainageGroupDirection.EAST || direction == ChainageGroupDirection.WEST) {
- // Setup class name
- $wnd.jQuery(this.getItemContainer()).addClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupHorizontalStyleName());
- // Create horizontal list of items
- var row;
- for(var i = 0, s = this.getBoxes().length; i < s; i++) {
- if(i % MAX_ITEMS_PER_ROW == 0) {
- if(row != null) {
- table.appendChild(row);
- }
- row = $doc.createElement('tr');
- }
- var cell = $doc.createElement('td');
- cell.appendChild(this.getBoxes()[i].getElement());
- row.appendChild(cell);
- }
- table.appendChild(row);
- } else if(direction == ChainageGroupDirection.NORTH || direction == ChainageGroupDirection.SOUTH) {
- // Setup class name
- $wnd.jQuery(this.getItemContainer()).removeClass(@com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::getChainageGroupHorizontalStyleName());
- // Create vertical list of items
- var rows = [];
- for(var i = 0, s = $wnd.Math.min(this.getBoxes().length, MAX_ITEMS_PER_ROW); i < s; i++) {
- var row = $doc.createElement('tr');
- rows.push(row);
- table.appendChild(row);
- }
- for(var i = 0, s = this.getBoxes().length; i < s; i++) {
- var row = rows[i % MAX_ITEMS_PER_ROW];
- var cell = $doc.createElement('td');
- cell.appendChild(this.getBoxes()[i].getElement());
- row.appendChild(cell);
- }
- } else {
- throw "Direction not handled";
- }
- this.getItemContainer().appendChild(table);
- // Show container
- this.getContainer().style.visibility = 'visible';
- for(var i = 0, size = this.getBoxes().length; i < size; i++) {
- var currentBox = this.getBoxes()[i];
- for(var j = 0, boxSize = currentBox.getItems().length; j < boxSize; j++) {
- var item = currentBox.getItems()[j];
- @com.yotta.horizon.mapping.presenters.SectionItemPresenterChainageGroup::fireItemReady(IIZ)(item.renderGroupId, item.geometry.DSIID, false);
- }
- }
- };
- // Method to add an item to the window, draw must be called
- // to update the window and position the items
- SectionItemPresenterChainageGroup.prototype.addItem = function(item) {
- if(this.containsItem(item)) {
- return; // Cannot add again
- }
- var key = @com.yotta.horizon.mapping.shared.SectionItemMap::getKey(Lcom/yotta/horizon/mapping/shared/SectionItem;)(item);
- this.items_[key] = item;
- // Update on next draw
- this.setDoUpdate(true);
- };
- // Method to remove an item from the window, draw must be called
- // to update the window and position the items
- SectionItemPresenterChainageGroup.prototype.removeItem = function(item) {
- if(this.containsItem(item) == false) {
- return; // Cannot remove if not in map
- }
- var key = @com.yotta.horizon.mapping.shared.SectionItemMap::getKey(Lcom/yotta/horizon/mapping/shared/SectionItem;)(item);
- delete this.items_[key];
- // Update on next draw
- this.setDoUpdate(true);
- };
- // Method to remove all items from the window, draw must be called
- // to update the window and position the items
- SectionItemPresenterChainageGroup.prototype.clearItems = function() {
- this.items_ = {};
- // Update on next draw
- this.setDoUpdate(true);
- };
- // Gets the section items currently being displayed
- SectionItemPresenterChainageGroup.prototype.getItems = function() {
- return this.items_;
- };
- // Gets the number of items currently in the map
- SectionItemPresenterChainageGroup.prototype.getItemsCount = function() {
- var count = 0;
- for(var k in this.items_) {
- if(this.items_.hasOwnProperty(k)) {
- ++count;
- }
- }
- return count;
- };
- // Gets whether to perform a ui update on next draw
- SectionItemPresenterChainageGroup.prototype.getDoUpdate = function() {
- return this.doUpdate_;
- };
- SectionItemPresenterChainageGroup.prototype.getSectionHeading = function() {
- return this.sectionHeading_;
- };
- // Sets whether to perform a ui update on next draw
- SectionItemPresenterChainageGroup.prototype.setDoUpdate = function(doUpdate) {
- this.doUpdate_ = doUpdate;
- };
- // Gets whether the window contains a section item
- SectionItemPresenterChainageGroup.prototype.containsItem = function(item) {
- var key = @com.yotta.horizon.mapping.shared.SectionItemMap::getKey(Lcom/yotta/horizon/mapping/shared/SectionItem;)(item);
- return key in this.items_;
- };
- // Gets the chainage path
- SectionItemPresenterChainageGroup.prototype.getChainagePath = function() {
- return this.chainagePath_;
- };
- // Gets whether the window sits on the left or right
- SectionItemPresenterChainageGroup.prototype.isLeft = function() {
- return this.isLeft_;
- };
- // Gets the container for the window
- SectionItemPresenterChainageGroup.prototype.getContainer = function() {
- return this.container_;
- };
- // Gets the container for section items
- SectionItemPresenterChainageGroup.prototype.getItemContainer = function() {
- return this.itemContainer_;
- };
- // Gets the polyline that joins the box to the origin
- SectionItemPresenterChainageGroup.prototype.getPolyline = function() {
- return this.polyline_;
- };
- // Gets the anchor points lat lng coordinate
- SectionItemPresenterChainageGroup.prototype.getAnchorLatLng = function() {
- return this.anchorLatLng_;
- };
- // Sets the anchor points lat lng coordinate
- SectionItemPresenterChainageGroup.prototype.setAnchorLatLng = function(latLng) {
- this.anchorLatLng_ = latLng;
- // Update on next draw
- this.setDoUpdate(true);
- };
- // Gets the elbow points lat lng coordinate
- SectionItemPresenterChainageGroup.prototype.getElbowLatLng = function() {
- return this.elbowLatLng_;
- };
- // Sets the elbow points lat lng coordinate
- SectionItemPresenterChainageGroup.prototype.setElbowLatLng = function(latLng) {
- this.elbowLatLng_ = latLng;
- // Update on next draw
- this.setDoUpdate(true);
- };
- // Gets the anchor enumeration
- SectionItemPresenterChainageGroup.prototype.getAnchor = function() {
- return this.anchor_;
- };
- // Sets the anchor enumeration
- SectionItemPresenterChainageGroup.prototype.setAnchor = function(anchor) {
- this.anchor_ = anchor;
- // Update on next draw
- this.setDoUpdate(true);
- };
- // Gets the direction enumeration
- SectionItemPresenterChainageGroup.prototype.getDirection = function() {
- return this.direction_;
- };
- // Sets the direction enumeration
- SectionItemPresenterChainageGroup.prototype.setDirection = function(direction) {
- this.direction_ = direction;
- // Update on next draw
- this.setDoUpdate(true);
- };
- // Gets the box instances
- SectionItemPresenterChainageGroup.prototype.getBoxes = function() {
- return this.boxes_;
- };
- // Gets the min zoom range the window displays for
- SectionItemPresenterChainageGroup.prototype.getMinLevel = function() {
- return this.minLevel_;
- };
- // Gets the max zoom ranget the window displays for
- SectionItemPresenterChainageGroup.prototype.getMaxLevel = function() {
- return this.maxLevel_;
- };
- // Gets the lower chainage value of the path
- SectionItemPresenterChainageGroup.prototype.getLowerChainage = function() {
- return this.lowerChainage_;
- };
- // Gets the upper chainage value of the path
- SectionItemPresenterChainageGroup.prototype.getUpperChainage = function() {
- return this.upperChainage_;
- };
- // Method to clear the item container of all elements
- SectionItemPresenterChainageGroup.prototype.clearItemContainer = function() {
- // Unset all items (unset variables where necessary)
- for(var i = 0, s = this.getBoxes().length; i < s; i++) {
- this.getBoxes()[i].dispose();
- }
- // Reset boxes
- this.boxes_ = [];
- // Remove all items from container (should only be the table)
- while(this.getItemContainer().hasChildNodes()) {
- this.getItemContainer().removeChild(this.getItemContainer().firstChild);
- }
- };
- // Dispose of the control
- SectionItemPresenterChainageGroup.prototype.dispose = function() {
- this.setMap(null);
- this.map_ = null;
- this.chainagePath_ = null;
- this.minLevel_ = null;
- this.maxLevel_ = null;
- this.lowerChainage_ = null;
- this.upperChainage_ = null;
- this.isLeft_ = null;
- this.container_ = null;
- this.itemContainer_ = null;
- this.anchorLatLng_ = null;
- this.elbowLatLng_ = null;
- this.anchor_ = null;
- this.direction_ = null;
- this.items_ = null;
- this.boxes_ = null;
- this.polyline_ = null;
- };
- return SectionItemPresenterChainageGroup;
- }-*/;
- /**
- * Checks whether section items are styled and whether they listen to
- * mouseover/out events
- * @return a flag indicating whether to style section items
- */
- private static final boolean isSectionItemsLinked() {
- return HorizonConfigFlags.INSTANCE.stylesSectionItems();
- }
- /**
- * Checks whether the elbow drawing routine is enabled
- * @return a flag indicating if the polylines joining items to chaninage
- * groups are enabled
- */
- private static final boolean isElbowEnabled() {
- return HorizonConfigFlags.INSTANCE.stylesElbow();
- }
- /**
- * Checks whether a section item is selected
- * @param item the item to check
- * @return a flag indicating selecetion
- */
- private static final boolean isSectionItemSelected(SectionItem item) {
- return item.isSelected();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement