| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
Ext.namespace('GeoExt.ux'); |
|---|
| 16 |
|
|---|
| 17 |
GeoExt.ux.RoutingPanel = Ext.extend(Ext.Panel, { |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
map: null, |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
startLocationCombo: null, |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
endLocationCombo: null, |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
proxy: null, |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
routingStore: null, |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
lang: 'en', |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
routingServiceType: 'cloudmade', |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
routingVersionCloudmade: null, |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
routingStatusCloudmade: null, |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
routingStatusMessageCloudmade: null, |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
routingRouteSummaryCloudmade: null, |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
routingRouteGeometryCloudmade: null, |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
routingRouteInstructionsCloudmade: null, |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
routingLayer: null, |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
routingRecenterMap: true, |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
routingPathFeature: null, |
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
routingStartFeature: null, |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
routingEndFeature: null, |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
routingPointDrawControl: null, |
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
routingResultPanel: null, |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
route_typeCloudmade: 'car', |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
cloudmadeKey: null, |
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
geocodingType: 'cloudmade', |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
geocodingQueryParam: 'query', |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
geocodingMaxRows: 20, |
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
geocodingUrl: null, |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
showGoogleItinerary: true, |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
routingStyle: { |
|---|
| 211 |
strokeColor: "#0000FF", |
|---|
| 212 |
strokeOpacity: 0.5, |
|---|
| 213 |
strokeWidth: 5 |
|---|
| 214 |
}, |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
vectorStyle: new OpenLayers.StyleMap({ |
|---|
| 223 |
"default": new OpenLayers.Style({ |
|---|
| 224 |
pointRadius: "8", |
|---|
| 225 |
fillColor: "#FF0000", |
|---|
| 226 |
fillOpacity: 0.5, |
|---|
| 227 |
strokeColor: "#FF0000", |
|---|
| 228 |
strokeOpacity: 1, |
|---|
| 229 |
strokeWidth: 1 |
|---|
| 230 |
}) |
|---|
| 231 |
}), |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
routingProjection: new OpenLayers.Projection("EPSG:4326"), |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
readPermalink: true, |
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
initComponent : function() { |
|---|
| 253 |
var defConfig = { |
|---|
| 254 |
plain: true, |
|---|
| 255 |
border: false |
|---|
| 256 |
}; |
|---|
| 257 |
|
|---|
| 258 |
Ext.applyIf(this, defConfig); |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
if (this.geocodingType == 'cloudmade') { |
|---|
| 262 |
this.geocodingUrl = 'http://geocoding.cloudmade.com/' + this.cloudmadeKey + '/geocoding/v2/find.js?results=' + this.geocodingMaxRows + '&return_geometry=false'; |
|---|
| 263 |
this.startLocationCombo = new Ext.form.ComboBox({ |
|---|
| 264 |
fieldLabel: OpenLayers.i18n('A'), |
|---|
| 265 |
name: 'startLocationCombo', |
|---|
| 266 |
emptyText: OpenLayers.i18n('Search start...'), |
|---|
| 267 |
minChars: 1, |
|---|
| 268 |
queryDelay: 50, |
|---|
| 269 |
hideTrigger: true, |
|---|
| 270 |
charset: 'UTF8', |
|---|
| 271 |
forceSelection: true, |
|---|
| 272 |
displayField: 'name', |
|---|
| 273 |
queryParam: this.geocodingQueryParam, |
|---|
| 274 |
tpl: '<tpl for="."><div class="x-combo-list-item"><h1>{name}</h1></div></tpl>', |
|---|
| 275 |
store: new Ext.data.Store({ |
|---|
| 276 |
proxy: new Ext.data.ScriptTagProxy({ |
|---|
| 277 |
url: this.geocodingUrl, |
|---|
| 278 |
method: 'GET' |
|---|
| 279 |
}), |
|---|
| 280 |
reader: new Ext.data.JsonReader({ |
|---|
| 281 |
totalProperty: "found", |
|---|
| 282 |
root: "features", |
|---|
| 283 |
fields: [ |
|---|
| 284 |
{ |
|---|
| 285 |
name: 'name', |
|---|
| 286 |
mapping: 'properties.name' |
|---|
| 287 |
}, |
|---|
| 288 |
{ |
|---|
| 289 |
name: 'centroid' |
|---|
| 290 |
} |
|---|
| 291 |
] |
|---|
| 292 |
}) |
|---|
| 293 |
}), |
|---|
| 294 |
listeners: { |
|---|
| 295 |
"select": function(combo, record, index) { |
|---|
| 296 |
if (this.routingStartFeature) { |
|---|
| 297 |
this.routingLayer.removeFeatures([this.routingStartFeature]); |
|---|
| 298 |
} |
|---|
| 299 |
this.startLocationCombo.locationString = record.data.centroid.coordinates[0] + ',' + record.data.centroid.coordinates[1]; |
|---|
| 300 |
}, |
|---|
| 301 |
scope: this |
|---|
| 302 |
} |
|---|
| 303 |
}); |
|---|
| 304 |
|
|---|
| 305 |
this.endLocationCombo = new Ext.form.ComboBox({ |
|---|
| 306 |
fieldLabel: OpenLayers.i18n('B'), |
|---|
| 307 |
name: 'endLocationCombo', |
|---|
| 308 |
emptyText: OpenLayers.i18n('Search end...'), |
|---|
| 309 |
minChars: 1, |
|---|
| 310 |
queryDelay: 50, |
|---|
| 311 |
hideTrigger: true, |
|---|
| 312 |
charset: 'UTF8', |
|---|
| 313 |
forceSelection: true, |
|---|
| 314 |
displayField: 'name', |
|---|
| 315 |
queryParam: this.geocodingQueryParam, |
|---|
| 316 |
tpl: '<tpl for="."><div class="x-combo-list-item"><h1>{name}</h1></div></tpl>', |
|---|
| 317 |
store: new Ext.data.Store({ |
|---|
| 318 |
proxy: new Ext.data.ScriptTagProxy({ |
|---|
| 319 |
url: this.geocodingUrl, |
|---|
| 320 |
method: 'GET' |
|---|
| 321 |
}), |
|---|
| 322 |
reader: new Ext.data.JsonReader({ |
|---|
| 323 |
totalProperty: "found", |
|---|
| 324 |
root: "features", |
|---|
| 325 |
fields: [ |
|---|
| 326 |
{ |
|---|
| 327 |
name: 'name', |
|---|
| 328 |
mapping: 'properties.name' |
|---|
| 329 |
}, |
|---|
| 330 |
{ |
|---|
| 331 |
name: 'centroid' |
|---|
| 332 |
} |
|---|
| 333 |
] |
|---|
| 334 |
}) |
|---|
| 335 |
}), |
|---|
| 336 |
listeners: { |
|---|
| 337 |
"select": function(combo, record, index) { |
|---|
| 338 |
if (this.routingEndFeature) { |
|---|
| 339 |
this.routingLayer.removeFeatures([this.routingEndFeature]); |
|---|
| 340 |
} |
|---|
| 341 |
this.endLocationCombo.locationString = record.data.centroid.coordinates[0] + ',' + record.data.centroid.coordinates[1]; |
|---|
| 342 |
}, |
|---|
| 343 |
scope: this |
|---|
| 344 |
} |
|---|
| 345 |
}); |
|---|
| 346 |
} |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
if (this.geocodingType == 'geonames') { |
|---|
| 350 |
this.startLocationCombo = new GeoExt.ux.geonames.GeoNamesSearchCombo({ |
|---|
| 351 |
fieldLabel: OpenLayers.i18n('A'), |
|---|
| 352 |
map: this.map, |
|---|
| 353 |
zoom: 13 |
|---|
| 354 |
}); |
|---|
| 355 |
this.startLocationCombo.on( |
|---|
| 356 |
"select", function(combo, record, index) { |
|---|
| 357 |
if (this.routingStartFeature) { |
|---|
| 358 |
this.routingLayer.removeFeatures([this.routingStartFeature]); |
|---|
| 359 |
} |
|---|
| 360 |
this.startLocationCombo.locationString = record.data.lat + ',' + record.data.lng; |
|---|
| 361 |
}, this |
|---|
| 362 |
); |
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
this.endLocationCombo = new GeoExt.ux.geonames.GeoNamesSearchCombo({ |
|---|
| 366 |
fieldLabel: OpenLayers.i18n('B'), |
|---|
| 367 |
map: this.map, |
|---|
| 368 |
zoom: 13 |
|---|
| 369 |
}); |
|---|
| 370 |
this.endLocationCombo.on("select", function(combo, record, index) { |
|---|
| 371 |
if (this.routingEndFeature) { |
|---|
| 372 |
this.routingLayer.removeFeatures([this.routingEndFeature]); |
|---|
| 373 |
} |
|---|
| 374 |
this.endLocationCombo.locationString = record.data.lat + ',' + record.data.lng; |
|---|
| 375 |
}, this); |
|---|
| 376 |
} |
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
this.routingResultPanel = new Ext.Panel({ |
|---|
| 380 |
border: false, |
|---|
| 381 |
html: '', |
|---|
| 382 |
bodyStyle: 'padding:5px 5px 5px 5px;' |
|---|
| 383 |
}); |
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
if (!this.startLocationCombo.locationString) { |
|---|
| 387 |
this.startLocationCombo.locationString = '47.25976,9.58423'; |
|---|
| 388 |
} |
|---|
| 389 |
if (!this.endLocationCombo.locationString) { |
|---|
| 390 |
this.endLocationCombo.locationString = '47.26117,9.59882'; |
|---|
| 391 |
} |
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
this.items = [ |
|---|
| 395 |
{ |
|---|
| 396 |
layout: 'form', |
|---|
| 397 |
border:false, |
|---|
| 398 |
labelWidth: 10, |
|---|
| 399 |
items: [ |
|---|
| 400 |
{ |
|---|
| 401 |
layout: 'column', |
|---|
| 402 |
border: false, |
|---|
| 403 |
defaults:{ |
|---|
| 404 |
layout:'form', |
|---|
| 405 |
border:false, |
|---|
| 406 |
labelWidth: 10, |
|---|
| 407 |
bodyStyle:'padding:5px 0px 0px 5px' |
|---|
| 408 |
}, |
|---|
| 409 |
items:[ |
|---|
| 410 |
{ |
|---|
| 411 |
columnWidth:0.75, |
|---|
| 412 |
defaults:{ |
|---|
| 413 |
anchor:'100%' |
|---|
| 414 |
}, |
|---|
| 415 |
items: [ |
|---|
| 416 |
this.startLocationCombo |
|---|
| 417 |
] |
|---|
| 418 |
}, |
|---|
| 419 |
{ |
|---|
| 420 |
columnWidth:0.25, |
|---|
| 421 |
items: [ |
|---|
| 422 |
{ |
|---|
| 423 |
xtype:'button', |
|---|
| 424 |
text: OpenLayers.i18n('Get Point'), |
|---|
| 425 |
handler: function(button, event) { |
|---|
| 426 |
this.routingPointDrawControl.type = 'GetStartPoint'; |
|---|
| 427 |
this.routingPointDrawControl.activate(); |
|---|
| 428 |
}, |
|---|
| 429 |
scope: this |
|---|
| 430 |
} |
|---|
| 431 |
] |
|---|
| 432 |
} |
|---|
| 433 |
] |
|---|
| 434 |
}, |
|---|
| 435 |
{ |
|---|
| 436 |
layout: 'column', |
|---|
| 437 |
border: false, |
|---|
| 438 |
defaults:{ |
|---|
| 439 |
layout:'form', |
|---|
| 440 |
border:false, |
|---|
| 441 |
labelWidth: 10, |
|---|
| 442 |
bodyStyle:'padding:0px 0px 0px 5px;' |
|---|
| 443 |
}, |
|---|
| 444 |
items:[ |
|---|
| 445 |
{ |
|---|
| 446 |
columnWidth:0.75, |
|---|
| 447 |
defaults:{ |
|---|
| 448 |
anchor:'100%' |
|---|
| 449 |
}, |
|---|
| 450 |
items: [ |
|---|
| 451 |
this.endLocationCombo |
|---|
| 452 |
] |
|---|
| 453 |
}, |
|---|
| 454 |
{ |
|---|
| 455 |
columnWidth:0.25, |
|---|
| 456 |
items: [ |
|---|
| 457 |
{ |
|---|
| 458 |
xtype:'button', |
|---|
| 459 |
text: OpenLayers.i18n('Get Point'), |
|---|
| 460 |
handler: function(button, event) { |
|---|
| 461 |
this.routingPointDrawControl.type = 'GetEndPoint'; |
|---|
| 462 |
this.routingPointDrawControl.activate(); |
|---|
| 463 |
}, |
|---|
| 464 |
scope: this |
|---|
| 465 |
} |
|---|
| 466 |
] |
|---|
| 467 |
} |
|---|
| 468 |
] |
|---|
| 469 |
} |
|---|
| 470 |
] |
|---|
| 471 |
}, |
|---|
| 472 |
{ |
|---|
| 473 |
layout: 'column', |
|---|
| 474 |
border: false, |
|---|
| 475 |
items: [ |
|---|
| 476 |
{ |
|---|
| 477 |
columnWidth: 1, |
|---|
| 478 |
border: false, |
|---|
| 479 |
bodyCfg: {tag:'center'}, |
|---|
| 480 |
items: [ |
|---|
| 481 |
{ |
|---|
| 482 |
xtype:'button', |
|---|
| 483 |
text: OpenLayers.i18n('Compute itinerary'), |
|---|
| 484 |
handler: function() { |
|---|
| 485 |
this.getItinerary(); |
|---|
| 486 |
}, |
|---|
| 487 |
scope: this |
|---|
| 488 |
} |
|---|
| 489 |
] |
|---|
| 490 |
} |
|---|
| 491 |
] |
|---|
| 492 |
|
|---|
| 493 |
}, |
|---|
| 494 |
{ |
|---|
| 495 |
border: false, |
|---|
| 496 |
items: [ |
|---|
| 497 |
this.routingResultPanel |
|---|
| 498 |
] |
|---|
| 499 |
} |
|---|
| 500 |
|
|---|
| 501 |
]; |
|---|
| 502 |
|
|---|
| 503 |
this.addEvents( |
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
'routingcomputed', |
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
'beforeroutingcomputed'); |
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
GeoExt.ux.RoutingPanel.superclass.initComponent.call(this); |
|---|
| 522 |
}, |
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
afterRender: function() { |
|---|
| 528 |
GeoExt.ux.RoutingPanel.superclass.afterRender.call(this); |
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
if (!this.routingLayer) { |
|---|
| 532 |
this.routingLayer = new OpenLayers.Layer.Vector("Routing", {styleMap: this.vectorStyle}); |
|---|
| 533 |
} |
|---|
| 534 |
this.map.addLayer(this.routingLayer); |
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
this.routingPointDrawControl = new OpenLayers.Control.DrawFeature(this.routingLayer, OpenLayers.Handler.Point); |
|---|
| 538 |
this.map.addControl(this.routingPointDrawControl); |
|---|
| 539 |
this.routingPointDrawControl.events.on({ "featureadded": function(events) { |
|---|
| 540 |
var featureLocation = null; |
|---|
| 541 |
if (this.routingPointDrawControl.type == 'GetStartPoint') { |
|---|
| 542 |
if (this.routingStartFeature) { |
|---|
| 543 |
this.routingLayer.removeFeatures([this.routingStartFeature]); |
|---|
| 544 |
this.routingStartFeature = null; |
|---|
| 545 |
} |
|---|
| 546 |
this.routingStartFeature = events.feature; |
|---|
| 547 |
featureLocation = this.routingStartFeature.geometry.clone(); |
|---|
| 548 |
featureLocation.transform(this.map.getProjectionObject(), this.routingProjection); |
|---|
| 549 |
this.startLocationCombo.locationString = featureLocation.y + ',' + featureLocation.x; |
|---|
| 550 |
this.startLocationCombo.emptyText = OpenLayers.i18n('Position: ') + Math.round(featureLocation.y * 100000) / 100000 + ',' + Math.round(featureLocation.x * 100000) / 100000; |
|---|
| 551 |
this.startLocationCombo.clearValue(); |
|---|
| 552 |
} |
|---|
| 553 |
if (this.routingPointDrawControl.type == 'GetEndPoint') { |
|---|
| 554 |
if (this.routingEndFeature) { |
|---|
| 555 |
this.routingLayer.removeFeatures([this.routingEndFeature]); |
|---|
| 556 |
this.routingEndFeature = null; |
|---|
| 557 |
} |
|---|
| 558 |
this.routingEndFeature = events.feature; |
|---|
| 559 |
featureLocation = this.routingEndFeature.geometry.clone(); |
|---|
| 560 |
featureLocation.transform(this.map.getProjectionObject(), this.routingProjection); |
|---|
| 561 |
this.endLocationCombo.locationString = featureLocation.y + ',' + featureLocation.x; |
|---|
| 562 |
this.endLocationCombo.emptyText = OpenLayers.i18n('Position: ') + Math.round(featureLocation.y * 100000) / 100000 + ',' + Math.round(featureLocation.x * 100000) / 100000; |
|---|
| 563 |
this.endLocationCombo.clearValue(); |
|---|
| 564 |
} |
|---|
| 565 |
this.routingPointDrawControl.deactivate(); |
|---|
| 566 |
}, |
|---|
| 567 |
scope: this |
|---|
| 568 |
}); |
|---|
| 569 |
|
|---|
| 570 |
if (this.readPermalink) { |
|---|
| 571 |
var parameters = OpenLayers.Util.getParameters(); |
|---|
| 572 |
this.setPermalink(parameters); |
|---|
| 573 |
} |
|---|
| 574 |
} |
|---|
| 575 |
, |
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 |
|
|---|
| 582 |
getPermalink: function(complete) { |
|---|
| 583 |
var permalink; |
|---|
| 584 |
if (complete) { |
|---|
| 585 |
permalink = window.location.href; |
|---|
| 586 |
if (OpenLayers.String.contains(permalink, '?')) { |
|---|
| 587 |
var end = permalink.indexOf('?'); |
|---|
| 588 |
permalink = permalink.substring(0, end); |
|---|
| 589 |
} |
|---|
| 590 |
permalink = permalink + "?"; |
|---|
| 591 |
} else { |
|---|
| 592 |
permalink = ''; |
|---|
| 593 |
} |
|---|
| 594 |
|
|---|
| 595 |
permalink = permalink + "routingReadPermalink=" + this.readPermalink; |
|---|
| 596 |
permalink = permalink + "&routingRecenterMap=" + this.routingRecenterMap; |
|---|
| 597 |
|
|---|
| 598 |
if (this.startLocationCombo.locationString && this.routingPathFeature) { |
|---|
| 599 |
permalink = permalink + "&routingStartLocationString=" + this.startLocationCombo.locationString; |
|---|
| 600 |
} |
|---|
| 601 |
if (this.endLocationCombo.locationString && this.routingPathFeature) { |
|---|
| 602 |
permalink = permalink + "&routingEndLocationString=" + this.endLocationCombo.locationString; |
|---|
| 603 |
} |
|---|
| 604 |
if (this.startLocationCombo.value) { |
|---|
| 605 |
permalink = permalink + "&routingStartLocationValue=" + this.startLocationCombo.value; |
|---|
| 606 |
} |
|---|
| 607 |
if (this.endLocationCombo.value) { |
|---|
| 608 |
permalink = permalink + "&routingEndLocationValue=" + this.endLocationCombo.value; |
|---|
| 609 |
} |
|---|
| 610 |
if (this.startLocationCombo.emptyText.indexOf(OpenLayers.i18n('Position: ')) > -1) { |
|---|
| 611 |
permalink = permalink + "&routingStartLocationEmptyText=" + this.startLocationCombo.emptyText; |
|---|
| 612 |
} |
|---|
| 613 |
if (this.endLocationCombo.emptyText.indexOf(OpenLayers.i18n('Position: ')) > -1) { |
|---|
| 614 |
permalink = permalink + "&routingEndLocationEmptyText=" + this.endLocationCombo.emptyText; |
|---|
| 615 |
} |
|---|
| 616 |
if (this.map && !this.routingRecenterMap) { |
|---|
| 617 |
permalink = permalink + "&routingeasting=" + this.map.getCenter().lon; |
|---|
| 618 |
permalink = permalink + "&routingnorthing=" + this.map.getCenter().lat; |
|---|
| 619 |
permalink = permalink + "&routingzoom=" + this.map.getZoom(); |
|---|
| 620 |
} |
|---|
| 621 |
return permalink; |
|---|
| 622 |
} |
|---|
| 623 |
, |
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
|
|---|
| 627 |
|
|---|
| 628 |
|
|---|
| 629 |
|
|---|
| 630 |
setPermalink: function(parameters) { |
|---|
| 631 |
if (parameters.routingReadPermalink) { |
|---|
| 632 |
this.readPermalink = this.stringToBoolean(parameters.routingReadPermalink); |
|---|
| 633 |
} |
|---|
| 634 |
if (parameters.routingRecenterMap) { |
|---|
| 635 |
this.routingRecenterMap = this.stringToBoolean(parameters.routingRecenterMap); |
|---|
| 636 |
} |
|---|
| 637 |
if (parameters.routingStartLocationString) { |
|---|
| 638 |
this.startLocationCombo.locationString = parameters.routingStartLocationString[0] + "," + parameters.routingStartLocationString[1]; |
|---|
| 639 |
} |
|---|
| 640 |
if (parameters.routingEndLocationString) { |
|---|
| 641 |
this.endLocationCombo.locationString = parameters.routingEndLocationString[0] + "," + parameters.routingEndLocationString[1]; |
|---|
| 642 |
} |
|---|
| 643 |
if (parameters.routingStartLocationString && parameters.routingEndLocationString) { |
|---|
| 644 |
this.getItinerary(); |
|---|
| 645 |
} |
|---|
| 646 |
if (parameters.routingeasting && parameters.routingnorthing) { |
|---|
| 647 |
var position = new OpenLayers.LonLat(parseFloat(parameters.routingeasting), parseFloat(parameters.routingnorthing)); |
|---|
| 648 |
if (this.map) { |
|---|
| 649 |
this.map.setCenter(position); |
|---|
| 650 |
} |
|---|
| 651 |
} |
|---|
| 652 |
if (parameters.routingzoom) { |
|---|
| 653 |
if (this.map) { |
|---|
| 654 |
this.map.zoomTo(parseInt(parameters.routingzoom, 10)); |
|---|
| 655 |
} |
|---|
| 656 |
} |
|---|
| 657 |
if (parameters.routingStartLocationValue) { |
|---|
| 658 |
this.startLocationCombo.setValue(parameters.routingStartLocationValue); |
|---|
| 659 |
} |
|---|
| 660 |
if (parameters.routingEndLocationValue) { |
|---|
| 661 |
this.endLocationCombo.setValue(parameters.routingEndLocationValue); |
|---|
| 662 |
} |
|---|
| 663 |
if (parameters.routingStartLocationEmptyText) { |
|---|
| 664 |
this.startLocationCombo.emptyText = parameters.routingStartLocationEmptyText.toString(); |
|---|
| 665 |
} |
|---|
| 666 |
if (parameters.routingEndLocationEmptyText) { |
|---|
| 667 |
this.endLocationCombo.emptyText = parameters.routingEndLocationEmptyText.toString(); |
|---|
| 668 |
} |
|---|
| 669 |
}, |
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
|
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
|
|---|
| 676 |
stringToBoolean: function(string) { |
|---|
| 677 |
switch (string.toLowerCase()) { |
|---|
| 678 |
case "true": case "yes": case "1": return true; |
|---|
| 679 |
case "false": case "no": case "0": case null: return false; |
|---|
| 680 |
default: return Boolean(string); |
|---|
| 681 |
} |
|---|
| 682 |
}, |
|---|
| 683 |
|
|---|
| 684 |
|
|---|
| 685 |
|
|---|
| 686 |
|
|---|
| 687 |
getItinerary: function() { |
|---|
| 688 |
if (this.routingServiceType == 'cloudmade') { |
|---|
| 689 |
|
|---|
| 690 |
this.fireEvent('beforeroutingcomputed', this); |
|---|
| 691 |
this.routingResultPanel.html = OpenLayers.i18n('Computation ongoing....'); |
|---|
| 692 |
if (this.routingResultPanel.body) { |
|---|
| 693 |
this.routingResultPanel.body.update(this.routingResultPanel.html); |
|---|
| 694 |
} |
|---|
| 695 |
|
|---|
| 696 |
var newUrl = this.startLocationCombo.locationString + ',' + this.endLocationCombo.locationString; |
|---|
| 697 |
newUrl = newUrl + "/" + this.route_typeCloudmade + ".js?lang=" + this.lang; |
|---|
| 698 |
this.proxy = new Ext.data.ScriptTagProxy({ |
|---|
| 699 |
url: "http://routes.cloudmade.com/" + this.cloudmadeKey + "/api/0.3/" + newUrl, |
|---|
| 700 |
nocache: false |
|---|
| 701 |
}); |
|---|
| 702 |
this.routingStore = new Ext.data.Store({ |
|---|
| 703 |
proxy: this.proxy, |
|---|
| 704 |
reader: new Ext.data.JsonReader({ |
|---|
| 705 |
root: 'version', |
|---|
| 706 |
fields: [ |
|---|
| 707 |
{ |
|---|
| 708 |
name: 'total_length' |
|---|
| 709 |
} |
|---|
| 710 |
] |
|---|
| 711 |
|
|---|
| 712 |
}) |
|---|
| 713 |
}); |
|---|
| 714 |
|
|---|
| 715 |
this.routingStore.on( |
|---|
| 716 |
'load', function(store) { |
|---|
| 717 |
this.routingVersionCloudmade = store.reader.jsonData.version; |
|---|
| 718 |
this.routingStatusCloudmade = store.reader.jsonData.status; |
|---|
| 719 |
if (store.reader.jsonData.status_message) { |
|---|
| 720 |
this.routingStatusMessageCloudmade = store.reader.jsonData.status_message; |
|---|
| 721 |
} |
|---|
| 722 |
if (store.reader.jsonData.route_summary) { |
|---|
| 723 |
this.routingRouteSummaryCloudmade = store.reader.jsonData.route_summary; |
|---|
| 724 |
} |
|---|
| 725 |
if (store.reader.jsonData.route_geometry) { |
|---|
| 726 |
this.routingRouteGeometryCloudmade = store.reader.jsonData.route_geometry; |
|---|
| 727 |
} |
|---|
| 728 |
if (store.reader.jsonData.route_instructions) { |
|---|
| 729 |
this.routingRouteInstructionsCloudmade = store.reader.jsonData.route_instructions; |
|---|
| 730 |
} |
|---|
| 731 |
if (this.routingStatusCloudmade == '0') { |
|---|
| 732 |
this.drawRoute(); |
|---|
| 733 |
var googleLinks = '' |
|---|
| 734 |
if (this.showGoogleItinerary) { |
|---|
| 735 |
var googleLinks = '<a href="http://maps.google.com/maps?source=s_d&saddr=' + this.startLocationCombo.locationString + '&daddr=' + this.endLocationCombo.locationString + '&dirflg=a" target="new">' + OpenLayers.i18n('Google Itinerary by car') + '</a><br><a href="http://maps.google.com/maps?source=s_d&saddr=' + this.startLocationCombo.locationString + '&daddr=' + this.endLocationCombo.locationString + '&dirflg=r" target="new">' + OpenLayers.i18n('Google Itinerary by public transport') + '</a><br><a href="http://maps.google.com/maps?source=s_d&saddr=' + this.startLocationCombo.locationString + '&daddr=' + this.endLocationCombo.locationString + '&dirflg=w" target="new">' + OpenLayers.i18n('Google Itinerary on foot') + '</a>'; |
|---|
| 736 |
} |
|---|
| 737 |
this.routingResultPanel.html = OpenLayers.i18n('Total length: ') + Math.round(this.routingRouteSummaryCloudmade.total_distance / 1000) + ' [km]<br>' + googleLinks; |
|---|
| 738 |
this.routingResultPanel.body.update(this.routingResultPanel.html); |
|---|
| 739 |
} else { |
|---|
| 740 |
this.routingResultPanel.html = this.routingStatusMessageCloudmade; |
|---|
| 741 |
this.routingResultPanel.body.update(this.routingResultPanel.html); |
|---|
| 742 |
} |
|---|
| 743 |
this.fireEvent('routingcomputed', this); |
|---|
| 744 |
}, this); |
|---|
| 745 |
this.routingStore.load(); |
|---|
| 746 |
} else { |
|---|
| 747 |
alert('Routing service: ' + this.routingServiceType + ' not supported. Patch welcome !'); |
|---|
| 748 |
} |
|---|
| 749 |
}, |
|---|
| 750 |
|
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 |
|
|---|
| 754 |
clearItinerary: function() { |
|---|
| 755 |
if (this.routingPathFeature) { |
|---|
| 756 |
this.routingLayer.removeFeatures([this.routingPathFeature]); |
|---|
| 757 |
} |
|---|
| 758 |
this.startLocationCombo.clearValue(); |
|---|
| 759 |
this.endLocationCombo.clearValue(); |
|---|
| 760 |
if (this.routingStartFeature) { |
|---|
| 761 |
this.routingLayer.removeFeatures([this.routingStartFeature]); |
|---|
| 762 |
this.routingStartFeature = null; |
|---|
| 763 |
} |
|---|
| 764 |
if (this.routingEndFeature) { |
|---|
| 765 |
this.routingLayer.removeFeatures([this.routingEndFeature]); |
|---|
| 766 |
this.routingEndFeature = null; |
|---|
| 767 |
} |
|---|
| 768 |
this.routingResultPanel.html = ''; |
|---|
| 769 |
this.routingResultPanel.body.update(this.routingResultPanel.html); |
|---|
| 770 |
}, |
|---|
| 771 |
|
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 |
|
|---|
| 775 |
drawRoute: function() { |
|---|
| 776 |
var pointList = []; |
|---|
| 777 |
|
|---|
| 778 |
if (this.routingServiceType == 'cloudmade') { |
|---|
| 779 |
var newPoint = null; |
|---|
| 780 |
for (var i = 0; i < this.routingRouteGeometryCloudmade.length; i++) { |
|---|
| 781 |
newPoint = new OpenLayers.Geometry.Point(this.routingRouteGeometryCloudmade[i][1], |
|---|
| 782 |
this.routingRouteGeometryCloudmade[i][0]); |
|---|
| 783 |
newPoint.transform(this.routingProjection, |
|---|
| 784 |
this.map.getProjectionObject()); |
|---|
| 785 |
pointList.push(newPoint); |
|---|
| 786 |
} |
|---|
| 787 |
} |
|---|
| 788 |
|
|---|
| 789 |
if (this.routingPathFeature) { |
|---|
| 790 |
this.routingLayer.removeFeatures([this.routingPathFeature]); |
|---|
| 791 |
} |
|---|
| 792 |
this.routingPathFeature = new OpenLayers.Feature.Vector( |
|---|
| 793 |
new OpenLayers.Geometry.LineString(pointList), null, this.routingStyle); |
|---|
| 794 |
|
|---|
| 795 |
this.routingLayer.addFeatures([this.routingPathFeature]); |
|---|
| 796 |
if (this.routingRecenterMap) { |
|---|
| 797 |
this.map.zoomToExtent(this.routingPathFeature.geometry.bounds); |
|---|
| 798 |
} |
|---|
| 799 |
} |
|---|
| 800 |
}); |
|---|
| 801 |
|
|---|
| 802 |
|
|---|
| 803 |
Ext.reg('gxux_routingpanel', GeoExt.ux.RoutingPanel); |
|---|