From 4bbd10cc8ab550a519d6f66538b8f6a991f4ade0 Mon Sep 17 00:00:00 2001 From: Amedeo Mantica Date: Mon, 23 Apr 2012 17:56:20 +0200 Subject: [PATCH] Deprecation on AjaxGMap, and commit of new CCGoogleMap AjaxGMap and AjaxGMarker rely on Google Maps API V2 witch is deprecated too. The new CCGoogleMap and CCGoogleMapMarker uses google API V3 Signed-off-by: Amedeo Mantica --- .../Ajax/Ajax/Sources/er/ajax/AjaxGMap.java | 2 + .../Ajax/Sources/er/ajax/AjaxGMarker.java | 2 + .../Components/CCGoogleMap.api | 6 + .../Components/CCGoogleMapMarker.api | 18 +++ .../er/coolcomponents/CCGoogleMap.java | 125 ++++++++++++++++++ .../er/coolcomponents/CCGoogleMapMarker.java | 119 +++++++++++++++++ .../WebServerResources/INGoogleMaps.min.js | 7 + 7 files changed, 279 insertions(+) create mode 100644 Frameworks/Ajax/ERCoolComponents/Components/CCGoogleMap.api create mode 100644 Frameworks/Ajax/ERCoolComponents/Components/CCGoogleMapMarker.api create mode 100644 Frameworks/Ajax/ERCoolComponents/Sources/er/coolcomponents/CCGoogleMap.java create mode 100644 Frameworks/Ajax/ERCoolComponents/Sources/er/coolcomponents/CCGoogleMapMarker.java create mode 100644 Frameworks/Ajax/ERCoolComponents/WebServerResources/INGoogleMaps.min.js diff --git a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxGMap.java b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxGMap.java index e4a164cd5e9..592ac85336e 100644 --- a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxGMap.java +++ b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxGMap.java @@ -25,6 +25,8 @@ * @binding apiKey apiKey to use for the map, if you want to ovverride the property below * @property ajax.google.maps.apiKey an api key you can get from http://www.google.com/apis/maps/ . If your app runs on http://ip:port/cgi-bin/WebObjects/GoogleMaps.woa, register the key for http://ip:port/cgi-bin/WebObjects/ . Using a fixed WO port is recommended (unless you want to get a new api key everytime you restart your server). AjaxGMaps will not work without an Api Key. */ + +@Deprecated public class AjaxGMap extends AjaxComponent { private String _id; diff --git a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxGMarker.java b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxGMarker.java index 83b0eaa7cb3..f948ca68c00 100644 --- a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxGMarker.java +++ b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxGMarker.java @@ -18,6 +18,8 @@ * @binding infoWindowHtml the html that is inside the infowindow * @binding options the opts? argument to the constructor of the GMarker class. Value will be place inside {} */ + +@Deprecated public class AjaxGMarker extends WOComponent { private String _id; diff --git a/Frameworks/Ajax/ERCoolComponents/Components/CCGoogleMap.api b/Frameworks/Ajax/ERCoolComponents/Components/CCGoogleMap.api new file mode 100644 index 00000000000..9d824ec3483 --- /dev/null +++ b/Frameworks/Ajax/ERCoolComponents/Components/CCGoogleMap.api @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Frameworks/Ajax/ERCoolComponents/Components/CCGoogleMapMarker.api b/Frameworks/Ajax/ERCoolComponents/Components/CCGoogleMapMarker.api new file mode 100644 index 00000000000..6b2de55acbc --- /dev/null +++ b/Frameworks/Ajax/ERCoolComponents/Components/CCGoogleMapMarker.api @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Frameworks/Ajax/ERCoolComponents/Sources/er/coolcomponents/CCGoogleMap.java b/Frameworks/Ajax/ERCoolComponents/Sources/er/coolcomponents/CCGoogleMap.java new file mode 100644 index 00000000000..617ce2e6ac3 --- /dev/null +++ b/Frameworks/Ajax/ERCoolComponents/Sources/er/coolcomponents/CCGoogleMap.java @@ -0,0 +1,125 @@ +package er.coolcomponents; + +import org.apache.log4j.Logger; + +import com.webobjects.appserver.WOActionResults; +import com.webobjects.appserver.WOAssociation; +import com.webobjects.appserver.WOContext; +import com.webobjects.appserver.WOElement; +import com.webobjects.appserver.WORequest; +import com.webobjects.appserver.WOResponse; +import com.webobjects.appserver._private.WODynamicElementCreationException; +import com.webobjects.foundation.NSDictionary; + +import er.ajax.AjaxDynamicElement; +import er.ajax.AjaxUtils; +import er.extensions.foundation.ERXProperties; + +/** + * WebObjects wrapper for INGoogleMap.js. + * + *

