001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.gwt.client.ui.input.location; 029 030import com.google.gwt.core.client.JavaScriptObject; 031 032/** 033 * The location value.<p> 034 */ 035public final class CmsLocationValue extends JavaScriptObject { 036 037 /** 038 * Protected constructor required for JavaScript overlay objects.<p> 039 */ 040 protected CmsLocationValue() { 041 042 } 043 044 /** 045 * Parses the given JSON string.<p> 046 * 047 * @param value the value string to parse 048 * 049 * @return the location object 050 */ 051 public static native CmsLocationValue parse(String value)/*-{ 052 if (value.indexOf("{") != 0) { 053 // add curly braces if not present before parsing 054 value = "{" + value + "}"; 055 } 056 try { 057 return JSON.parse(value); 058 } catch (e) { 059 return eval("("+value+")"); 060 } 061 }-*/; 062 063 /** 064 * Clones the value object.<p> 065 * 066 * @return the clone 067 */ 068 public native CmsLocationValue cloneValue()/*-{ 069 return { 070 address : this.address, 071 height : this.height, 072 lat : this.lat, 073 lng : this.lng, 074 mode : this.mode, 075 type : this.type, 076 width : this.width, 077 zoom : this.zoom 078 }; 079 }-*/; 080 081 /** 082 * Returns the location address.<p> 083 * 084 * @return the address 085 */ 086 public native String getAddress()/*-{ 087 return this.address !== undefined ? this.address : ''; 088 }-*/; 089 090 /** 091 * Returns the height.<p> 092 * 093 * @return the height 094 */ 095 public native int getHeight()/*-{ 096 return this.height; 097 }-*/; 098 099 /** 100 * Returns the latitude.<p> 101 * 102 * @return the latitude 103 */ 104 public native float getLatitude()/*-{ 105 return this.lat; 106 }-*/; 107 108 /** 109 * Returns the latitude string representation.<p> 110 * 111 * @return the latitude string representation 112 */ 113 public native String getLatitudeString()/*-{ 114 return this.lat.toFixed(6); 115 ; 116 }-*/; 117 118 /** 119 * Returns the longitude.<p> 120 * 121 * @return the longitude 122 */ 123 public native float getLongitude()/*-{ 124 return this.lng; 125 }-*/; 126 127 /** 128 * Returns the longitude string representation.<p> 129 * 130 * @return the longitude string representation 131 */ 132 public native String getLongitudeString()/*-{ 133 return this.lng.toFixed(6); 134 }-*/; 135 136 /** 137 * Returns the mode.<p> 138 * 139 * @return the mode 140 */ 141 public native String getMode()/*-{ 142 return this.mode; 143 }-*/; 144 145 /** 146 * Returns the type.<p> 147 * 148 * @return the type 149 */ 150 public native String getType()/*-{ 151 return this.type; 152 }-*/; 153 154 /** 155 * Returns the width.<p> 156 * 157 * @return the width 158 */ 159 public native int getWidth()/*-{ 160 return this.width; 161 }-*/; 162 163 /** 164 * Returns the zoom.<p> 165 * 166 * @return the zoom 167 */ 168 public native int getZoom()/*-{ 169 return this.zoom; 170 }-*/; 171 172 /** 173 * Sets the address.<p> 174 * 175 * @param address the address 176 */ 177 public native void setAddress(String address)/*-{ 178 this.address = address; 179 }-*/; 180 181 /** 182 * Sets the height.<p> 183 * 184 * @param height the height 185 */ 186 public native void setHeight(int height)/*-{ 187 this.height = height; 188 }-*/; 189 190 /** 191 * Sets the height.<p> 192 * 193 * @param height the height 194 */ 195 public native void setHeight(String height)/*-{ 196 var h = parseInt(height); 197 this.height = isNaN(h) ? 0 : h; 198 }-*/; 199 200 /** 201 * Sets the latitude.<p> 202 * 203 * @param latitude the latitude 204 */ 205 public native void setLatitude(float latitude)/*-{ 206 this.lat = latitude; 207 }-*/; 208 209 /** 210 * Sets the latitude.<p> 211 * 212 * @param latitude the latitude 213 */ 214 public native void setLatitude(String latitude)/*-{ 215 var lat = parseFloat(latitude); 216 this.lat = isNaN(lat) ? 0 : lat; 217 }-*/; 218 219 /** 220 * Sets the longitude.<p> 221 * 222 * @param longitude the longitude 223 */ 224 public native void setLongitude(float longitude)/*-{ 225 this.lng = longitude; 226 }-*/; 227 228 /** 229 * Sets the longitude.<p> 230 * 231 * @param longitude the longitude 232 */ 233 public native void setLongitude(String longitude)/*-{ 234 var lng = parseFloat(longitude); 235 this.lng = isNaN(lng) ? 0 : lng; 236 }-*/; 237 238 /** 239 * Sets the map mode.<p> 240 * 241 * @param mode the map mode 242 */ 243 public native void setMode(String mode)/*-{ 244 this.mode = mode; 245 }-*/; 246 247 /** 248 * Sets the map type.<p> 249 * 250 * @param type the map type 251 */ 252 public native void setType(String type)/*-{ 253 this.type = type; 254 }-*/; 255 256 /** 257 * Sets the width.<p> 258 * 259 * @param width the width 260 */ 261 public native void setWidth(int width)/*-{ 262 this.width = width; 263 }-*/; 264 265 /** 266 * Sets the width.<p> 267 * 268 * @param width the width 269 */ 270 public native void setWidth(String width)/*-{ 271 var w = parseInt(width); 272 this.width = isNaN(w) ? 0 : w; 273 }-*/; 274 275 /** 276 * Sets the map zoom level.<p> 277 * 278 * @param zoom the zoom level 279 */ 280 public native void setZoom(int zoom)/*-{ 281 this.zoom = zoom; 282 }-*/; 283 284 /** 285 * Sets the map zoom level.<p> 286 * 287 * @param zoom the zoom level 288 */ 289 public native void setZoom(String zoom)/*-{ 290 var z = parseInt(z); 291 this.zoom = isNaN(z) ? 0 : z; 292 }-*/; 293 294 /** 295 * Returns the JSON string representation of this value.<p> 296 * 297 * @return the JSON string representation 298 */ 299 public native String toJSONString()/*-{ 300 return JSON.stringify(this); 301 }-*/; 302 303}