Large diffs are not rendered by default.

@@ -443,10 +443,16 @@
* (Ushahidi.REPORTS, Ushahidi.KML, Ushahidi.SHARES. Ushahidi.DEFAULT)
* options - {Object} Optional object key/value pairs of the markers to be added to the map
*
* Valid options are:
* name - {String} Name of the Layer being added
* url - {String} Fetch URL for the layer data
* styleMap - {OpenLayers.StyleMap} Styling for the layer
* Valid options are:
* name - {String} Name of the Layer being added
* url - {String} Fetch URL for the layer data
* styleMap - {OpenLayers.StyleMap} Styling for the layer
* callback - {Function} Callback function to preprocess the data returned by
* the url When the callback is specified, the protocol property
* is omitted from the options passed to the layer constructor. The
* features property is used instead
* transform - {Boolean} When true, transforms the featur geometry to spherical mercator
* The default value is false
*
* save - {bool} Whether to save the layer in the internal registry of Ushahidi.Map This
* parameter should be set to true, if the layer being added is new so as to ensure
@@ -463,15 +469,16 @@
maxDepth: 5
});
} else if (layerType == Ushahidi.DEFAULT) {
var point = this._olMap.getCenter();
this.deleteLayer("default");

var markers = new OpenLayers.Layer.Markers("default");
markers.addMarker(new OpenLayers.Marker(point));
markers.addMarker(new OpenLayers.Marker(this._olMap.getCenter()));

this._olMap.addLayer(markers);
var context = this;

context._olMap.events.register("click", context._olMap, function(e){
point = context._olMap.getLonLatFromViewPortPx(e.xy);
var point = context._olMap.getLonLatFromViewPortPx(e.xy);
markers.clearMarkers();
markers.addMarker(new OpenLayers.Marker(point));

@@ -486,53 +493,57 @@
return this;
}

if (options === undefined) {
// No options defined - where layerType !== Ushahidi.DEFAULT
if (options == undefined) {
throw "Invalid layer options";
}

// Save the layer data in the internal registry
if (save != undefined && save) {
if (save !== undefined && save) {
this._registry.push({layerType: layerType, options: options});
}

// Transform feature point coordinate to Spherical Mercator
// Transform feature geometry to Spherical Mercator
preFeatureInsert = function(feature) {
if (feature.geometry !== undefined && feature.geometry != null) {
if (feature.geometry) {
var point = new OpenLayers.Geometry.Point(feature.geometry.x, feature.geometry.y);
OpenLayers.Projection.transform(point, Ushahidi.proj_4326, Ushahidi.proj_900913);
feature.geometry.x = point.x;
feature.geometry.y = point.y;
}
}

// Layer names should be unique, therefore delete any
// existing layer that has the same name as the one
// being added
// existing layer that has the same name as the one being added
this.deleteLayer(options.name);

// Layer options
var layerOptions = {
preFeatureInsert: preFeatureInsert,
projection: Ushahidi.proj_4326,
formatOptions: {
extractStyles: true,
extractAttributes: true,
},
strategies: [new OpenLayers.Strategy.Fixed({preload: true})],
}
};

if (options.transform) {
// Transform the feature geometry to spherical mercator
layerOptions.preFeatureInsert = preFeatureInsert;
}

// Build out the fetch url
var fetchURL = Ushahidi.baseURL + options.url;

// Apply the report filters to the layer fetch URL except where
// the layer type is KML
if (layerType != Ushahidi.KML) {
if (layerType !== Ushahidi.KML) {
var params = [];
for (var _key in this._reportFilters) {
params.push(_key + '=' + this._reportFilters[_key]);
}

// Update the fetch URL witht parameters
fetchURL += (params.length > 0) ? '?' + params.join('&') : '';

// Get the styling to use
var styleMap = null;
if (options.styleMap !== undefined) {
@@ -549,14 +560,35 @@
layerOptions.styleMap = styleMap;
}

// Set the protocol
layerOptions.protocol = new OpenLayers.Protocol.HTTP({
url: fetchURL,
format: protocolFormat
});
// Is there a callback for the data
var layerFeatures = [];
if (options.callback !== undefined) {
$.ajax({
url: fetchURL,
async: false,
success: function(response) {
var jsonFormat = new OpenLayers.Format.JSON();
var jsonStr = jsonFormat.write(options.callback(response));
var format = new OpenLayers.Format.GeoJSON();
layerFeatures = format.read(jsonStr);
},
dataType: "json"
});
} else {
layerOptions.strategies = [new OpenLayers.Strategy.Fixed({preload: true})];

// Set the protocol
layerOptions.protocol = new OpenLayers.Protocol.HTTP({
url: fetchURL,
format: protocolFormat
});
}

// Create the layer
var layer = new OpenLayers.Layer.Vector(options.name, layerOptions);
if (layerFeatures !== null && layerFeatures.length > 0) {
layer.addFeatures(layerFeatures);
}

// Add the layer to the map
var context = this;
@@ -674,14 +706,20 @@
lon = zoom_point.lon;
lat = zoom_point.lat;

var thumb = "";
if (typeof(event.feature.attributes.thumb) != 'undefined' &&
event.feature.attributes.thumb != '') {
thumb = "<div class=\"infowindow_image\"><a href='"+event.feature.attributes.link+"'>";
thumb += "<img src=\""+event.feature.attributes.thumb+"\" height=\"59\" width=\"89\" /></a></div>";
// Image to display within the popup
var image = "";
if (event.feature.attributes.thumb !== undefined && event.feature.attributes.thumb != '') {
image = "<div class=\"infowindow_image\"><a href='"+event.feature.attributes.link+"'>";
image += "<img src=\""+event.feature.attributes.thumb+"\" height=\"59\" width=\"89\" /></a></div>";
} else if (event.feature.attributes.image !== undefined && event.feature.attributes.image != '') {
image = "<div class=\"infowindow_image\">";
image += "<a href=\""+event.feature.attributes.link+"\" title=\""+event.feature.attributes.name+"\">";
image += "<img src=\""+event.feature.attributes.image+"\" />";
image += "</a>";
image += "</div>";
}

var content = "<div class=\"infowindow\">" + thumb +
var content = "<div class=\"infowindow\">" + image +
"<div class=\"infowindow_content\">"+
"<div class=\"infowindow_list\">"+event.feature.attributes.name+"</div>\n" +
"<div class=\"infowindow_meta\">";
@@ -18,7 +18,7 @@

$(window).load(function(){

// OpenLayers uses IE's VML for vector graphics. -->
// OpenLayers uses IE's VML for vector graphics
// We need to wait for IE's engine to finish loading all namespaces (document.namespaces) for VML.
// jQuery.ready is executing too soon for IE to complete it's loading process.

@@ -44,8 +44,11 @@
longitude: <?php echo $longitude; ?>
});

// Subscribe for makerpositionchanged event
map.register("markerpositionchanged", updateAlertCoordinates);
// Subscribe to makerpositionchanged event
map.register("markerpositionchanged", function(coords){
$("#alert_lat").val(coords.latitude);
$("#alert_lon").val(coords.longitude);
});

$('.btn_find').on('click', function () {
geoCode();
@@ -81,7 +84,7 @@
$("#alert_mobile").focus(function() {
$("#alert_mobile_yes").attr("checked",true);
}).blur(function() {
if( !this.value.length ) {
if(!this.value.length) {
$("#alert_mobile_yes").attr("checked",false);
}
});
@@ -93,8 +96,7 @@
$("#alert_email_yes").attr("checked",false);
}
});



// Category treeview
$("#category-column-1,#category-column-2").treeview({
persist: "location",
@@ -103,13 +105,6 @@
});
});
});

// Update the coorindates for the alerts form
function updateAlertCoordinates(coords) {
$("#alert_lat").val(coords.latitude);
$("#alert_lon").val(coords.longitude);
}


/**
* Google GeoCoder
@@ -30,128 +30,6 @@
var endTime = <?php echo $active_endDate ?>;


/**
* Display info window for checkin data
*/
function showCheckinData(event) {
selectedFeature = event.feature;
zoom_point = event.feature.geometry.getBounds().getCenterLonLat();
lon = zoom_point.lon;
lat = zoom_point.lat;

var content = "<div class=\"infowindow\" style=\"color:#000000\"><div class=\"infowindow_list\">";

if(event.feature.attributes.ci_media_medium !== "")
{
content += "<a href=\""+event.feature.attributes.ci_media_link+"\" rel=\"lightbox-group1\" title=\""+event.feature.attributes.ci_msg+"\">";
content += "<img src=\""+event.feature.attributes.ci_media_medium+"\" /><br/>";
}

content += event.feature.attributes.ci_msg+"</div><div style=\"clear:both;\"></div>";
content += "\n<div class=\"infowindow_meta\">";
content += "<a href='javascript:zoomToSelectedFeature("+ lon + ","+ lat +",1)'><?php echo Kohana::lang('ui_main.zoom_in');?></a>";
content += "&nbsp;&nbsp;|&nbsp;&nbsp;";
content += "<a href='javascript:zoomToSelectedFeature("+ lon + ","+ lat +",-1)'><?php echo Kohana::lang('ui_main.zoom_out');?></a></div>";
content += "</div>";

if (content.search("<?php echo '<'; ?>script") != -1)
{
content = "Content contained Javascript! Escaped content below.<br />" + content.replace(/<?php echo '<'; ?>/g, "&lt;");
}

popup = new OpenLayers.Popup.FramedCloud("chicken",
event.feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,100),
content,
null, true, onPopupClose);

event.feature.popup = popup;
map.addPopup(popup);
}

/**
* Display Checkin Points
* Note: This function totally ignores the timeline
*/
function showCheckins() {
$(document).ready(function(){

var ci_styles = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
pointRadius: "5", // sized according to type attribute
fillColor: "${fillcolor}",
strokeColor: "${strokecolor}",
fillOpacity: "${fillopacity}",
strokeOpacity: 0.75,
strokeWidth: 1.5
})
});

var checkinLayer = new OpenLayers.Layer.Vector('Checkins', {styleMap: ci_styles});
map.addLayers([checkinLayer]);

highlightCtrl = new OpenLayers.Control.SelectFeature(checkinLayer, {
hover: true,
highlightOnly: true,
renderIntent: "temporary"
});
map.addControl(highlightCtrl);
highlightCtrl.activate();

selectControl = new OpenLayers.Control.SelectFeature([checkinLayer,markers]);
map.addControl(selectControl);
selectControl.activate();
checkinLayer.events.on({
"featureselected": showCheckinData,
"featureunselected": onFeatureUnselect
});

$.getJSON("<?php echo url::site()."api/?task=checkin&action=get_ci&mapdata=1&sqllimit=1000&orderby=checkin.checkin_date&sort=ASC"?>", function(data) {
var user_colors = new Array();
// Get colors
$.each(data["payload"]["users"], function(i, payl) {
user_colors[payl.id] = payl.color;
});

// Get checkins
$.each(data["payload"]["checkins"], function(key, ci) {

var cipoint = new OpenLayers.Geometry.Point(parseFloat(ci.lon), parseFloat(ci.lat));
cipoint.transform(proj_4326, proj_900913);

var media_link = '';
var media_medium = '';
var media_thumb = '';

if(ci.media === undefined)
{
// No image
}
else
{
// Image!
media_link = ci.media[0].link;
media_medium = ci.media[0].medium;
media_thumb = ci.media[0].thumb;
}

var checkinPoint = new OpenLayers.Feature.Vector(cipoint, {
fillcolor: "#"+user_colors[ci.user],
strokecolor: "#FFFFFF",
fillopacity: ci.opacity,
ci_id: ci.id,
ci_msg: ci.msg,
ci_media_link: media_link,
ci_media_medium: media_medium,
ci_media_thumb: media_thumb
});

checkinLayer.addFeatures([checkinPoint]);
});
});
});
}