+ * CCGoogleMap replaces AjaxGmap and will allow you to easily insert a google map inside your page

+ *

+ * You must set the property ajax.google.maps.V3.apiKey in your Properties file

+ * + *

please note that is REQUIRED to set the widht height of the map, you can use id, class, or style to do that

+ * + * @binding id the id of the div element that CCGoogleMap will generate + * @binding class the class of the div element + * @binding style the style of the div element + * @binding zoom the desidered map startup zoom level + * @binding lat the latidude of the map center + * @binding lng the longitude of the map center + * @binding type, can be ROADMAP, SATELLITE, HYBRID or TERRAIN, default to ROADMAP. all uppercase string + * + * + * @see INWebTools + * + * @author amedeomantica (WebObjects wrapper and INGoogleMap.js) + */ + +public class CCGoogleMap extends AjaxDynamicElement { + //private static Logger log = Logger.getLogger(CCGoogleMap.class); + + private WOAssociation _elementId; + private WOAssociation _elementClass; + private WOAssociation _elementStyle; + private WOAssociation _zoom; + private WOAssociation _type; + private WOAssociation _lat; + private WOAssociation _lng; + + public CCGoogleMap(String aName, NSDictionary someAssociations, + WOElement template) { + super(aName, someAssociations, template); + + _elementId = (WOAssociation) someAssociations.objectForKey("id"); + _elementStyle = (WOAssociation) someAssociations.objectForKey("style"); + _elementClass = (WOAssociation) someAssociations.objectForKey("class"); + + _zoom = (WOAssociation) someAssociations.objectForKey("zoom"); + _type = (WOAssociation) someAssociations.objectForKey("type"); + _lat = (WOAssociation) someAssociations.objectForKey("lat"); + _lng = (WOAssociation) someAssociations.objectForKey("lng"); + + if( (_lat == null )||( _lng == null ) ) { + throw new WODynamicElementCreationException("Unable to create CCGoogleMap, missing coordinates"); + } + + } + + @Override + public void appendToResponse(WOResponse response, WOContext context) { + super.appendToResponse(response, context); + AjaxUtils.addScriptCodeInHead(response, context, "var in_googleApiKey=\"" + + ERXProperties.stringForKey("ajax.google.maps.V3.apiKey") + "\""); + + response.appendContentString("
"); + } + + + @Override + protected void addRequiredWebResources(WOResponse response,WOContext context) { + addScriptResourceInHead(context, response, "ERCoolComponents", "INGoogleMaps.min.js"); + } + + + @Override + public WOActionResults handleRequest(WORequest request, WOContext context) { + // TODO Auto-generated method stub + return null; + } + +} \ No newline at end of file diff --git a/Frameworks/Ajax/ERCoolComponents/Sources/er/coolcomponents/CCGoogleMapMarker.java b/Frameworks/Ajax/ERCoolComponents/Sources/er/coolcomponents/CCGoogleMapMarker.java new file mode 100644 index 00000000000..4b2129a98a1 --- /dev/null +++ b/Frameworks/Ajax/ERCoolComponents/Sources/er/coolcomponents/CCGoogleMapMarker.java @@ -0,0 +1,119 @@ +package er.coolcomponents; + +import com.webobjects.appserver.WOActionResults; +import com.webobjects.appserver.WOAssociation; +import com.webobjects.appserver.WOContext; +import com.webobjects.appserver.WOElement; +import com.webobjects.appserver.WORequest; +import com.webobjects.appserver.WOResponse; +import com.webobjects.foundation.NSDictionary; + +import er.ajax.AjaxDynamicElement; + +/** + * WebObjects wrapper for INGoogleMap.js. + * + *

+ * CCGoogleMapMarker replaces AjaxGmapMarker and will allow you to easily insert one or more google markers inside a CCGoogleMap inside your page

+ * + *

CCGoogleMapMarker will also insert an html address element on the page, + * the content of CCGoogleMapMarker wil be copied inside the ballon thet people wil see clicking on the marker + * if you don't want the address element to be shown on page simply set display none using css (id, class or style)

+ * + * @binding id the id of the address element that CCGoogleMapMarker will generate + * @binding class the class of the address element + * @binding style the style of the address element + * @binding googleMapId REQUIRED the id of the google map where you want the marker to be placed + * @binding lat the latidude of the marker + * @binding lng the longitude of the marker + * + * + * @see INWebTools + * + * @author amedeomantica (WebObjects wrapper and INGoogleMap.js) + */ + +public class CCGoogleMapMarker extends AjaxDynamicElement { + + private WOAssociation _elementId; + private WOAssociation _elementClass; + private WOAssociation _elementStyle; + private WOAssociation _googleMapId; + private WOAssociation _draggable; + private WOAssociation _lat; + private WOAssociation _lng; + private WOElement _children; + + public CCGoogleMapMarker(String name, + NSDictionary someAssociations, WOElement children) { + super(name, someAssociations, children); + + _elementId = (WOAssociation) someAssociations.objectForKey("id"); + _elementStyle = (WOAssociation) someAssociations.objectForKey("style"); + _elementClass = (WOAssociation) someAssociations.objectForKey("class"); + + _googleMapId = (WOAssociation) someAssociations.objectForKey("googleMapId"); + _draggable = (WOAssociation) someAssociations.objectForKey("draggable"); + _lat = (WOAssociation) someAssociations.objectForKey("lat"); + _lng = (WOAssociation) someAssociations.objectForKey("lng"); + + _children = children; + } + + @Override + public void appendToResponse(WOResponse response, WOContext context) { + // We need to call these otherwise the method "addRequiredWebResources" would not be called + super.appendToResponse(response, context); + + response.appendContentString("
"); + + _children.appendToResponse(response, context); + + response.appendContentString("
"); + + } + + + @Override + protected void addRequiredWebResources(WOResponse response, + WOContext context) { + + addScriptResourceInHead(context, response, "ERCoolComponents", "INGoogleMaps.min.js"); + + } + + @Override + public WOActionResults handleRequest(WORequest request, WOContext context) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/Frameworks/Ajax/ERCoolComponents/WebServerResources/INGoogleMaps.min.js b/Frameworks/Ajax/ERCoolComponents/WebServerResources/INGoogleMaps.min.js new file mode 100644 index 00000000000..6b01275fae4 --- /dev/null +++ b/Frameworks/Ajax/ERCoolComponents/WebServerResources/INGoogleMaps.min.js @@ -0,0 +1,7 @@ +/** INGoogleMaps.js + * @author Amedeo Mantica + * @copyright Amedeo Mantica + * @version 0.1 + * Source available on https://github.com/amedeomantica/INWebTools + */ +function IN_setupGoogleMaps(){var a=in_googleApiKey;var b=document.createElement("script");b.type="text/javascript";b.src="http://maps.googleapis.com/maps/api/js?key="+a+"&sensor=false&callback=IN_initializeMaps";document.body.appendChild(b)}window.IN_isIE=false;window.IN_GoogleMaps=Array();var IN_initializeMaps=function(){var a;var b=document.getElementsByTagName("div");for(a=0;a