Skip to content
Snippets Groups Projects
Commit e57a487b authored by Brandon Bergren's avatar Brandon Bergren
Browse files

JSLint run.

This file needs some serious work still, it will definately need the most work before dynamic bootstrapping works.
parent 3520b58b
No related branches found
No related tags found
No related merge requests found
/* $Id$ */
/**
* @file
* Gmap Overlay Editor
*/
Drupal.gmap.addHandler('overlayedit_linestyle', function(elem) {
/*global $, Drupal, GEvent, GMarker, GPolygon, GPolyline */
Drupal.gmap.addHandler('overlayedit_linestyle', function (elem) {
var obj = this;
obj.vars.styles['overlayline'] = [];
var f = function() {
obj.vars.styles.overlayline = [];
var f = function () {
var o = Number($(this).attr('id').match(/\d+$/));
obj.vars.styles['overlayline'][o] = this.value;
obj.vars.styles.overlayline[o] = this.value;
};
$(elem).find('input.gmap_style').change(f).each(f);
});
Drupal.gmap.addHandler('overlayedit_linestyle_apply', function(elem) {
Drupal.gmap.addHandler('overlayedit_linestyle_apply', function (elem) {
var obj = this;
obj.vars.overlay_linestyle_apply = Boolean(elem.checked);
$(elem).change(function() {
$(elem).change(function () {
obj.vars.overlay_linestyle_apply = Boolean(this.checked);
});
});
Drupal.gmap.addHandler('overlayedit_polystyle', function(elem) {
Drupal.gmap.addHandler('overlayedit_polystyle', function (elem) {
var obj = this;
obj.vars.styles['overlaypoly'] = [];
var f = function() {
obj.vars.styles.overlaypoly = [];
var f = function () {
var o = Number($(this).attr('id').match(/\d+$/));
obj.vars.styles['overlaypoly'][o] = this.value;
obj.vars.styles.overlaypoly[o] = this.value;
};
$(elem).find('input.gmap_style').change(f).each(f);
});
Drupal.gmap.addHandler('overlayedit_polystyle_apply', function(elem) {
Drupal.gmap.addHandler('overlayedit_polystyle_apply', function (elem) {
var obj = this;
obj.vars.overlay_polystyle_apply = Boolean(elem.checked);
$(elem).change(function() {
$(elem).change(function () {
obj.vars.overlay_polystyle_apply = Boolean(this.checked);
});
});
Drupal.gmap.addHandler('overlayedit_fillstroke_default', function(elem) {
Drupal.gmap.addHandler('overlayedit_fillstroke_default', function (elem) {
var obj = this;
obj.vars._usedefaultfillstroke = Boolean(elem.checked);
$(elem).change(function() {
$(elem).change(function () {
obj.vars._usedefaultfillstroke = Boolean(this.checked);
alert(obj.vars._usedefaultfillstroke);
});
});
Drupal.gmap.addHandler('overlayedit_mapclicktype',function(elem) {
Drupal.gmap.addHandler('overlayedit_mapclicktype', function (elem) {
var obj = this;
obj.vars.overlay_add_mode = elem.value;
$(elem).change(function() {
$(elem).change(function () {
obj.vars.overlay_add_mode = elem.value;
if (obj.temp_point) {
delete obj.temp_point;
}
});
});
Drupal.gmap.addHandler('overlayedit_markerclicktype',function(elem) {
Drupal.gmap.addHandler('overlayedit_markerclicktype', function (elem) {
var obj = this;
obj.vars.overlay_del_mode = elem.value;
$(elem).change(function() {
$(elem).change(function () {
obj.vars.overlay_del_mode = elem.value;
});
});
Drupal.gmap.addHandler('gmap',function(elem) {
Drupal.gmap.addHandler('gmap', function (elem) {
var obj = this;
// Add status bar
var status = $(elem).after('<div class="gmap-statusbar">Status</div>').next();
obj.statusdiv = status[0];
obj.bind('buildmacro',function(add) {
obj.bind('buildmacro', function (add) {
var temp, i, q, tm, ct;
var style_line = function(n) {
if (!n.style.length) { return '';};
var style = n.style.slice(0,3);
var style_line = function (n) {
if (!n.style.length) {
return '';
}
var style = n.style.slice(0, 3);
style[0] = '#' + style[0];
return style.join('/') + ':';
}
var style_poly = function(n) {
if (!n.style.length) { return '';};
};
var style_poly = function (n) {
if (!n.style.length) {
return '';
}
var style = n.style.slice();
style[0] = '#' + style[0];
style[3] = '#' + style[3];
return style.join('/') + ':';
}
};
var feature_dump = function(n) {
var feature_dump = function (n) {
var f = n.overlay;
var tmp = [];
var i, ct, vtx;
......@@ -108,7 +115,7 @@ Drupal.gmap.addHandler('gmap',function(elem) {
var polylines = [];
var circles = [];
var markers = {};
$.each(obj._oe.features, function(i,n) {
$.each(obj._oe.features, function (i, n) {
if (n.type) {
switch (n.type) {
case 'polyline':
......@@ -118,7 +125,9 @@ Drupal.gmap.addHandler('gmap',function(elem) {
add.push('polygon=' + style_poly(n) + feature_dump(n));
break;
case 'point':
if (!markers[n.marker]) { markers[n.marker] = [];};
if (!markers[n.marker]) {
markers[n.marker] = [];
}
var pt = n.overlay.getLatLng();
var ptxt = '';
if (n.html) {
......@@ -132,7 +141,7 @@ Drupal.gmap.addHandler('gmap',function(elem) {
}
}
});
$.each(markers, function(i, n) {
$.each(markers, function (i, n) {
add.push('markers=' + i + '::' + n.join(' + '));
});
}
......@@ -141,7 +150,7 @@ Drupal.gmap.addHandler('gmap',function(elem) {
Drupal.gmap.map.prototype.statusdiv = undefined;
Drupal.gmap.map.prototype.status = function(text) {
Drupal.gmap.map.prototype.status = function (text) {
var obj = this;
if (obj.statusdiv) {
$(obj.statusdiv).html(text);
......@@ -149,7 +158,7 @@ Drupal.gmap.map.prototype.status = function(text) {
};
// Extend markers to store type info.
GMarker.prototype.gmapMarkerData = function(data) {
GMarker.prototype.gmapMarkerData = function (data) {
if (data) {
this._gmapdata = data;
}
......@@ -157,31 +166,32 @@ GMarker.prototype.gmapMarkerData = function(data) {
};
/************* Overlay edit widget ******************/
Drupal.gmap.addHandler('overlayedit',function(elem) {
Drupal.gmap.addHandler('overlayedit', function (elem) {
var obj = this;
var binding = obj.bind('overlay_edit_mode',function() {
var binding = obj.bind('overlay_edit_mode', function () {
// @@@
});
$(elem).change(function() {
$(elem).change(function () {
obj.vars.overlay_next_icon = elem.value;
// obj.vars.overlay_edit_mode = elem.value;
// obj.change('overlay_edit_mode',binding);
});
obj.bind('init', function() {
obj.bind('init', function () {
obj._oe = {};
obj.vars.overlay_add_mode = 'Points'; //elem.value;
obj.vars.overlay_del_mode = 'Remove';
var edit_text_elem;
if(obj.map) {
if (obj.map) {
obj._oe.features = [];
obj._oe.featuresRef = {};
obj._oe.editing = false;
obj._oe.markerseq = {};
GEvent.addListener(obj.map, 'click', function(overlay, point) {
GEvent.addListener(obj.map, 'click', function (overlay, point) {
var ctx, s, p;
if (overlay) {
if (obj._oe.editing) {
// Work around problem where double clicking to finish a poly fires a click event.
......@@ -195,18 +205,20 @@ Drupal.gmap.addHandler('overlayedit',function(elem) {
switch (obj.vars.overlay_add_mode) {
case 'Points':
var m = elem.value; // @@@ It's kinda silly to be binding the whole shebang to this dropdown..
if (!obj._oe.markerseq.hasOwnProperty(m)) {obj._oe.markerseq[m] = -1;};
if (!obj._oe.markerseq.hasOwnProperty(m)) {
obj._oe.markerseq[m] = -1;
}
obj._oe.markerseq[m] = obj._oe.markerseq[m] + 1;
var p = new GMarker(point,{icon:Drupal.gmap.getIcon(m, obj._oe.markerseq[m])});
p = new GMarker(point, {icon: Drupal.gmap.getIcon(m, obj._oe.markerseq[m])});
obj.map.addOverlay(p);
var ctx = {
ctx = {
'type' : 'point',
'marker' : m,
'overlay' : p
};
var offset = obj._oe.features.push(ctx) - 1;
obj._oe.editing = false;
GEvent.addListener(p, "click", function() {
GEvent.addListener(p, "click", function () {
switch (obj.vars.overlay_del_mode) {
case 'Remove':
obj._oe.markerseq[m] = obj._oe.markerseq[m] - 1;
......@@ -215,14 +227,17 @@ Drupal.gmap.addHandler('overlayedit',function(elem) {
ctx.overlay = null;
var tmpcnt = 0;
// Renumber markers in set.
$.each(obj._oe.features, function(i, n) {
if (n.type && n.type == 'point' && n.marker == m) {
$.each(obj._oe.features, function (i, n) {
if (n.type && n.type === 'point' && n.marker === m) {
var pt = n.overlay.getLatLng();
n.overlay.setImage(Drupal.gmap.getIcon(n.marker, tmpcnt).image);
tmpcnt = tmpcnt + 1;
}
});
break;
case 'Edit info':
// @@@
break;
}
obj.change('mapedited', -1);
});
......@@ -230,17 +245,17 @@ Drupal.gmap.addHandler('overlayedit',function(elem) {
break;
case 'Lines':
var ctx = {
ctx = {
'type' : 'polyline',
'style' : [],
'overlay' : null
};
var s = obj.vars.styles['line_default'];
s = obj.vars.styles.line_default;
if (obj.vars.overlay_linestyle_apply) {
ctx.style = obj.vars.styles.overlayline.slice();
s = ctx.style;
}
var p = new GPolyline([point], '#' + s[0], Number(s[1]), s[2] / 100);
p = new GPolyline([point], '#' + s[0], Number(s[1]), s[2] / 100);
obj.map.addOverlay(p);
ctx.overlay = p;
obj._oe.featuresRef[p] = obj._oe.features.push(ctx) - 1;
......@@ -248,11 +263,13 @@ Drupal.gmap.addHandler('overlayedit',function(elem) {
p.enableDrawing();
p.enableEditing({onEvent: "mouseover"});
p.disableEditing({onEvent: "mouseout"});
GEvent.addListener(p, "endline", function() {
GEvent.addListener(p, "endline", function () {
//obj._oe.editing = false;
GEvent.addListener(p, "lineupdated", function(){obj.change('mapedited', -1);});
GEvent.addListener(p, "click", function(latlng, index) {
if (typeof index == "number") {
GEvent.addListener(p, "lineupdated", function () {
obj.change('mapedited', -1);
});
GEvent.addListener(p, "click", function (latlng, index) {
if (typeof index === "number") {
// Delete vertex on click.
p.deleteVertex(index);
}
......@@ -267,17 +284,17 @@ Drupal.gmap.addHandler('overlayedit',function(elem) {
break;
case 'GPolygon':
var ctx = {
ctx = {
'type' : 'polygon',
'style' : [],
'overlay' : null
};
var s = obj.vars.styles['poly_default'];
s = obj.vars.styles.poly_default;
if (obj.vars.overlay_polystyle_apply) {
ctx.style = obj.vars.styles.overlaypoly.slice();
s = ctx.style;
}
var p = new GPolygon([point], '#' + s[0], Number(s[1]), s[2] / 100, '#' + s[3], s[4] / 100);
p = new GPolygon([point], '#' + s[0], Number(s[1]), s[2] / 100, '#' + s[3], s[4] / 100);
obj.map.addOverlay(p);
ctx.overlay = p;
obj._oe.featuresRef[p] = obj._oe.features.push(ctx) - 1;
......@@ -285,11 +302,13 @@ Drupal.gmap.addHandler('overlayedit',function(elem) {
p.enableDrawing();
p.enableEditing({onEvent: "mouseover"});
p.disableEditing({onEvent: "mouseout"});
GEvent.addListener(p, "endline", function() {
GEvent.addListener(p, "endline", function () {
//obj._oe.editing = false;
GEvent.addListener(p, "lineupdated", function(){obj.change('mapedited', -1);});
GEvent.addListener(p, "click", function(latlng, index) {
if (typeof index == "number") {
GEvent.addListener(p, "lineupdated", function () {
obj.change('mapedited', -1);
});
GEvent.addListener(p, "click", function (latlng, index) {
if (typeof index === "number") {
p.deleteVertex(index);
}
else {
......@@ -298,7 +317,7 @@ Drupal.gmap.addHandler('overlayedit',function(elem) {
feature.fill = obj.vars.fill;
p.setStrokeStyle(feature.stroke);
p.setFillStyle(feature.fill); // @@@
}
}
});
obj.change('mapedited', -1);
});
......@@ -309,7 +328,7 @@ Drupal.gmap.addHandler('overlayedit',function(elem) {
// @@@ Translate
obj.status("Drawing circle. Click a point on the rim to place.");
var handle = GEvent.addListener(obj.map, 'click', function(overlay, point) {
var handle = GEvent.addListener(obj.map, 'click', function (overlay, point) {
if (point) {
var ctx = {
'type' : 'circle',
......@@ -318,24 +337,27 @@ Drupal.gmap.addHandler('overlayedit',function(elem) {
'style' : [],
'overlay' : null
};
var s = obj.vars.styles['poly_default'];
var s = obj.vars.styles.poly_default;
if (obj.vars.overlay_polystyle_apply) {
ctx.style = obj.vars.styles.overlaypoly.slice();
s = ctx.style;
}
obj.status("Placed circle. Radius was "+ temppoint.distanceFrom(point) / 1000 + " km.");
obj.status("Placed circle. Radius was " + temppoint.distanceFrom(point) / 1000 + " km.");
ctx.radius = temppoint.distanceFrom(point);
var p = new GPolygon(obj.poly.calcPolyPoints(ctx.center, ctx.radius, 32), '#' + s[0], Number(s[1]), s[2] / 100, '#' + s[3], s[4] / 100);
obj.map.addOverlay(p);
ctx.overlay = p;
obj._oe.featuresRef[p] = obj._oe.features.push(ctx) - 1;
GEvent.addListener(p, "click", function() {
GEvent.addListener(p, "click", function () {
switch (obj.vars.overlay_del_mode) {
case 'Remove':
ctx.type = 'deleted';
obj.map.removeOverlay(p);
ctx.overlay = null;
break;
case 'Edit info':
// @@@
break;
}
obj.change('mapedited', -1);
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment