Skip to content

Commit

Permalink
Deprecation on AjaxGMap, and commit of new CCGoogleMap
Browse files Browse the repository at this point in the history
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 <amedeo.mantica@insigno.it>
  • Loading branch information
Amedeo Mantica committed Apr 23, 2012
1 parent 2958b3d commit 4bbd10c
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxGMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxGMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions Frameworks/Ajax/ERCoolComponents/Components/CCGoogleMap.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wodefinitions>
<wo wocomponentcontent="false" class="CCGoogleMap.java">

</wo>
</wodefinitions>
18 changes: 18 additions & 0 deletions Frameworks/Ajax/ERCoolComponents/Components/CCGoogleMapMarker.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wodefinitions>
<wo class="CCGoogleMap.java" wocomponentcontent="false">

<binding name="id"/>
<binding name="style"/>
<binding name="class"/>
<binding name="googleMapId"/>
<validation message="'googleMapId' is a required binding.">
<unbound name="googleMapId"/>
</validation>
<binding name="lat"/>

<binding name="lng"/>

<binding name="address"/>
</wo>
</wodefinitions>
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>
* CCGoogleMap replaces AjaxGmap and will allow you to easily insert a google map inside your page</p>
* <p>
* You must set the property ajax.google.maps.V3.apiKey in your Properties file</p>
*
* <p>please note that is REQUIRED to set the widht height of the map, you can use id, class, or style to do that</p>
*
* @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 <a href="https://github.com/amedeomantica/INWebTools">INWebTools</a>
*
* @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("<div ");

if(_elementId != null) {
response.appendContentString("id=\"" + _elementId.valueInComponent(context.component()) + "\" ");
}

String classValue = "in_GoogleMap ";
if(_elementClass != null) {
classValue = classValue + (String)_elementClass.valueInComponent(context.component());
}
response.appendContentString("class=\"" + classValue + "\" ");

if(_elementStyle != null) {
response.appendContentString("style=\"" + _elementStyle.valueInComponent(context.component()) + "\" ");
}

String zoomValue = "14";
if(_zoom!=null) {
zoomValue = (String) _zoom.valueInComponent(context.component());
}
response.appendContentString("data-zoom=\"" + zoomValue + "\" ");

String mapType = "ROADMAP";
if(_type!=null) {
mapType = (String) _type.valueInComponent(context.component());
}

response.appendContentString("data-type=\"" + mapType + "\" ");
response.appendContentString("data-lng=\"" + _lng.valueInComponent(context.component()) + "\" ");
response.appendContentString("data-lat=\"" + _lat.valueInComponent(context.component()) + "\"");

response.appendContentString("></div>");
}


@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;
}

}
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>
* CCGoogleMapMarker replaces AjaxGmapMarker and will allow you to easily insert one or more google markers inside a CCGoogleMap inside your page</p>
*
* <p>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)</p>
*
* @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 <a href="https://github.com/amedeomantica/INWebTools">INWebTools</a>
*
* @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<String, WOAssociation> 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("<address ");

if(_elementId != null) {
response.appendContentString("id=\"" + _elementId.valueInComponent(context.component()) + "\" ");
}

String classValue = "in_GoogleMapMarker ";
if(_elementClass != null) {
classValue = classValue + (String)_elementClass.valueInComponent(context.component());
}
response.appendContentString("class=\"" + classValue + "\" ");

if(_elementStyle != null) {
response.appendContentString("style=\"" + _elementStyle.valueInComponent(context.component()) + "\" ");
}

response.appendContentString("data-in_GoogleMap-id=\"" + _googleMapId.valueInComponent(context.component()) + "\" ");

String draggable = "false";
if(_draggable!=null) {
draggable = (String) _draggable.valueInComponent(context.component());
}

response.appendContentString("data-draggable=\"" + draggable + "\" ");

response.appendContentString("data-lng=\"" + _lng.valueInComponent(context.component()) + "\" ");
response.appendContentString("data-lat=\"" + _lat.valueInComponent(context.component()) + "\"");

response.appendContentString(">");

_children.appendToResponse(response, context);

response.appendContentString("</address>");

}


@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;
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4bbd10c

Please sign in to comment.