2 * @fileoverview functions used for visualizing GIS data
5 * @requires jquery/jquery.svg.js
6 * @requires jquery/jquery.mousewheel.js
7 * @requires jquery/jquery.event.drag-2.0.min.js
18 * Zooms and pans the visualization.
22 var g = svg.getElementById('groupPanel');
24 g.setAttribute('transform', 'translate(' + x + ', ' + y + ') scale(' + scale + ')');
27 $('circle.vector').each(function() {
28 id = $(this).attr('id');
29 circle = svg.getElementById(id);
32 "stroke-width" : (2 / scale)
37 $('polyline.vector').each(function() {
38 id = $(this).attr('id');
39 line = svg.getElementById(id);
41 "stroke-width" : (2 / scale)
46 $('path.vector').each(function() {
47 id = $(this).attr('id');
48 polygon = svg.getElementById(id);
50 "stroke-width" : (0.5 / scale)
56 * Initially loads either SVG or OSM visualization based on the choice.
58 function selectVisualization() {
59 if ($('#choice').prop('checked') != true) {
60 $('#openlayersmap').hide();
62 $('#placeholder').hide();
68 * Adds necessary styles to the div that coontains the openStreetMap.
71 var $placeholder = $('#placeholder');
73 'border' : '1px solid #aaa',
74 'width' : $placeholder.width(),
75 'height' : $placeholder.height(),
78 $('#openlayersmap').css(cssObj);
82 * Loads the SVG element and make a reference to it.
85 var $placeholder = $('#placeholder');
88 onLoad: function(svg_ref) {
93 // Removes the second SVG element unnecessarily added due to the above command
94 $placeholder.find('svg:nth-child(2)').remove();
98 * Adds controllers for zooming and panning.
100 function addZoomPanControllers() {
101 var $placeholder = $('#placeholder');
102 if ($("#placeholder svg").length > 0) {
103 var pmaThemeImage = $('#pmaThemeImage').attr('value');
104 // add panning arrows
105 $('<img class="button" id="left_arrow" src="' + pmaThemeImage + 'west-mini.png">').appendTo($placeholder);
106 $('<img class="button" id="right_arrow" src="' + pmaThemeImage + 'east-mini.png">').appendTo($placeholder);
107 $('<img class="button" id="up_arrow" src="' + pmaThemeImage + 'north-mini.png">').appendTo($placeholder);
108 $('<img class="button" id="down_arrow" src="' + pmaThemeImage + 'south-mini.png">').appendTo($placeholder);
109 // add zooming controls
110 $('<img class="button" id="zoom_in" src="' + pmaThemeImage + 'zoom-plus-mini.png">').appendTo($placeholder);
111 $('<img class="button" id="zoom_world" src="' + pmaThemeImage + 'zoom-world-mini.png">').appendTo($placeholder);
112 $('<img class="button" id="zoom_out" src="' + pmaThemeImage + 'zoom-minus-mini.png">').appendTo($placeholder);
117 * Resizes the GIS visualization to fit into the space available.
119 function resizeGISVisualization() {
120 var $placeholder = $('#placeholder');
122 // Hide inputs for width and height
123 $("input[name='visualizationSettings[width]']").parents('tr').remove();
124 $("input[name='visualizationSettings[height]']").parents('tr').remove();
126 var old_width = $placeholder.width();
127 var extraPadding = 100;
128 var leftWidth = $('.gis_table').width();
129 var windowWidth = document.documentElement.clientWidth;
130 var visWidth = windowWidth - extraPadding - leftWidth;
132 // Assign new value for width
133 $placeholder.width(visWidth);
134 $('svg').attr('width', visWidth);
136 // Assign the offset created due to resizing to default_x and center the svg.
137 default_x = (visWidth - old_width) / 2;
142 * Initialize the GIS visualization.
144 function initGISVisualization() {
145 // Loads either SVG or OSM visualization based on the choice
146 selectVisualization();
147 // Resizes the GIS visualization to fit into the space available
148 resizeGISVisualization();
149 // Adds necessary styles to the div that coontains the openStreetMap
151 // Draws openStreetMap with openLayers
153 // Loads the SVG element and make a reference to it
155 // Adds controllers for zooming and panning
156 addZoomPanControllers();
161 * Ajax handlers for GIS visualization page
163 * Actions Ajaxified here:
165 * Zooming in and zooming out on mousewheel movement.
166 * Panning the visualization on dragging.
167 * Zooming in on double clicking.
168 * Zooming out on clicking the zoom out button.
169 * Panning on clicking the arrow buttons.
170 * Displaying tooltips for GIS objects.
172 $(document).ready(function() {
174 // If we are in GIS visualization, initialize it
175 if ($('.gis_table').length > 0) {
176 initGISVisualization();
179 $('#choice').live('click', function() {
180 if ($(this).prop('checked') == false) {
181 $('#placeholder').show();
182 $('#openlayersmap').hide();
184 $('#placeholder').hide();
185 $('#openlayersmap').show();
189 $('#placeholder').live('mousewheel', function(event, delta) {
193 // zooming in keeping the position under mouse pointer unmoved.
194 x = event.layerX - (event.layerX - x) * 1.5;
195 y = event.layerY - (event.layerY - y) * 1.5;
200 // zooming out keeping the position under mouse pointer unmoved.
201 x = event.layerX - (event.layerX - x) / 1.5;
202 y = event.layerY - (event.layerY - y) / 1.5;
208 var dragX = 0; var dragY = 0;
209 $('svg').live('dragstart', function(event, dd) {
210 $('#placeholder').addClass('placeholderDrag');
211 dragX = Math.round(dd.offsetX);
212 dragY = Math.round(dd.offsetY);
215 $('svg').live('mouseup', function(event) {
216 $('#placeholder').removeClass('placeholderDrag');
219 $('svg').live('drag', function(event, dd) {
220 newX = Math.round(dd.offsetX);
223 newY = Math.round(dd.offsetY);
229 $('#placeholder').live('dblclick', function(event) {
231 // zooming in keeping the position under mouse pointer unmoved.
232 x = event.layerX - (event.layerX - x) * 1.5;
233 y = event.layerY - (event.layerY - y) * 1.5;
237 $('#zoom_in').live('click', function(e) {
242 width = $('#placeholder svg').attr('width');
243 height = $('#placeholder svg').attr('height');
244 // zooming in keeping the center unmoved.
245 x = width / 2 - (width / 2 - x) * 1.5;
246 y = height / 2 - (height / 2 - y) * 1.5;
250 $('#zoom_world').live('click', function(e) {
258 $('#zoom_out').live('click', function(e) {
263 width = $('#placeholder svg').attr('width');
264 height = $('#placeholder svg').attr('height');
265 // zooming out keeping the center unmoved.
266 x = width / 2 - (width / 2 - x) / 1.5;
267 y = height / 2 - (height / 2 - y) / 1.5;
271 $('#left_arrow').live('click', function(e) {
277 $('#right_arrow').live('click', function(e) {
283 $('#up_arrow').live('click', function(e) {
289 $('#down_arrow').live('click', function(e) {
296 * Detect the mousemove event and show tooltips.
298 $('.polygon, .multipolygon, .point, .multipoint, .linestring, .multilinestring, '
299 + '.geometrycollection').live('mousemove', function(event) {
300 contents = $.trim($(this).attr('name'));
301 $("#tooltip").remove();
302 if (contents != '') {
303 $('<div id="tooltip">' + contents + '</div>').css({
304 position : 'absolute',
306 top : event.pageY + 10,
307 left : event.pageX + 10,
308 border : '1px solid #fdd',
310 'background-color' : '#fee',
312 }).appendTo("body").fadeIn(200);
317 * Detect the mouseout event and hide tooltips.
319 $('.polygon, .multipolygon, .point, .multipoint, .linestring, .multilinestring, '
320 + '.geometrycollection').live('mouseout', function(event) {
321 $("#tooltip").remove();