Retour à la documentation
/**
* @class spw.widgets.SpwRouting
*/
define(["dojo/_base/declare", "spw/api/SpwBaseTemplatedWidget", "dojo/text!./templates/SpwRouting.html",
"dojo/_base/lang", "dojo/_base/array", "spw/api/MessageManager", "dojo/i18n!./nls/SpwRouting",
"esri/symbols/SimpleLineSymbol", "spw/widgets/SpwQuickAddressSearch", "dojo/topic",
"esri/symbols/PictureMarkerSymbol", "dojo/dom-construct", "dojo/_base/Color", "dojo/dom-style",
"dojo/has", "dojo/_base/config", "dojo/text!./templates/SpwRoutingResultItem.html",
"esri/geometry/Polyline", "esri/geometry/Point", "esri/graphic", "spw/api/Utils",
"spw/api/ProjectionManager", "dojo/query",
"dijit/form/RadioButton", "dijit/form/Button", "dojo/_base/sniff"],
function(declare, SpwBaseTemplatedWidget, template, lang, array, MessageManager, labels,
SimpleLineSymbol, SpwQuickAddressSearch, topic, PictureMarkerSymbol, domConstruct,
Color, domStyle, has, djConfig, SpwRoutingResultItemTemplate, Polyline, Point,
Graphic, Utils, ProjectionManager, DojoQuery) {
/**
* Event envoyé lorsque le calcul d'itinéraire est effectué avec succès
* @event
* @memberOf spw.api.SpwRoutingWidget#
*/
SPW_ROUTING_WIDGET_SUCCESS = "SPW_ROUTING_WIDGET/SUCCESS";
/**
* Event envoyé lorsqu'une erreur se produit lors du calcul d'itinéraire
* @event
* @memberOf spw.api.SpwRoutingWidget#
*/
SPW_ROUTING_WIDGET_ERROR = "SPW_ROUTING_WIDGET/ERROR";
/**
* Event envoyé lorsque l'utilisateur click sur le bouton afin d'envoyer la requête pour le calcul d'itinéraire
* @event
* @memberOf spw.api.SpwRoutingWidget#
*/
SPW_ROUTING_WIDGET_ON_SEARCH_RESULTAT_CLICKED = "SPW_ROUTING_WIDGET/ON_SEARCH_RESULTAT_CLICKED";
/**
* Event envoyé lorsqu'une position valide est trouvée lorsque l'utilisateur choisi le départ ou l'arrivée pour le calcul d'itinéraire au click sur la carte
* @event
* @memberOf spw.api.SpwRoutingWidget#
*/
SPW_ROUTING_WIDGET_GET_NEAREST_POSITION_RESULT = "SPW_ROUTING_WIDGET/GET_NEAREST_POSITION_RESULT";
/**
* Event envoyé en cas d'erreur lorsque l'utilisateur choisi le départ ou l'arrivée pour le calcul d'itinéraire au click sur la carte
* @event
* @memberOf spw.api.SpwRoutingWidget#
*/
SPW_ROUTING_WIDGET_GET_NEAREST_POSITION_ERROR = "SPW_ROUTING_WIDGET/GET_NEAREST_POSITION_ERROR";
var SpwRouting = declare("spw.widgets.SpwRouting", [SpwBaseTemplatedWidget], /** @lends spw.widgets.SpwRouting.prototype */{
templateString: template,
labels: labels,
geolocalisationApiUrl: "//geoservices.wallonie.be/geolocalisation/js/SpwGeolocalisationApi.js",
geolocSrid: 31370,
routingApiUrl: "//geoservices.wallonie.be/routing/js/SpwRoutingApi.js",
routingSrid: 31370,
/**
* L'outil est-il initialisé?
* @private
* @type Boolean
*/
_initialized: false,
_itineraireGraphic: null,
_itineraireLineSymbole: SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([0,255,255,0.5]),
5),
_departPointGraphic: null,
_departPreviewPointGraphic: null,
_departPointSymbol: null,
_arriveePointGraphic: null,
_arriveePreviewPointGraphic: null,
_arriveePointSymbol: null,
_spwGeolocalisationSearchInputDepart: null,
_spwGeolocalisationSearchInputArrivee: null,
zoomOnResultClick: false,
_depart: null,
_arrivee: null,
_result: null,
_selectOnMap: null,
_printMode:"default",
_btnPrepareSelectDepartOnMap: null,
_config:null,
_w: null,
iconClass: "routingIcon",
/**
* @constructs _
*/
constructor : function(config) {
this.set('inToolbar', true);
this._label = this.labels.spwRoutingWidgetTitle;
this._config = config;
this.resizable = false;
},
postCreate: function(){
this.inherited(arguments);
var ctxt=this;
this._spwGeolocalisationSearchInputDepart = new SpwQuickAddressSearch({
spwViewer: this.spwViewer,
inWidget: true,
onDisplayResult: lang.hitch(this, this.onDisplayResultDepart),
_displayedTypes: ['POSITION','RUE'],
_resultClickedListener: lang.hitch(this, this.onResultClickedDepart)
});
this._spwGeolocalisationSearchInputDepart.setReplaceSearchValueOnClickItem();
domConstruct.place(this._spwGeolocalisationSearchInputDepart.domNode, this._spwGeolocalisationSearchInputDepartHolder, "last");
this._spwGeolocalisationSearchInputArrivee = new SpwQuickAddressSearch({
spwViewer: this.spwViewer,
inWidget: true,
onDisplayResult: lang.hitch(this, this.onDisplayResultArrive),
_displayedTypes: ['POSITION','RUE'],
_resultClickedListener: lang.hitch(this, this.onResultClickedArrivee)
});
this._spwGeolocalisationSearchInputArrivee.setReplaceSearchValueOnClickItem();
domConstruct.place(this._spwGeolocalisationSearchInputArrivee.domNode, this._spwGeolocalisationSearchInputArriveeHolder, "last");
// this.setContent(this.domNode);
topic.subscribe(SPW_ROUTING_WIDGET_SUCCESS+this.id, lang.hitch(this, this.computeRouteSuccessHandler));
topic.subscribe(SPW_ROUTING_WIDGET_ERROR+this.id, lang.hitch(this, this.computeRouteErrorHandler));
topic.subscribe(SPW_ROUTING_WIDGET_ON_SEARCH_RESULTAT_CLICKED+this.id, lang.hitch(this, this.onSearchResultatClicked));
topic.subscribe(SPW_ROUTING_WIDGET_GET_NEAREST_POSITION_RESULT+this.id, lang.hitch(this, this.getNearestPositionResult));
topic.subscribe(SPW_ROUTING_WIDGET_GET_NEAREST_POSITION_ERROR+this.id, lang.hitch(this, this.getNearestPositionError));
this.spwViewer.get('spwMap').on(this.spwViewer.get('spwMap').events.MapClicked, lang.hitch(this, this.onSpwMapClick));
this._departPointSymbol = PictureMarkerSymbol(this.imagesPath + "SpwRoutingWidgetFlagDepart.png", 24, 24);
this._departPointSymbol.setOffset(2, 10);
this._arriveePointSymbol = PictureMarkerSymbol(this.imagesPath + "SpwRoutingWidgetFlagArrivee.png", 24, 24);
this._arriveePointSymbol.setOffset(2, 10);
this._initialized = true;
},
onDisplayResultDepart: function() {
var resultList = DojoQuery(".SpwGeolocalisationSearchInputResult", this._spwGeolocalisationSearchInputDepart.domNode)[0];
resultList.style.position = 'inherit';
resultList.style.position = 'fixed';
},
onDisplayResultArrive: function() {
var resultList = DojoQuery(".SpwGeolocalisationSearchInputResult", this._spwGeolocalisationSearchInputArrivee.domNode)[0];
resultList.style.position = 'inherit';
resultList.style.position = 'fixed';
},
onActivate: function(){
this.inherited(arguments);
// this._panel.domNode.style.left="";
// this._panel.domNode.style.right="10px";
},
onDeactivate: function(){
this.raz();
this.inherited(arguments);
},
raz: function() {
this._spwGeolocalisationSearchInputDepart.reset();
this._spwGeolocalisationSearchInputArrivee.reset();
this._depart = null;
this._arrivee = null;
this.removeResult();
this.removeItineraireGraphic();
},
callRouting: function() {
require([this.routingApiUrl], lang.hitch(this, function(){
if(typeof(spwRouting) == "undefined"){
MessageManager.getInstance().notifyError(this.labels.routingServiceUnavailable);
}
else {
this.spwViewer.trackEvent("spw.widgets.SpwRouting", "callRouting", this._spwGeolocalisationSearchInputDepart.getLabel() + " - " + this._spwGeolocalisationSearchInputArrivee.getLabel());
if(this._depart != null && this._arrivee != null) {
this.showLoading();
this.removeItineraireGraphic();
this.removeResult();
var etapes =
'[' +
'{"idTroncon":'+(this._depart.idTroncon || this._depart.idTronconCentral)+',"fraction":'+(this._depart.fraction || 0.5)+',"cote":"'+(this._depart.cote||"D")+'"},' +
'{"idTroncon":'+(this._arrivee.idTroncon || this._arrivee.idTronconCentral)+',"fraction":'+(this._arrivee.fraction || 0.5)+',"cote":"'+(this._arrivee.cote||"D")+'"}'+
']';
var ctxt = this;
spwRouting.computeRoute(
(this.routePrefShortest.checked ? "SHORTEST" : "FASTEST"),
(djConfig.locale == "fr" ? "FRENCH" : "GERMAN"),
etapes,
function(result) {
topic.publish(SPW_ROUTING_WIDGET_SUCCESS+ctxt.id, result);
},
function(request, status, error) {
topic.publish(SPW_ROUTING_WIDGET_ERROR+ctxt.id, request, status, error);
});
}
else {
MessageManager.getInstance().notifyWarning(this.labels.pleaseSelectStartAndEnd);
}
}
}));
},
computeRouteSuccessHandler: function(result) {
this.hideLoading();
if(result.errorCode == 0) {
this.displayResult(result);
}
else if(result.errorCode == 1) {
MessageManager.getInstance().notifyError(this.labels.errorOccuredWhileComputing + "<br/>" + result.errorMsg);
}
else {
MessageManager.getInstance().notifyWarning(result.errorMsg);
}
},
computeRouteErrorHandler: function(request, status, error) {
this.hideLoading();
console.log(error);
MessageManager.getInstance().notifyError(this.labels.errorOccuredWhileComputing);
},
displayResult: function(result) {
this._result = result;
this.addItineraireGraphic();
try{
// domStyle.set(this._panel.containerNode,"overflow","hidden");
domStyle.set(this.routingResultDiv,"margin","3px");
}catch(e){}
// this.resizePanel(this.width, 500);
// this._panel.domNode.style.left="";
// this._panel.domNode.style.right="10px";
domStyle.set(this.routingResultDiv, "display", "");
this.distanceTd.innerHTML = this.labels.distance + " : " + Utils.toDistanceString(this._result.distance);
this.dureeTd.innerHTML = this.labels.duration + " : " + Utils.toDureeString(this._result.temps, djConfig.locale);
for(var i=0;i<this._result.segments.length;i++) {
var spwRoutingResultItem = new SpwRoutingResultItem({
labels: this.labels,
spwViewer: this.spwViewer,
_segment: this._result.segments[i],
_first: (i == 0),
_rowNum:i,
_last: false,
_parent: this
});
domConstruct.place(spwRoutingResultItem.domNode, this.routingResultListDiv, "last");
if(i == this._result.segments.length - 1) {
var spwRoutingResultItemArrivee = new SpwRoutingResultItem({
labels: this.labels,
spwViewer: this.spwViewer,
_coordonneesFin: this._result.coordonnees[this._result.coordonnees.length - 1],
_first: false,
_last: true,
_rowNum:i+1,
_parent: this
});
domConstruct.place(spwRoutingResultItemArrivee.domNode, this.routingResultListDiv, "last");
}
}
},
removeResult: function() {
this._result = null;
if(this.routingResultListDiv) {
domConstruct.empty(this.routingResultListDiv);
}
domStyle.set(this.routingResultDiv, "display", "none");
// this.resizePanel(this.width, 140);
},
addItineraireGraphic: function() {
this.removeItineraireGraphic();
var geometry = new Polyline(this.spwViewer.get('spatialReference'));
var points = new Array();
for(var i=0; i<this._result.coordonnees.length; i++) {
var pt = new Point(this._result.coordonnees[i].x, this._result.coordonnees[i].y, this.spwViewer.get('spatialReference'));
if (this.geolocSrid != this.spwViewer.get('spwMap').esriMap.spatialReference.wkid) {
var res = ProjectionManager.getInstance().transform(this.geolocSrid, this.spwViewer.get('spwMap').esriMap.spatialReference.wkid, pt.x, pt.y);
pt = new Point(res.x, res.y, this.spwViewer.get('spatialReference'));
}
if(i == 0) {
this._departPointGraphic = new Graphic(pt, this._departPointSymbol);
}
else if(i == this._result.coordonnees.length - 1) {
this._arriveePointGraphic = new Graphic(pt, this._arriveePointSymbol);
}
points.push(pt);
}
geometry.addPath(points);
this._itineraireGraphic = Graphic(geometry, this._itineraireLineSymbole);
// this.spwViewer.get('spwMap').showGraphic(this._itineraireGraphic, "SpwRoutingWidget");
// this.spwViewer.get('spwMap').showGraphic(this._departPointGraphic, "SpwRoutingWidget");
// this.spwViewer.get('spwMap').showGraphic(this._arriveePointGraphic, "SpwRoutingWidget");
this.spwViewer.get('spwMap').get('esriMap').graphics.add(this._itineraireGraphic);
this.spwViewer.get('spwMap').get('esriMap').graphics.add(this._departPointGraphic);
this.spwViewer.get('spwMap').get('esriMap').graphics.add(this._arriveePointGraphic);
this.spwViewer.get('spwMap').zoomToExtent(geometry.getExtent());
},
removeItineraireGraphic: function() {
if(this._itineraireGraphic!=null){
this._itineraireGraphic.hide();
this._departPointGraphic.hide();
this._arriveePointGraphic.hide();
this.spwViewer.get('spwMap').get('esriMap').graphics.remove(this._itineraireGraphic);
this.spwViewer.get('spwMap').get('esriMap').graphics.remove(this._departPointGraphic);
this.spwViewer.get('spwMap').get('esriMap').graphics.remove(this._arriveePointGraphic);
this._itineraireGraphic = null;
this._departPointGraphic = null;
this._arriveePointGraphic = null;
}
if (this._departPreviewPointGraphic) {
this._departPreviewPointGraphic.hide();
}
if (this._arriveePreviewPointGraphic) {
this._arriveePreviewPointGraphic.hide();
}
this.spwViewer.get('spwMap').get('esriMap').graphics.remove(this._departPreviewPointGraphic);
this.spwViewer.get('spwMap').get('esriMap').graphics.remove(this._arriveePreviewPointGraphic);
},
onResultClickedDepart: function(data) {
topic.publish(SPW_ROUTING_WIDGET_ON_SEARCH_RESULTAT_CLICKED + this.id, "D", data);
},
onResultClickedArrivee: function(data) {
topic.publish(SPW_ROUTING_WIDGET_ON_SEARCH_RESULTAT_CLICKED+this.id, "A", data);
},
onSearchResultatClicked: function(type, data) {
if(type == "D") {
this._depart = data;
}
else {
this._arrivee = data;
}
this.addFlag(data, type);
var x = data.x || data.xMin;
var y = data.y || data.yMin;
if(x && y && this.zoomOnResultClick){
this.spwViewer.get('spwMap').zoomToPoint(x, y, 200);
}
},
prepareSelectDepartOnMap: function() {
this._selectOnMap = "D";
},
prepareSelectArriveeOnMap: function() {
this._selectOnMap = "A";
},
onSpwMapClick: function(x, y, srid) {
if(this._selectOnMap) {
require([this.geolocalisationApiUrl], lang.hitch(this, function(){
if(typeof(spwGeolocalisation) == "undefined"){
MessageManager.getInstance().notifyError(this.labels.geolocalisationServiceUnavailable);
}
else {
if(this._selectOnMap == "D") {
this._spwGeolocalisationSearchInputDepart.reset();
this._spwGeolocalisationSearchInputDepart.setDefaultLabel(this.labels.searchingPosition);
this._spwGeolocalisationSearchInputDepart.displayWaitingLogo();
}
else {
this._spwGeolocalisationSearchInputArrivee.reset();
this._spwGeolocalisationSearchInputArrivee.setDefaultLabel(this.labels.searchingPosition);
this._spwGeolocalisationSearchInputArrivee.displayWaitingLogo();
}
var ctxt = this;
if (this.geolocSrid !== srid) {
var pt = ProjectionManager.getInstance().transform(srid, this.geolocSrid, x, y);
x = pt.x;
y = pt.y;
}
spwGeolocalisation.getNearestPosition(x, y, function(data) {
topic.publish(SPW_ROUTING_WIDGET_GET_NEAREST_POSITION_RESULT+ctxt.id, data);
}, function(request, status, error) {
topic.publish(SPW_ROUTING_WIDGET_GET_NEAREST_POSITION_ERROR+ctxt.id, request, status, error);
});
}
}));
}
},
getNearestPositionResult: function(position) {
if(position.errorCode == 0) {
this.spwViewer.trackEvent("spw.widgets.SpwRouting", "getNearestPositionResult", position.adresse);
if(this._selectOnMap == "D") {
this._depart = position;
this._spwGeolocalisationSearchInputDepart.reset();
this._spwGeolocalisationSearchInputDepart.setWorkingLabel(this._depart.adresse);
this._spwGeolocalisationSearchInputDepart.hideWaitingLogo();
this.addFlag(position, 'D');
}
else {
this._arrivee = position;
this._spwGeolocalisationSearchInputArrivee.reset();
this._spwGeolocalisationSearchInputArrivee.setWorkingLabel(this._arrivee.adresse);
this._spwGeolocalisationSearchInputArrivee.hideWaitingLogo();
this.addFlag(position, 'A');
}
}
else {
MessageManager.getInstance().notifyError(this.labels.errorOccuredWhileGettingNearestPosition + "<br/>" + position.errorMsg);
}
this._selectOnMap = null;
},
addFlag: function(position, type) {
var x = position.x || position.xMin;
var y = position.y || position.yMin;
var result = {x: x, y: y};
if (this.geolocSrid != this.spwViewer.get('spwMap').esriMap.spatialReference.wkid) {
result = ProjectionManager.getInstance().transform(this.geolocSrid, this.spwViewer.get('spwMap').esriMap.spatialReference.wkid, x, y);
}
var pt = new Point(result.x, result.y, this.spwViewer.get('spatialReference'));
if (type == 'D') {
this.spwViewer.get('spwMap').get('esriMap').graphics.remove(this._departPreviewPointGraphic);
this._departPreviewPointGraphic = new Graphic(pt, this._departPointSymbol);
this.spwViewer.get('spwMap').get('esriMap').graphics.add(this._departPreviewPointGraphic);
} else if (type == 'A'){
this.spwViewer.get('spwMap').get('esriMap').graphics.remove(this._arriveePreviewPointGraphic);
this._arriveePreviewPointGraphic = new Graphic(pt, this._arriveePointSymbol);
this.spwViewer.get('spwMap').get('esriMap').graphics.add(this._arriveePreviewPointGraphic);
}
},
getNearestPositionError: function(request, status, error) {
MessageManager.getInstance().notifyError(this.labels.searchAllError + error);
if(this._selectOnMap == "D") {
this._spwGeolocalisationSearchInputDepart.reset();
this._spwGeolocalisationSearchInputDepart.hideWaitingLogo();
}
else {
this._spwGeolocalisationSearchInputArrivee.reset();
this._spwGeolocalisationSearchInputArrivee.hideWaitingLogo();
}
this._selectOnMap = null;
},
invertStartEnd: function() {
if(this._depart || this._arrivee) {
this.spwViewer.trackEvent("spw.widgets.SpwRouting", "invertStartEnd");
var newDepartLabel = this._spwGeolocalisationSearchInputArrivee.getLabel();
var newArriveeLabel = this._spwGeolocalisationSearchInputDepart.getLabel();
this._spwGeolocalisationSearchInputDepart.reset();
this._spwGeolocalisationSearchInputArrivee.reset();
if(this._depart && this._arrivee) {
var temp = this._depart;
this._depart = this._arrivee;
this._spwGeolocalisationSearchInputDepart.setWorkingLabel(newDepartLabel);
this._arrivee = temp;
this._spwGeolocalisationSearchInputArrivee.setWorkingLabel(newArriveeLabel);
}
else if(this._depart && !this._arrivee) {
this._arrivee = this._depart;
this._spwGeolocalisationSearchInputArrivee.setWorkingLabel(newArriveeLabel);
}
else if(!this._depart && this._arrivee) {
this._depart = this._arrivee;
this._spwGeolocalisationSearchInputDepart.setWorkingLabel(newDepartLabel);
}
this._spwGeolocalisationSearchInputDepart.hideWaitingLogo();
this._spwGeolocalisationSearchInputArrivee.hideWaitingLogo();
this.callRouting();
}
},
getCurrentLayersDeclaration:function(){
var tabVisibleLayers = this.spwViewer.get('spwMap').getMapServices({visible: true});
var i = 0;
var txtDeclaration = "var tabLay = new Array();";
while (i<tabVisibleLayers.length /*&& false*/){
var lay = tabVisibleLayers[i].get('layer');
if (lay.declaredClass=="esri.layers.ArcGISDynamicMapServiceLayer"|| lay.declaredClass=="esri.layers.ArcGISTiledMapServiceLayer"){
var txt = "tabLay.push(new "+lay.declaredClass+"(\""+lay.url+"\",{";
txt+="id:'"+lay.id+"',"+"opacity:"+lay.opacity;
txt+="}));";
txtDeclaration+=txt;
}
i++;
}
//txtDeclaration+="tabLay.push(new esri.layers.ArcGISTiledMapServiceLayer('http://geoservices.wallonie.be/arcgis/rest/services/DONNEES_BASE/FOND_PLAN_CARTE_2012_v1_RW/MapServer'));";
return txtDeclaration;
},
printItinerary: function() {
if(this._result) {
this.spwViewer.trackEvent("spw.widgets.SpwRouting", "printItinerary");
var url = window.location.pathname+"printSPW";
console.info(url);
this._w = window.open(url);
this._w.document.open();
/*this._w.document.domain=document.domain;
var str = djConfig.modulePaths.spw;
var spwApiUrl = str;
if (spwApiUrl!="spw"){
spwApiUrl = str.substring(0,str.indexOf("spw"));
}*/
var xmin= this.spwViewer.get('spwMap').get('esriMap').extent.xmin;
var xmax= this.spwViewer.get('spwMap').get('esriMap').extent.xmax;
var ymin= this.spwViewer.get('spwMap').get('esriMap').extent.ymin;
var ymax= this.spwViewer.get('spwMap').get('esriMap').extent.ymax;
var urlEsriAPI = ((this._config && this._config.urlEsriAPI) ? this._config.urlEsriAPI : 'http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8');
var urlEsriStyle = ((this._config && this._config.urlEsriStyle) ? this._config.urlEsriStyle : 'http://geoportail.wallonie.be/geoviewer/1.0/style');
var windowHTML =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"+
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\">"+
"<head>" +
"<meta http-equiv='X-UA-Compatible' content='IE=9' />" +
"<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>" +
"<meta http-equiv='X-UA-Compatible' content='IE=EmulateIE8' />" +
"<META content='IE=edge' http-equiv='X-UA-Compatible'>" +
"<meta http-equiv='X-UA-Compatible' content='IE=8' />" +
"<meta http-equiv='X-UA-Compatible' content='IE=IE9' />" +
"<meta http-equiv='X-UA-Compatible' content='IE=Edge' />" +
"<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>"+
"<style>"+
"body {"+
"font: 12px Myriad,Helvetica,Tahoma,Arial,clean,sans-serif;"+
"}" +
"@media print"+
"{"+
".notPrint {display:none;}"+
"}"+
".SpwRoutingResultItem {"+
"}"+
".SpwRoutingResultItem {"+
" background-color: #BABABA;"+
"}"+
"</style>" +
"<script type='text/javascript'>" +
"var djConfig = {"+
" parseOnLoad : true,"+
" locale: 'fr',"+
" baseUrl: './',"+
" modulePaths: {"+
" }"+
"};"+
"</script>" +
"<script type='text/javascript' src='"+urlEsriAPI+"'></script>"+
"<link rel='stylesheet' type='text/css' href='"+urlEsriStyle+"' />"+
"<script type=\"text/javascript\">"+
"window.afterDojoLoaded=function(){" +
"dojo.require('dijit.dijit');"+
"dojo.require('dojo.io.script');"+
"dojo.require('dijit.layout.BorderContainer');"+
"dojo.require('dijit.layout.ContentPane');"+
"dojo.require('esri.map');"+
"dojo.ready(function(){" +
"window.LAMBERT72_SP_REF = new esri.SpatialReference({ wkid: 31370 });" +
"window.setResult=function(res){window._result=res;};" +
"window.initMap=function(mapDivName,x,y){" +
"var map = new esri.Map(mapDivName,{" +
//"extent : new esri.geometry.Extent({xmin:"+xmin+",ymin:"+ymin+",xmax:"+xmax+",ymax:"+ymax+",spatialReference:{wkid:31370}})," +
"logo: false," +
"nav: false," +
"isPanArrows: false," +
"slider: false" +
"});" +
"map.disablePan();" +
this.getCurrentLayersDeclaration()+
"var i = 0;" +
"while(i<tabLay.length){" +
"var layer= tabLay[i];" +
"map.addLayer(layer);" +
"i++;" +
"} " +
"addItin(_result,map,x,y);" +
"};" +
"" +
"});" +
"window.globalMapLoading=true;" +
"};" +
"window.addItin=function(_result,map,x,y){" +
"var _itineraireLineSymbole= new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([0,255,255,0.5]),5);" +
"var _departPointSymbol = esri.symbol.PictureMarkerSymbol('"+this.imagesPath + "SpwRoutingWidgetFlagDepart.png', 24, 24);"+
"_departPointSymbol.setOffset(2, 10);"+
"var _arriveePointSymbol = esri.symbol.PictureMarkerSymbol('"+this.imagesPath + "SpwRoutingWidgetFlagArrivee.png', 24, 24);"+
"_arriveePointSymbol.setOffset(2, 10);" +
"var graphicsLayer = new esri.layers.GraphicsLayer();" +
"map.addLayer(graphicsLayer);" +
"var geometry = new esri.geometry.Polyline(LAMBERT72_SP_REF);" +
"var points = new Array();" +
"for(var i=0; i<_result.coordonnees.length; i++) {" +
" var pt = new esri.geometry.Point(_result.coordonnees[i].x, _result.coordonnees[i].y, LAMBERT72_SP_REF);" +
" if(i == 0) {" +
" _departPointGraphic = new esri.Graphic(pt, _departPointSymbol);" +
" }" +
" else if(i == _result.coordonnees.length - 1) {" +
" _arriveePointGraphic = new esri.Graphic(pt, _arriveePointSymbol);" +
" }" +
" points.push(pt);" +
"}" +
"geometry.addPath(points);" +
"_itineraireGraphic = new esri.Graphic(geometry, _itineraireLineSymbole);" +
"graphicsLayer.add(_itineraireGraphic);" +
"graphicsLayer.add(_departPointGraphic);" +
"graphicsLayer.add(_arriveePointGraphic);" +
"if(typeof x=='undefined' || typeof y=='undefined'||x==null ||y==null){" +
"map.setExtent(new esri.geometry.Extent(" +
"geometry.getExtent().xmin-5000, " +
"geometry.getExtent().ymin-5000, " +
"geometry.getExtent().xmax+5000, " +
"geometry.getExtent().ymax+5000, " +
"LAMBERT72_SP_REF), true);" +
"}else{" +
"var radius=200;" +
"map.setExtent(new esri.geometry.Extent(x-radius, y-radius, x+radius, y+radius, LAMBERT72_SP_REF), true);" +
"}" +
"};" +
"window.setMapDetailsVisible=function(isVisible){" +
"dojo.query('.mapDetail').forEach(function(node, index, arr){" +
"node.style.display=((isVisible==true)?'block':'none');" +
"});" +
"};"+
"</script>"+
"</head>"+
"<body style='overflow:scroll;'>" +
"<table class='notPrint' style=\"width:100%;position:relative;\">" +
"<tr>" +
"<td style='width:20%;'></td>"+
"<td>"+
"<table style='width:100%;text-align:center;'>" +
"<tr>" +
"<td>"+
"<button onclick='window.print();' type='button'>"+this.labels.printPageAction+"</button>"+
"</td>";
windowHTML+="<td>" +
"<input onclick='window.document.getElementById(\"globalMapTable\").style.display=((this.checked==true)?\"block\":\"none\");' type='checkbox' checked/> "+this.labels.printPageShowGlobalMap+
"</td>" ;
//BKA
if ((typeof has("ie") =="undefined") || (typeof has("ie") !="undefined" && has("ie") >8)){
//alert(dojo.isIE);
windowHTML+="<td>" +
"<input onclick='window.setMapDetailsVisible(this.checked);' type='checkbox' checked/> " +this.labels.printPageShowDetailMaps+
"</td>" ;
}
windowHTML+="</tr>" +
"</table>" +
"</td>" +
"<td style='width:20%;'></td>" +
"</tr>"+
"</table>"+
"<table id='globalMapTable' style=\"width:100%;height:500px;position:relative;\">" +
"<tr>" +
"<td style='width:20%;'>"+
"</td>"+
"<td style='border:1px solid black;'>"+
"<div id=\"globalMap\" class='mapGlobal' style=\"bottom:0;right:0;left:0;top:0;\"></div>" +
"</td>" +
"<td style='width:20%;'>" +
"</td>" +
"</tr>"+
"</table>"+
"<center>"+
"<table style='text-align:left'>"+
"<tr>"+
"<td id=\"tdLblDepart\" align=\"right\"></td>"+
"<td id=\"tdDepart\"></td>"+
"</tr>"+
"<tr>"+
"<td id=\"tdLblArrivee\" align=\"right\"></td>"+
"<td id=\"tdArrivee\"></td>"+
"</tr>"+
"<tr>"+
"<td id=\"tdLblDistance\" align=\"right\"></td>"+
"<td id=\"tdDistance\"></td>"+
"</tr>"+
"<tr>"+
"<td id=\"tdLblDuree\" align=\"right\"></td>"+
"<td id=\"tdDuree\"></td>"+
"</tr>"+
"</table>"+
" "+
"<table id=\"tableSegments\">"+
"</table>"+
" "+
"© SPW"+
"</center>"+
"</body>"+
"</html>";
this._w._result=this._result;
this._w.document.write(windowHTML);
this._w.document.close();
var context = this;
//setTimeout(function(){
var win = this._w;
var body;
function ieLoaded(){
body = win.document.getElementsByTagName("body");
if(body[0]==null){
console.info('0');
// Page isn't ready yet!
setTimeout(ieLoaded, 10);
}else{
if (typeof win.dojo=="undefined" && !win.dojoScriptIsSend){
var n = win.document.createElement("script");
n.src = "http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8";
/*if (!body.appendChild){
body=body[0];
}*/
body[0].appendChild(n);
setTimeout(ieLoaded, 10);
win.dojoScriptIsSend=true;
}else if(typeof win.dojo=="undefined" && win.dojoScriptIsSend){
setTimeout(ieLoaded, 100);
}else if(!win.initMap && !win.globalMapLoading){
win.afterDojoLoaded();
setTimeout(ieLoaded, 100);
}else if(!win.initMap && win.globalMapLoading){
setTimeout(ieLoaded, 100);
}else{
context._w.setResult(context._result);
context._w.initMap('globalMap',null,null);
context._w.document.title = context.labels.spwRoutingWidgetTitle;
context._w.document.getElementById("tdLblDepart").innerHTML = "<b>" + context.labels.start + " :</b>";
context._w.document.getElementById("tdDepart").innerHTML = context._depart.adresse;
context._w.document.getElementById("tdLblArrivee").innerHTML = "<b>" + context.labels.end + " :</b>";
context._w.document.getElementById("tdArrivee").innerHTML = context._arrivee.adresse;
context._w.document.getElementById("tdLblDistance").innerHTML = "<b>" + context.labels.distance + " :</b>";
context._w.document.getElementById("tdDistance").innerHTML = Utils.toDistanceString(context._result.distance);
context._w.document.getElementById("tdLblDuree").innerHTML = "<b>" + context.labels.duration + " :</b>";
context._w.document.getElementById("tdDuree").innerHTML = Utils.toDureeString(context._result.temps, djConfig.locale);
for(var i=0;i<context._result.segments.length;i++) {
var table = context._w.document.getElementById("tableSegments");
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var _class = "SpwRoutingResultItem";
row.className += _class;
var cell1 = row.insertCell(0);
var classImg = context.getImgPathByInstruction(context._result.segments[i].instruction);
cell1.innerHTML = "<span class='itinary " + classImg + "' style='margin-right: 10px;'/>";
var cell2 = row.insertCell(1);
cell2.innerHTML = "<div style='text-align:left;'> " +
"<b> "+(rowCount+1)+".</b> "+context._result.segments[i].instruction +
"</div>" +
"<div>" +
"<table style='width:100%;font-size:10px;'>" +
"<tr>" +
"<td style='text-align:left;'>" +
"</td>" +
"<td style='text-align:right;'>" +
Utils.toDistanceString(context._result.segments[i].longueur) +
" - "+
Utils.toDureeString(context._result.segments[i].temps, djConfig.locale)+
"</td>" +
"</tr>" +
"</table>" +
"</div> " ;
//BKA
if ((typeof has("ie") =="undefined") || (typeof has("ie") !="undefined" && has("ie") >8)){
var cell3 = row.insertCell(2);
cell3.innerHTML = "<div id='miniMap"+(rowCount+1)+"' class='mapDetail' style='width:150px;height:150px;'></div>" ;
context._w.initMap('miniMap'+(rowCount+1),context._result.segments[i].coordonneesDebut.x,context._result.segments[i].coordonneesDebut.y);
}
}
var table = context._w.document.getElementById("tableSegments");
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var _class = "SpwRoutingResultItem";
row.className += _class;
var cell1 = row.insertCell(0);
cell1.innerHTML = "<img src='"+context.imagesPath+"SpwRoutingWidgetFlagArrivee.png' style='padding-right:10px;'/>";
var cell2 = row.insertCell(1);
cell2.innerHTML = "<div style='text-align:left;'> <b> "+(rowCount+1)+".</b> "+context.labels.end+"</div>";
//BKA
if ((typeof has("ie") =="undefined") || (typeof has("ie") !="undefined" && has("ie") > 8)){
var cell3 = row.insertCell(2);
cell3.innerHTML = "<div id='miniMap"+(rowCount+1)+"' class='mapDetail' style='width:150px;height:150px;'></div>";
var lastSeg = context._result.segments[context._result.segments.length-1];
var lastPts = lastSeg.coordonnees[lastSeg.coordonnees.length-1];
context._w.initMap('miniMap'+(rowCount+1),lastPts.x,lastPts.y);
}
}
//context._w.print();
//}, 1000);
}
}
ieLoaded();
}
},
getImgPathByInstruction: function(instruction) {
if(new RegExp("^(D.marrez sur|Fahren Sie los auf).*").test(instruction)) {
return 'depart';
}
else if(new RegExp("^(Continuez|Halten Sie|Reihen Sie|Fahren Sie).*").test(instruction)) {
return 'toutDroit';
}
else if(new RegExp("^(Tournez|Biegen Sie).*(.gauche|links ab).*").test(instruction)) {
return 'gauche';
}
else if(new RegExp("^(Tournez|Biegen Sie).*(.droite|rechts ab).*").test(instruction)) {
return 'droite';
}
else if(new RegExp("^(Faites un demi-tour|Wenden Sie).*").test(instruction)) {
return 'demiTour';
}
else if(new RegExp("(^Prenez la sortie|^Nehmen Sie.*Ausfahrt.*)").test(instruction)) {
return 'sortie';
}
else if(new RegExp("(^Prenez l'acc.s|^Nehmen Sie.*Auffahrt.*)").test(instruction)) {
return 'entree';
}
else {
return 'toutDroit';
}
}
});
var SpwRoutingResultItem = declare("spw.widgets.SpwRoutingResultItem", [SpwBaseTemplatedWidget], {
templateString: SpwRoutingResultItemTemplate,
_segment: null,
/**
* Label à du résultat
* @private
* @type String
*/
_label: "",
/**
* Image accompagnant le label
* @private
* @type String
*/
_imgSrc: null,
/**
* Ce résultat est-il le premier?
* @private
* @type Boolean
*/
_first: false,
/**
* Ce résultat est-il le dernier?
* @private
* @type Boolean
*/
_last: false,
/**
* @private
* @type Boolean
*/
_coordonneesFin: false,
_rowNum:0,
_parent: null,
_style :"",
_class: "SpwRoutingResultItem",
postMixInProperties: function() {
this._class = "SpwRoutingResultItem";
if(!this._last) {
this._imgSrc = this._parent.getImgPathByInstruction(this._segment.instruction);
}
else {
this._imgSrc = "itinary arrivee";
}
},
buildRendering: function(){
this.inherited(arguments);
if(!this._last) {
this._label.innerHTML = "<div> " +
"<div> " +
"<b> "+(this._rowNum+1)+".</b> "+this._segment.instruction +
"</div>" +
"<div>" +
"<table style='width:100%;font-size:10px;'>" +
"<tr>" +
"<td style='text-align:left;'>" +
"</td>" +
"<td style='text-align:right;'>" +
Utils.toDistanceString(this._segment.longueur) +
" - "+
Utils.toDureeString(this._segment.temps, djConfig.locale)+
"</td>" +
"</tr>" +
"</table>" +
"</div> "+
"</div> ";
}
else {
this._label.innerHTML = "<div> " +
"<div> " +
"<b> "+(this._rowNum+1)+".</b> "+this.labels.end +
"</div>" +
"</div> ";
}
},
onClick : function () {
if(!this._last) {
this.spwViewer.get('spwMap').zoomToPoint(this._segment.coordonneesDebut.x, this._segment.coordonneesDebut.y, 200);
}
else {
this.spwViewer.get('spwMap').zoomToPoint(this._coordonneesFin.x, this._coordonneesFin.y, 200);
}
}
});
return SpwRouting;
});