| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
Ext.namespace("GeoExt.ux") |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
GeoExt.ux.Measure = Ext.extend(GeoExt.Action, { |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
tip: null, |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
template: null, |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
constructor: function(handler, config) { |
|---|
| 54 |
config.control = this.buildControl({ |
|---|
| 55 |
handler: handler, |
|---|
| 56 |
styleMap: config.styleMap || this.styleMap() |
|---|
| 57 |
}); |
|---|
| 58 |
delete config.styleMap; |
|---|
| 59 |
if (typeof(config.template) == "string") { |
|---|
| 60 |
this.template = new Ext.XTemplate(config.template, { |
|---|
| 61 |
decimals: config.decimals || 2, |
|---|
| 62 |
compiled: true |
|---|
| 63 |
}); |
|---|
| 64 |
} else if (config.template instanceof Ext.XTemplate) { |
|---|
| 65 |
this.template = config.template; |
|---|
| 66 |
} |
|---|
| 67 |
delete config.template; |
|---|
| 68 |
delete config.decimals; |
|---|
| 69 |
arguments.callee.superclass.constructor.call(this, config); |
|---|
| 70 |
}, |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
buildControl: function(options) { |
|---|
| 82 |
var listeners = { |
|---|
| 83 |
"measure": OpenLayers.Function.bind(this.display, this), |
|---|
| 84 |
"deactivate": OpenLayers.Function.bind(this.cleanup, this), |
|---|
| 85 |
"measurepartial": OpenLayers.Function.bind(this.cleanup, this) |
|---|
| 86 |
}; |
|---|
| 87 |
return new OpenLayers.Control.Measure( |
|---|
| 88 |
options.handler, { |
|---|
| 89 |
persist: true, |
|---|
| 90 |
eventListeners: listeners, |
|---|
| 91 |
handlerOptions: { |
|---|
| 92 |
layerOptions: { |
|---|
| 93 |
styleMap: options.styleMap |
|---|
| 94 |
} |
|---|
| 95 |
} |
|---|
| 96 |
} |
|---|
| 97 |
); |
|---|
| 98 |
}, |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
cleanup: function() { |
|---|
| 104 |
if (this.tip) { |
|---|
| 105 |
this.tip.destroy(); |
|---|
| 106 |
this.tip = null; |
|---|
| 107 |
} |
|---|
| 108 |
}, |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
makeString: function(event) { |
|---|
| 118 |
return this.template.apply(event); |
|---|
| 119 |
}, |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
display: function(event) { |
|---|
| 127 |
this.cleanup(); |
|---|
| 128 |
this.tip = new Ext.Tip({ |
|---|
| 129 |
html: this.makeString(event), |
|---|
| 130 |
closable: true, |
|---|
| 131 |
draggable: false, |
|---|
| 132 |
listeners: { |
|---|
| 133 |
hide: function() { |
|---|
| 134 |
this.control.cancel(); |
|---|
| 135 |
this.cleanup(); |
|---|
| 136 |
}, |
|---|
| 137 |
scope: this |
|---|
| 138 |
} |
|---|
| 139 |
}); |
|---|
| 140 |
Ext.getBody().on("mousemove", function(e) { |
|---|
| 141 |
this.tip.showAt(e.getXY()); |
|---|
| 142 |
}, this, { |
|---|
| 143 |
single: true |
|---|
| 144 |
}); |
|---|
| 145 |
}, |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
styleMap: function() { |
|---|
| 153 |
var sketchSymbolizers = { |
|---|
| 154 |
"Point": { |
|---|
| 155 |
pointRadius: 4, |
|---|
| 156 |
graphicName: "square", |
|---|
| 157 |
fillColor: "white", |
|---|
| 158 |
fillOpacity: 1, |
|---|
| 159 |
strokeWidth: 1, |
|---|
| 160 |
strokeOpacity: 1, |
|---|
| 161 |
strokeColor: "#333333" |
|---|
| 162 |
}, |
|---|
| 163 |
"Line": { |
|---|
| 164 |
strokeWidth: 2, |
|---|
| 165 |
strokeOpacity: 1, |
|---|
| 166 |
strokeColor: "#666666", |
|---|
| 167 |
strokeDashstyle: "dash" |
|---|
| 168 |
}, |
|---|
| 169 |
"Polygon": { |
|---|
| 170 |
strokeWidth: 2, |
|---|
| 171 |
strokeOpacity: 1, |
|---|
| 172 |
strokeColor: "#666666", |
|---|
| 173 |
fillColor: "white", |
|---|
| 174 |
fillOpacity: 0.3 |
|---|
| 175 |
} |
|---|
| 176 |
}; |
|---|
| 177 |
return new OpenLayers.StyleMap({ |
|---|
| 178 |
"default": new OpenLayers.Style(null, { |
|---|
| 179 |
rules: [new OpenLayers.Rule({symbolizer: sketchSymbolizers})] |
|---|
| 180 |
}) |
|---|
| 181 |
}); |
|---|
| 182 |
} |
|---|
| 183 |
}); |
|---|