001 /*
002 * Apache License
003 * Version 2.0, January 2004
004 * http://www.apache.org/licenses/
005 *
006 * Copyright 2008-2010 by chenillekit.org
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 */
014
015 package org.chenillekit.tapestry.core.components.google;
016
017 import org.apache.tapestry5.BindingConstants;
018 import org.apache.tapestry5.ClientElement;
019 import org.apache.tapestry5.ComponentResources;
020 import org.apache.tapestry5.annotations.Component;
021 import org.apache.tapestry5.annotations.Environmental;
022 import org.apache.tapestry5.annotations.Parameter;
023 import org.apache.tapestry5.ioc.annotations.Inject;
024 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
025 import org.chenillekit.tapestry.core.components.Hidden;
026
027 /**
028 * A GMarker marks a position on a (GPlotter) map.
029 * A marker object has a latitude (lat) and a longitude (lng), which is the geographical position where the marker is
030 * anchored on the map.
031 * The default icon G_DEFAULT_ICON is used to display the GMarker. @todo: implement GIcon
032 */
033 public class GMarker implements ClientElement
034 {
035
036 /**
037 * The id used to generate a page-unique client-side identifier for the component. If a component renders multiple
038 * times, a suffix will be appended to the to id to ensure uniqueness.
039 */
040 @Parameter(value = "prop:componentResources.id", defaultPrefix = BindingConstants.LITERAL)
041 private String clientId;
042
043 /**
044 * RenderSupport to get unique client side id.
045 */
046 @Environmental
047 private JavaScriptSupport javascriptSupport;
048
049 @Inject
050 private ComponentResources resources;
051
052 @Parameter(defaultPrefix = BindingConstants.LITERAL, allowNull = false)
053 private String gPlotterId;
054
055 /**
056 * The latitude coordinate in degrees, as a number between -90 and +90
057 */
058 @Parameter(defaultPrefix = BindingConstants.LITERAL, allowNull = false)
059 private Double lat;
060
061 /**
062 * The longitude coordinate in degrees, as a number between -180 and +180
063 */
064 @Parameter(defaultPrefix = BindingConstants.LITERAL, allowNull = false)
065 private Double lng;
066
067 /**
068 * Enables the marker to be dragged and dropped around the map
069 */
070 @Parameter(defaultPrefix = BindingConstants.LITERAL, value = "false")
071 private Boolean draggable;
072
073 /**
074 * The content of the info window is given as a string that contains HTML text.
075 */
076 @Parameter(defaultPrefix = BindingConstants.LITERAL)
077 private String infoWindowHtml;
078
079 @Component(parameters = {"value=inherit:lat"})
080 private Hidden hiddenLat;
081
082 @Component(parameters = {"value=inherit:lng"})
083 private Hidden hiddenLng;
084
085 private String assignedClientId;
086
087 void setupRender()
088 {
089 assignedClientId = javascriptSupport.allocateClientId(clientId);
090 }
091
092 void afterRender()
093 {
094 javascriptSupport.addScript("%s.setMarker(%s, %s, '%s','%s','%s',%s);", gPlotterId, lat, lng,
095 resources.isBound("infoWindowHtml") ? infoWindowHtml : "", hiddenLat.getClientId(),
096 hiddenLng.getClientId(), draggable);
097 }
098
099 /**
100 * Returns a unique id for the element. This value will be unique for any given rendering of a
101 * page. This value is intended for use as the id attribute of the client-side element, and will
102 * be used with any DHTML/Ajax related JavaScript.
103 */
104 public String getClientId()
105 {
106 return assignedClientId;
107 }
108
109 public Boolean getDraggable()
110 {
111 return draggable;
112 }
113
114 }