/
jquery.mapquery.mqFeatureInfo.js
91 lines (75 loc) · 2.84 KB
/
jquery.mapquery.mqFeatureInfo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* Copyright (c) 2011 by MapQuery Contributors (see AUTHORS for
* full list of contributors). Published under the MIT license.
* See https://github.com/mapquery/mapquery/blob/master/LICENSE for the
* full text of the license. */
/**
#jquery.mapquery.mqFeatureInfo.js
The file containing the mqFeatureInfo Widget
### *$('selector')*.`mqFeatureInfo([options])`
_version added 0.1_
####**Description**: create a widget to show feature information
+ **options**
- **map**: the mapquery instance
- **contents**: A function that returns HTML to be put into the popup.
It has one argument, which is the OpenLayers feature that was selected.
- **title**: Title that will be displayed at the top of the feature
info (default: Feature information)
>Returns: widget
The mqFeatureInfo widget allows us to display the information
of a selected feature.
$('#featureinfo').mqFeatureInfo({
map: '#map',
contents: function(feature) {
return '<p>' + feature.properties.id + '</p>';
}
});
*/
(function($) {
$.template('mqFeatureInfo',
'<div class="mq-featureinfo ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">' +
'<span class="ui-dialog-title">${title}</span>' +
'</div>' +
'<div" class="ui-dialog-content ui-widget-content">{{html contents}}</div>');
$.widget("mapQuery.mqFeatureInfo", {
options: {
// The MapQuery instance
map: undefined,
// A function that returns HTML to be put into the popup.
// It has one argument, which is the OpenLayers feature that
// was selected.
contents: undefined,
// Title that will be displayed at the top of the feature info
title: "Feature information"
},
_create: function() {
var map;
var self = this;
var element = this.element;
//get the mapquery object
map = $(this.options.map).data('mapQuery');
this.element.addClass('ui-dialog ui-widget ui-widget-content ' +
'ui-corner-all');
map.bind("featureselected", {widget: self}, self._onFeatureselected);
map.bind("featureunselected", {widget: self},
self._onFeatureunselected);
},
_destroy: function() {
this.element.removeClass('ui-dialog ui-widget ui-widget-content ' +
'ui-corner-all')
.empty();
},
_onFeatureselected: function(evt, layer, feature) {
var self = evt.data.widget;
var element = self.element;
var contents = self.options.contents.call(self.options, feature);
element.html($.tmpl('mqFeatureInfo', {
title: self.options.title,
contents: contents
}));
},
_onFeatureunselected: function(evt) {
var self = evt.data.widget;
self.element.empty();
}
});
})(jQuery);