/**
* Toggle Layer Switchers
*/
@@ -277,24 +155,25 @@ function refreshTimeline() {


jQuery(function() {
var reportsURL = "<?php echo Kohana::config('settings.allow_clustering') == 1 ? "json/cluster" : "json"; ?>";

// Render thee JavaScript for the base layers so that
// they are accessible by Ushahidi.js

<?php echo map::layers_js(FALSE); ?>

// Map configuration
var config = {

// Zoom level at which to display the map
zoom: <?php echo $default_zoom; ?>,
zoom: <?php echo Kohana::config('settings.default_zoom'); ?>,

// Redraw the layers when the zoom level changes
redrawOnZoom: true,

// Center of the map
center: {
latitude: <?php echo $latitude; ?>,
longitude: <?php echo $longitude; ?>
latitude: <?php echo Kohana::config('settings.default_lat'); ?>,
longitude: <?php echo Kohana::config('settings.default_lon'); ?>
},

// Map controls
@@ -324,7 +203,7 @@ function refreshTimeline() {
var map = new Ushahidi.Map('map', config);
map.addLayer(Ushahidi.GEOJSON, {
name: "<?php echo Kohana::lang('ui_main.reports'); ?>",
url: "<?php echo $json_url; ?>"
url: reportsURL
}, true);


@@ -355,8 +234,6 @@ function refreshTimeline() {
// Update report filters
map.updateReportFilters({c: categoryId});

// Check if the timeline is enabled

e.stopPropagation();
return false;
});
@@ -429,124 +306,78 @@ function refreshTimeline() {

//Execute the function when page loads
smartColumns();
});

$(window).resize(function () {
//Each time the viewport is adjusted/resized, execute the function
smartColumns();
});

// Are checkins enabled?
<?php if (Kohana::config('settings.checkins')): ?>

// URL for fetching the checkins
var checkinsURL = "api/?task=checkin&action=get_ci&mapdata=1&sqllimit=1000&orderby=checkin.checkin_date&sort=ASC";

// Styling for the checkins
var ciStyle = new OpenLayers.Style({
pointRadius: 5,
fillColor: "${color}",
strokeColor: "#FFFFFF",
fillOpacity: "${fillOpacity}",
strokeOpacity: 0.75,
strokeWidth: 1.5
});

// START CHECKINS!
<?php if (Kohana::config('settings.checkins')): ?>
var checkinStyleMap = new OpenLayers.StyleMap({
default: ciStyle
});

function cilisting(sqllimit,sqloffset) {
jsonurl = "<?php echo url::site(); ?>api/?task=checkin&action=get_ci&sqllimit="+sqllimit+"&sqloffset="+sqloffset+"&orderby=checkin.checkin_date&sort=DESC";

var showncount = 0;
$.getJSON(jsonurl, function(data) {

if(data.payload.checkins == undefined)
{
if(sqloffset != 0)
{
var newoffset = sqloffset - sqllimit;
$('div#cilist').html("<div style=\"text-align:center;\"><?php echo Kohana::lang('ui_main.no_checkins'); ?><br/><br/><a href=\"javascript:cilisting("+sqllimit+","+newoffset+");\">&lt;&lt; <?php echo Kohana::lang('ui_main.previous'); ?></a></div>");
}else{
$('div#cilist').html("<div style=\"text-align:center;\">No checkins to display.</div>");
}
// Add the checkins layer
map.addLayer(Ushahidi.GEOJSON, {
url: checkinsURL,
name: "Checkins",
callback: json2GeoJSON,
styleMap: checkinStyleMap,
transform: true,
});

return;
}

$('div#cilist').html("");

var user_colors = new Array();
// Get colors
$.each(data.payload.users, function(i, payl) {
user_colors[payl.id] = payl.color;
});

$.each(data.payload.checkins, function(i,item){

if(i == 0)
{
$('div#cilist').append("<div class=\"ci_checkin\" class=\"ci_id_"+item.id+"\"style=\"border:none\"><a name=\"ci_id_"+item.id+"\" />");
}else{
$('div#cilist').append("<div class=\"ci_checkin\" class=\"ci_id_"+item.id+"\" style=\"padding-bottom:5px;margin-bottom:5px;\"><a name=\"ci_id_"+item.id+"\" />");
}

if(item.media === undefined)
{
// Tint the color a bit
$('div#cilist').append("<div class=\"ci_colorblock ci_shorterblock\" style=\"background-color:#"+user_colors[item.user]+";\"><div class=\"ci_colorfade\"></div></div>");
}else{
// Show image
$('div#cilist').append("<div class=\"ci_colorblock ci_tallerblock\" style=\"background-color:#"+user_colors[item.user]+";\"><div class=\"ci_imgblock\"><a href=\""+item.media[0].link+"\" rel=\"lightbox-group1\" title=\""+item.msg+"\"><img src=\""+item.media[0].thumb+"\" height=\"59\" /></a></div></div>");
}

$('div#cilist').append("<div style=\"float:right;width:24px;height:24px;margin-right:10px;\"><a class=\"ci_moredetails\" reportid=\""+item.id+"\" href=\"javascript:externalZeroIn("+item.lon+","+item.lat+",16,"+item.id+");\"><img src=\"<?php echo url::file_loc('img'); ?>media/img/pin_trans.png\" width=\"24\" height=\"24\" /></a></div>");

$.each(data.payload.users, function(j,useritem){
if(useritem.id == item.user){
$('div#cilist').append("<div style=\"font-size:14px;width:215px;padding-top:0px;\"><a href=\"<?php echo url::site(); ?>profile/user/"+useritem.username+"\">"+useritem.name+"</a></div>");
/**
* Callback function to convert the data -
* returned by the checkins API call - to GeoJSON
*/
function json2GeoJSON(json) {
var GeoJSON = {
type: "FeatureCollection",
features: []
};

$.each(json["payload"]["checkins"], function(index, checkin){
var checkinImage = (checkin.media !== undefined) ? checkin.media[0].medium : "";
var checkinLink = (checkinImage !== "") ? checkin.media[0].link : "";
var feature = {
type: "Feature",
properties: {
name: checkin.msg,
link: checkinLink,
color: "#"+checkin.user.color,
image: checkinImage,
fillOpacity: checkin.opacity,
},
geometry: {
type: "Point",
coordinates: [checkin.lon, checkin.lat],
}
});

var utcDate = item.date.replace(" ","T")+"Z";

if(item.msg == "")
{
$('div#cilist').append("<div class=\"ci_cimsg\"><small><em>"+$.timeago(utcDate)+"</em></small></div>");
}else{
$('div#cilist').append("<div class=\"ci_cimsg\">"+item.msg+"<br/><small><em>"+$.timeago(utcDate)+"</em></small></div>");
}

if(item.comments !== undefined)
{
var user_link = '';
var comment_utcDate = '';
$.each(item.comments, function(j,comment){
comment_utcDate = comment.date.replace(" ","T")+"Z";
if(item.user_id != 0){
user_link = '<a href=\"<?php echo url::site(); ?>profile/user/'+comment.username+'\">'+comment.author+'</a>';
}else{
user_link = ''+comment.author+'';
}
$('div#cilist').append("<div style=\"clear:both\"></div>"+user_link+": "+comment.description+" <small>(<em>"+$.timeago(comment_utcDate)+"</em>)</small></div>");
});
}

$('div#cilist').append("<div style=\"clear:both\"></div></div>");

showncount = showncount + 1;
};
GeoJSON.features.push(feature);
});

// Show previous link
if(sqloffset == 0)
{
$('div#cilist').append("<div style=\"float:left;\">&lt;&lt; <?php echo Kohana::lang('ui_main.previous'); ?></div>");
}else{
var newoffset = sqllimit - sqloffset;
$('div#cilist').append("<div style=\"float:left;\"><a href=\"javascript:cilisting("+sqllimit+","+newoffset+");\">&lt;&lt; <?php echo Kohana::lang('ui_main.previous'); ?></a></div>");
}

// Show next link
if(showncount != sqllimit)
{
$('div#cilist').append("<div style=\"float:right;\"><?php echo Kohana::lang('ui_main.next'); ?> &gt;&gt;</div>");
}else{
var newoffset = sqloffset + sqllimit;
$('div#cilist').append("<div style=\"float:right;\"><a href=\"javascript:cilisting("+sqllimit+","+newoffset+");\"><?php echo Kohana::lang('ui_main.next'); ?> &gt;&gt;</a></div>");
}

$('div#cilist').append("<div style=\"clear:both\"></div>");
return GeoJSON;
}
<?php endif; ?>

});

}
});

$(window).resize(function () {
//Each time the viewport is adjusted/resized, execute the function
smartColumns();
});

cilisting(3,0);
showCheckins();

<?php if (Kohana::config('settings.checkins')): ?>
// EK <emmanuel(at)ushahidi.com
// TODO: Load the sidebar with the checkins - moving this to BackboneJS
<?php endif; ?>