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
16 * Zooms and pans the visualization.
18 function zoomAndPan() {
19 var g
= svg
.getElementById('groupPanel');
21 g
.setAttribute('transform', 'translate(' + x
+ ', ' + y
+ ') scale(' + scale
+ ')');
24 $('circle.vector').each(function() {
25 id
= $(this).attr('id');
26 circle
= svg
.getElementById(id
);
29 "stroke-width" : (2 / scale
)
34 $('polyline.vector').each(function() {
35 id
= $(this).attr('id');
36 line
= svg
.getElementById(id
);
38 "stroke-width" : (2 / scale
)
43 $('path.vector').each(function() {
44 id
= $(this).attr('id');
45 polygon
= svg
.getElementById(id
);
47 "stroke-width" : (0.5 / scale
)
53 * Ajax handlers for GIS visualization page
55 * Actions Ajaxified here:
57 * Zooming in and zooming out on mousewheel movement.
58 * Panning the visualization on dragging.
59 * Zooming in on double clicking.
60 * Zooming out on clicking the zoom out button.
61 * Panning on clicking the arrow buttons.
62 * Displaying tooltips for GIS objects.
64 $(document
).ready(function() {
65 var $placeholder
= $('#placeholder');
66 var $openlayersmap
= $('#openlayersmap');
68 if ($('#choice').prop('checked') != true) {
69 $openlayersmap
.hide();
75 'border' : '1px solid #aaa',
76 'width' : $placeholder
.width(),
77 'height' : $placeholder
.height(),
80 $openlayersmap
.css(cssObj
);
84 $('#choice').bind('click', function() {
85 if ($(this).prop('checked') == false) {
87 $openlayersmap
.hide();
90 $openlayersmap
.show();
94 $('#placeholder').svg({
95 onLoad: function(svg_ref
) {
100 // Removes the second SVG element unnecessarily added due to the above command.
101 $('#placeholder').find('svg:nth-child(2)').remove();
103 if ($("#placeholder svg").length
> 0) {
104 var pmaThemeImage
= $('#pmaThemeImage').attr('value');
105 // add panning arrows
106 $('<img class="button" id="left_arrow" src="' + pmaThemeImage
+ 'west-mini.png">').appendTo($placeholder
);
107 $('<img class="button" id="right_arrow" src="' + pmaThemeImage
+ 'east-mini.png">').appendTo($placeholder
);
108 $('<img class="button" id="up_arrow" src="' + pmaThemeImage
+ 'north-mini.png">').appendTo($placeholder
);
109 $('<img class="button" id="down_arrow" src="' + pmaThemeImage
+ 'south-mini.png">').appendTo($placeholder
);
110 // add zooming controls
111 $('<img class="button" id="zoom_in" src="' + pmaThemeImage
+ 'zoom-plus-mini.png">').appendTo($placeholder
);
112 $('<img class="button" id="zoom_world" src="' + pmaThemeImage
+ 'zoom-world-mini.png">').appendTo($placeholder
);
113 $('<img class="button" id="zoom_out" src="' + pmaThemeImage
+ 'zoom-minus-mini.png">').appendTo($placeholder
);
116 $('#placeholder').live('mousewheel', function(event
, delta
) {
120 // zooming in keeping the position under mouse pointer unmoved.
121 x
= event
.layerX
- (event
.layerX
- x
) * 1.5;
122 y
= event
.layerY
- (event
.layerY
- y
) * 1.5;
127 // zooming out keeping the position under mouse pointer unmoved.
128 x
= event
.layerX
- (event
.layerX
- x
) / 1.5;
129 y
= event
.layerY
- (event
.layerY
- y
) / 1.5;
135 var dragX
= 0; var dragY
= 0;
136 $('svg').live('dragstart', function(event
, dd
) {
137 $placeholder
.addClass('placeholderDrag');
138 dragX
= Math
.round(dd
.offsetX
);
139 dragY
= Math
.round(dd
.offsetY
);
142 $('svg').live('mouseup', function(event
) {
143 $placeholder
.removeClass('placeholderDrag');
146 $('svg').live('drag', function(event
, dd
) {
147 newX
= Math
.round(dd
.offsetX
);
150 newY
= Math
.round(dd
.offsetY
);
156 $('#placeholder').live('dblclick', function(event
) {
158 // zooming in keeping the position under mouse pointer unmoved.
159 x
= event
.layerX
- (event
.layerX
- x
) * 1.5;
160 y
= event
.layerY
- (event
.layerY
- y
) * 1.5;
164 $('#zoom_in').live('click', function(e
) {
169 width
= $('#placeholder svg').attr('width');
170 height
= $('#placeholder svg').attr('height');
171 // zooming in keeping the center unmoved.
172 x
= width
/ 2 - (width
/ 2 - x
) * 1.5;
173 y
= height
/ 2 - (height
/ 2 - y
) * 1.5;
177 $('#zoom_world').live('click', function(e
) {
185 $('#zoom_out').live('click', function(e
) {
190 width
= $('#placeholder svg').attr('width');
191 height
= $('#placeholder svg').attr('height');
192 // zooming out keeping the center unmoved.
193 x
= width
/ 2 - (width
/ 2 - x
) / 1.5;
194 y
= height
/ 2 - (height
/ 2 - y
) / 1.5;
198 $('#left_arrow').live('click', function(e
) {
204 $('#right_arrow').live('click', function(e
) {
210 $('#up_arrow').live('click', function(e
) {
216 $('#down_arrow').live('click', function(e
) {
223 * Detect the mousemove event and show tooltips.
225 $('.polygon, .multipolygon, .point, .multipoint, .linestring, .multilinestring, '
226 + '.geometrycollection').live('mousemove', function(event
) {
227 contents
= $(this).attr('name');
228 $("#tooltip").remove();
229 if (contents
!= '') {
230 $('<div id="tooltip">' + contents
+ '</div>').css({
231 position
: 'absolute',
233 top
: event
.pageY
+ 10,
234 left
: event
.pageX
+ 10,
235 border
: '1px solid #fdd',
237 'background-color' : '#fee',
239 }).appendTo("body").fadeIn(200);
244 * Detect the mouseout event and hide tooltips.
246 $('.polygon, .multipolygon, .point, .multipoint, .linestring, .multilinestring, '
247 + '.geometrycollection').live('mouseout', function(event
) {
248 $("#tooltip").remove();