001 package com.google.gwt.maps.client.streetview;
002
003 import com.google.gwt.core.client.JavaScriptObject;
004 import com.google.gwt.core.client.JsArray;
005 import com.google.gwt.dom.client.Element;
006 import com.google.gwt.event.shared.HandlerRegistration;
007 import com.google.gwt.maps.client.base.LatLng;
008 import com.google.gwt.maps.client.events.MapEventType;
009 import com.google.gwt.maps.client.events.MapHandlerRegistration;
010 import com.google.gwt.maps.client.events.closeclick.CloseClickEventFormatter;
011 import com.google.gwt.maps.client.events.closeclick.CloseClickMapHandler;
012 import com.google.gwt.maps.client.events.links.LinksChangeEventFormatter;
013 import com.google.gwt.maps.client.events.links.LinksChangeMapHandler;
014 import com.google.gwt.maps.client.events.pano.PanoChangeEventFormatter;
015 import com.google.gwt.maps.client.events.pano.PanoChangeMapHandler;
016 import com.google.gwt.maps.client.events.position.PositionChangeEventFormatter;
017 import com.google.gwt.maps.client.events.position.PositionChangeMapHandler;
018 import com.google.gwt.maps.client.events.pov.PovChangeEventFormatter;
019 import com.google.gwt.maps.client.events.pov.PovChangeMapHandler;
020 import com.google.gwt.maps.client.events.resize.ResizeEventFormatter;
021 import com.google.gwt.maps.client.events.resize.ResizeMapHandler;
022 import com.google.gwt.maps.client.events.visible.VisibleChangeEventFormatter;
023 import com.google.gwt.maps.client.events.visible.VisibleChangeMapHandler;
024 import com.google.gwt.maps.client.mvc.MVCArray;
025 import com.google.gwt.maps.client.mvc.MVCObject;
026 import com.google.gwt.maps.client.workaround.WorkAroundUtils;
027
028 /**
029 * Displays the panorama for a given LatLng or panorama ID. A StreetViewPanorama object provides a Street View "viewer" which can be stand-alone within a separate <code><div></code> or bound to a Map. This class extends MVCObject.
030 * <br><br>
031 * See <a href="https://developers.google.com/maps/documentation/javascript/reference#StreetViewPanorama">StreetViewPanorama API Doc</a>
032 */
033 public class StreetViewPanoramaImpl extends MVCObject<StreetViewPanoramaImpl> {
034
035 /**
036 * Displays the panorama for a given LatLng or panorama ID. A StreetViewPanorama object provides a Street View "viewer" which can be stand-alone within a separate <code><div></code> or bound to a Map. This class extends MVCObject.
037 * use newInstance();
038 */
039 protected StreetViewPanoramaImpl() {}
040
041 /**
042 * creates Displays the panorama for a given LatLng or panorama ID. A StreetViewPanorama object provides a Street View "viewer" which can be stand-alone within a separate <code><div></code> or bound to a Map. This class extends MVCObject.
043 * @param element {@link Element}
044 * @param options {@link StreetViewPanoramaOptions}
045 * @return {@link StreetViewPanoramaImpl}
046 */
047 public static StreetViewPanoramaImpl newInstance(Element element, StreetViewPanoramaOptions options) {
048 JavaScriptObject jso = createJso(element, options);
049 WorkAroundUtils.removeGwtObjectId(jso);
050 return jso.cast();
051 }
052
053 private final static native JavaScriptObject createJso(Element container, StreetViewPanoramaOptions opts) /*-{
054 return new $wnd.google.maps.StreetViewPanorama(container, opts)
055 }-*/;
056
057 /**
058 * Returns the set of navigation links for the Street View panorama.
059 */
060 public final native JsArray<StreetViewLink> getLinks() /*-{
061 return this.getLinks();
062 }-*/;
063
064 /**
065 * Returns the current panorama ID for the Street View panorama. This id is stable within the browser's current session only.
066 */
067 public final native String getPano() /*-{
068 return this.getPano();
069 }-*/;
070
071 /**
072 * Returns the current LatLng position for the Street View panorama.
073 */
074 public final native LatLng getPosition() /*-{
075 return this.getPosition();
076 }-*/;
077
078 /**
079 * Returns the current point of view for the Street View panorama.
080 */
081 public final native StreetViewPov getPov() /*-{
082 return this.getPov();
083 }-*/;
084
085 /**
086 * Returns true if the panorama is visible. It does not specify whether Street View imagery is available at the specified position.
087 */
088 public final native boolean getVisible() /*-{
089 return this.getVisible();
090 }-*/;
091
092 /**
093 * Set the custom panorama provider called on pano change to load custom panoramas.
094 * @param provider
095 */
096 public final native void registerPanoProvider(StreetViewPanoramaProvider provider) /*-{
097 this.panoProvider = function(pano, zoom, tileX, tileY) {
098 provider.@com.google.gwt.maps.client.streetview.StreetViewPanoramaProvider::getPanoData(Ljava/lang/String;III)(pano, zoom, tileX, tileY);
099 }
100 }-*/;
101
102 /**
103 * Sets the current panorama ID for the Street View panorama.
104 * @param pano
105 */
106 public final native void setPano(String pano) /*-{
107 this.setPano(pano);
108 }-*/;
109
110 /**
111 * Sets the current LatLng position for the Street View panorama.
112 * @param latLng
113 */
114 public final native void setPosition(LatLng latLng) /*-{
115 this.setPosition(latLng);
116 }-*/;
117
118 /**
119 * Sets the point of view for the Street View panorama.
120 * @param pov
121 */
122 public final native void setPov(StreetViewPov pov) /*-{
123 this.setPov(pov);
124 }-*/;
125
126 /**
127 * Sets to true to make the panorama visible. If set to false, the panorama will be hidden whether it is embedded in the map or in its own <code><div></code>.
128 * @param visible
129 */
130 public final native void setVisible(boolean visible) /*-{
131 this.setVisible(visible);
132 }-*/;
133
134 /**
135 * TODO
136 * Additional controls to attach to the panorama. To add a control to the panorama, add the control's <code><div></code> to the MVCArray corresponding to the ControlPosition where it should be rendered.
137 * @param controls
138 */
139 public final native void setControls(MVCArray<Element> controls) /*-{
140 this.controls = controls;
141 }-*/;
142
143 /**
144 * This event is fired when the close button is clicked.
145 * @param handler
146 */
147 public final HandlerRegistration addCloseClickHandler(CloseClickMapHandler handler) {
148 return MapHandlerRegistration.addHandler(this, MapEventType.CLOSECLICK, handler, new CloseClickEventFormatter());
149 }
150
151 /**
152 * This event is fired when the panorama's links change. The links change asynchronously following a pano id change.
153 * @param handler
154 */
155 public final HandlerRegistration addLinksChangeHandler(LinksChangeMapHandler handler) {
156 return MapHandlerRegistration.addHandler(this, MapEventType.LINKS_CHANGED, handler, new LinksChangeEventFormatter());
157 }
158
159 /**
160 * This event is fired when the panorama's pano id changes. The pano may change as the user navigates through the panorama or the position is manually set. Note that not all position changes trigger a pano_changed.
161 * @param handler
162 */
163 public final HandlerRegistration addPanoChangeHandler(PanoChangeMapHandler handler) {
164 return MapHandlerRegistration.addHandler(this, MapEventType.PANO_CHANGED, handler, new PanoChangeEventFormatter());
165 }
166
167 /**
168 * This event is fired when the panorama's position changes. The position changes as the user navigates through the panorama or the position is set manually.
169 * @param handler
170 */
171 public final HandlerRegistration addPositionChangeHandler(PositionChangeMapHandler handler) {
172 return MapHandlerRegistration.addHandler(this, MapEventType.POSITION_CHANGED, handler, new PositionChangeEventFormatter());
173 }
174
175 /**
176 * This event is fired when the panorama's point-of-view changes. The point of view changes as the pitch, zoom, or heading changes.
177 * @param handler
178 */
179 public final HandlerRegistration addPovChangeHandler(PovChangeMapHandler handler) {
180 return MapHandlerRegistration.addHandler(this, MapEventType.POV_CHANGED, handler, new PovChangeEventFormatter());
181 }
182
183 /**
184 * Developers should trigger this event on the panorama when its div changes size: google.maps.event.trigger(panorama, 'resize').
185 * @param handler
186 */
187 public final HandlerRegistration addResizeHandler(ResizeMapHandler handler) {
188 return MapHandlerRegistration.addHandler(this, MapEventType.RESIZE, handler, new ResizeEventFormatter());
189 }
190
191 /**
192 * This event is fired when the panorama's visibility changes. The visibility is changed when the Pegman id dragged onto the map, the close button is clicked, or setVisible() is called.
193 * @param handler
194 */
195 public final HandlerRegistration addVisibleChangeHandler(VisibleChangeMapHandler handler) {
196 return MapHandlerRegistration.addHandler(this, MapEventType.VISIBLE_CHANGED, handler, new VisibleChangeEventFormatter());
197 }
198
199 }