diff --git a/Widget.html b/Widget.html index 02ceb5a..3f8bb10 100644 --- a/Widget.html +++ b/Widget.html @@ -1,78 +1,18 @@

${nls.addDrawTitle}

-
- - -
- -
- -
- -
- +
-
-
-
-
- -
-
-
- -
-
-
- -
-
- - - - - - - - - - - -
- ${nls.fontName} - -
- Sans Serif (1) - Sans Serif (2) - Serif (1) - Serif (2) - Fixed Width (1) - Fixed Width (2) -
-
-
${nls.boldCharacter}
-
${nls.italicCharacter}
-
${nls.underlineCharacter}
-
-
- ${nls.textAngle} - - - ${nls.drawSampleRotatedText} -
-
-
@@ -91,26 +31,26 @@

${nls.addDrawTitle}

-
-

${nls.editDrawTitle}

+
+

${nls.addDrawTitle}


- +

- +
-
- +
+ @@ -130,17 +70,25 @@

${nls.editDrawTitle}

${nls.textAngle}
${nls.fontName} -
+
Sans Serif (1) Sans Serif (2) Serif (1) @@ -119,9 +59,9 @@

${nls.editDrawTitle}

Fixed Width (2)
-
${nls.boldCharacter}
-
${nls.italicCharacter}
-
${nls.underlineCharacter}
+
${nls.boldCharacter}
+
${nls.italicCharacter}
+
${nls.underlineCharacter}
- - ${nls.drawSampleRotatedText} + + ${nls.drawSampleRotatedText}
+ +
+
diff --git a/Widget.js b/Widget.js index e3c8f2e..7e308de 100644 --- a/Widget.js +++ b/Widget.js @@ -15,608 +15,621 @@ /////////////////////////////////////////////////////////////////////////// define([ - 'dojo/_base/declare', - 'dijit/_WidgetsInTemplateMixin', - 'jimu/BaseWidget', - 'esri/graphic', - 'esri/geometry/Point', - 'esri/symbols/SimpleMarkerSymbol', - 'esri/geometry/Polyline', - 'esri/symbols/SimpleLineSymbol', - 'esri/geometry/Polygon', - "esri/graphicsUtils", - 'esri/symbols/SimpleFillSymbol', - 'esri/symbols/TextSymbol', - 'esri/symbols/Font', - 'esri/units', - "esri/toolbars/edit", - 'esri/geometry/webMercatorUtils', - 'esri/geometry/geodesicUtils', - 'dojo/_base/lang', - 'dojo/on', - 'dojo/_base/html', - "dojo/sniff", - 'dojo/_base/Color', - 'dojo/_base/query', - 'dojo/_base/array', - 'dojo/dom-construct', - 'dojo/dom', - 'dijit/form/Select', - 'dijit/form/NumberSpinner', - 'jimu/dijit/ViewStack', - 'jimu/dijit/SymbolChooser', - 'jimu/dijit/DrawBox', - 'jimu/dijit/Message', - 'jimu/utils', - 'jimu/symbolUtils', - 'libs/storejs/store', - 'esri/InfoTemplate', - 'esri/layers/GraphicsLayer' - ], - function(declare,_WidgetsInTemplateMixin,BaseWidget,Graphic,Point, - SimpleMarkerSymbol,Polyline,SimpleLineSymbol,Polygon,graphicsUtils,SimpleFillSymbol, - TextSymbol,Font, esriUnits, Edit, webMercatorUtils,geodesicUtils,lang,on,html,has, - Color,Query,array, domConstruct, dom, Select,NumberSpinner,ViewStack,SymbolChooser, - DrawBox, Message, jimuUtils, jimuSymbolUtils, localStore, InfoTemplate,GraphicsLayer) {/*jshint unused: false*/ - return declare([BaseWidget, _WidgetsInTemplateMixin], { - name: 'eDraw', - baseClass: 'jimu-widget-draw', - - - _drawPlus:{ - "add":{ - "police":false, - "bold":false, - "italic":false, - "underline":false, - "angle":false - }, - "edit":{ - "police":false, - "bold":false, - "italic":false, - "underline":false, - "angle":false - } - }, - - startup: function() { - this.inherited(arguments); - this.viewStack.startup(); - this.viewStack.switchView(null); - }, - - postMixInProperties: function(){ - this.inherited(arguments); - this._resetUnitsArrays(); - }, - - postCreate: function() { - this.inherited(arguments); - jimuUtils.combineRadioCheckBoxWithLabel(this.showMeasure, this.showMeasureLabel); - this.drawBox.setMap(this.map); - - this.viewStack = new ViewStack({ - viewType: 'dom', - views: [this.pointSection, this.lineSection, this.polygonSection, this.textSection] - }); - html.place(this.viewStack.domNode, this.settingContent); - - //Global view (add/list) - this._initTabs(); - - - this._initUnitSelect(); - this._bindEvents(); - - //load if drawings in localStorage - this._initLocalStorage(); + 'dojo/_base/declare', + 'dijit/_WidgetsInTemplateMixin', + 'jimu/BaseWidget', + 'esri/graphic', + 'esri/symbols/SimpleMarkerSymbol', + 'esri/geometry/Polyline', + 'esri/symbols/SimpleLineSymbol', + 'esri/geometry/Polygon', + "esri/graphicsUtils", + 'esri/symbols/SimpleFillSymbol', + 'esri/symbols/TextSymbol', + 'esri/symbols/Font', + 'esri/units', + "esri/toolbars/edit", + 'esri/geometry/webMercatorUtils', + 'esri/geometry/geodesicUtils', + 'dojo/_base/lang', + 'dojo/on', + 'dojo/_base/html', + "dojo/sniff", + 'dojo/_base/Color', + 'dojo/_base/array', + 'dojo/dom-construct', + 'dojo/dom', + 'dijit/form/Select', + 'dijit/form/NumberSpinner', + 'jimu/dijit/ViewStack', + 'jimu/dijit/SymbolChooser', + 'jimu/dijit/DrawBox', + 'jimu/dijit/Message', + 'jimu/utils', + 'jimu/symbolUtils', + 'libs/storejs/store', + 'esri/InfoTemplate', + 'esri/layers/GraphicsLayer' + ], + function (declare, _WidgetsInTemplateMixin, BaseWidget, Graphic, SimpleMarkerSymbol, Polyline, SimpleLineSymbol, Polygon, graphicsUtils, SimpleFillSymbol, + TextSymbol, Font, esriUnits, Edit, webMercatorUtils, geodesicUtils, lang, on, html, has, + Color, array, domConstruct, dom, Select, NumberSpinner, ViewStack, SymbolChooser, + DrawBox, Message, jimuUtils, jimuSymbolUtils, localStore, InfoTemplate, GraphicsLayer) { + + /*jshint unused: false*/ + return declare([BaseWidget, _WidgetsInTemplateMixin], { + name : 'eDraw', + baseClass : 'jimu-widget-edraw', + - //Popup or click init - this._initDrawingPopupAndClick(); - - //Create edit dijit - this.editToolbar = new Edit(this.map); - }, - - resetGeometryEdit:function(){ - if(this._geometryEditSaveGraphic && this._editGraphic){ - var g = new Graphic(this._geometryEditSaveGraphic); - this._editGraphic.setGeometry(g.geometry); - } - }, - - activateGeometryEdit:function(graphic){ - if(!graphic && this.editToolbar){ - this.editToolbar.deactivate(); - return ; - } - // if(graphic.geometry.type=="extent") - // return; - - this._geometryEditSaveGraphic = graphic.toJson(); - - var tool = 0 | Edit.MOVE; - if(graphic.geometry.type!="point") - tool = tool | Edit.EDIT_VERTICES | Edit.SCALE | Edit.ROTATE; - - var options = { - allowAddVertices: true, - allowDeleteVertices: true, - uniformScaling: true - }; - this.editToolbar.activate(tool, graphic, options); - }, - - onClose:function(){ - this.selectDrawing(false); - this._enableMapPreview(false); - this.activateGeometryEdit(false); - }, - - onOpen:function(){ - if(this.drawBox.drawLayer.graphics.length > 0) - this.setTab("list"); - else - this.setTab("add"); - }, - - _initTabs:function(){ - this._tabsConfig={ - "add":{ - button:this.addSectionButton, - view:this.addSection, - active:"menu-item-active", - inactive:"menu-item", - buttons_when_active:"*" - }, - "edit":{ - button:this.editSectionButton, - view:this.editSection, - onlyVisible:true, - active:"menu-item-active ", - inactive:"hidden", - buttons_when_active:["list"] - }, - "list":{ - button:this.listSectionButton, - view:this.listSection, - onlyVisible:true, - active:"menu-item-active", - inactive:"menu-item", - buttons_when_active:"*" - }, - "importExport":{ - button:this.importExportSectionButton, - view:this.importExportSection, - onlyVisible:true, - active:"menu-item-active", - inactive:"menu-item", - buttons_when_active:"*" - } - }; - - if(!this.config.allowImportExport){ - this.importExportSectionButton.style.display = 'none'; - } - - var views = []; - for(var name in this._tabsConfig) - views.push(this._tabsConfig[name]["view"]); - +//////////////////////////////////////////// GENERAL METHODS ////////////////////////////////////////////////// + /** + * Set widget mode :add1 (type choice), add2 (symbology and attributes choice), edit, list, importExport + * @param name string Mode + * - add1 : Add drawing (type choice and measure option) + * - add2 : Add drawing (attributes and symbol chooser) + * - edit : Edit drawing (geometry, attributes and symbol chooser) + * - list : List drawings + * - importExport : + */ + setMode : function (name) { + this.editorEnableMapPreview(false); + this.editorActivateGeometryEdit(false); - this.globalViewStack = new ViewStack({ - viewType: 'dom', - views: views - }); - html.place(this.globalViewStack.domNode, this.settingAllContent); - }, - + switch(name){ + case 'add1': + this.setMenuState('add'); + + this._editorConfig["graphicCurrent"] = false; + + + this.TabViewStack.switchView(this.addSection); + + this.drawBox.deactivate(); + + this.setInfoWindow(false); + + break; + case 'add2': + this.setMenuState('add', ['add']); + + this._editorConfig["graphicCurrent"] = false; + + this.editorPrepareForAdd(this._editorConfig["defaultSymbols"][this._editorConfig['commontype']]); + + this.TabViewStack.switchView(this.editorSection); + + this.setInfoWindow(false); + + break; + case 'edit': + this.setMenuState('edit', ['edit']); + if (this._editorConfig["graphicCurrent"]) { + //prepare editor + this.editorPrepareForEdit(this._editorConfig["graphicCurrent"]); + + //Focus + var extent = graphicsUtils.graphicsExtent([this._editorConfig["graphicCurrent"]]); + this.map.setExtent(extent.expand(2), true); + } + + this.TabViewStack.switchView(this.editorSection); + + this.setInfoWindow(false); + + break; + case 'list': + this.setMenuState('list'); + + //Generate list and + this.listGenerateDrawTable(); + var nb_draws = this.drawBox.drawLayer.graphics.length; + var display = (nb_draws > 0) ? 'block' : 'none'; + html.setStyle(this.allActionsNode, 'display', display); + this.tableTH.innerHTML = nb_draws + ' ' + this.nls.draws; - setTab:function(name){ - var tab_asked = this._tabsConfig[name]; - - this._enableMapPreview(false); - this.activateGeometryEdit(false); - - if(!tab_asked) - return false; - - for(var tab in this._tabsConfig){ - if(tab==name || tab_asked["buttons_when_active"]=="*" || tab_asked["buttons_when_active"].indexOf(tab) != -1){ - this._tabsConfig[tab]["button"].className = - (tab==name) - ? this._tabsConfig[tab]["active"] - : this._tabsConfig[tab]["inactive"]; - } - else{ - this._tabsConfig[tab]["button"].className = "hidden"; - } - } - this.globalViewStack.switchView(this._tabsConfig[name]["view"]); - - switch(name){ - case "add": - this._editGraphic = false; - this.selectDrawing(false); - break; - case "list": - this._generateDrawTable(); - - var nb_draws = this.drawBox.drawLayer.graphics.length; - var display = (nb_draws>0) ? 'block' : 'none'; - html.setStyle(this.allActionsNode,'display',display); - this.tableTH.innerHTML = nb_draws + ' ' + this.nls.draws; - - //Save data in local storage - this._saveInLocalStorage(); - - break; - case "edit": - if(this._editGraphic){ - this.selectDrawing(this._editGraphic); - this.editNameField.value = this._editGraphic.attributes["name"]; - this.editDescriptionField.value = this._editGraphic.attributes["description"]; + //Save data in local storage + this.saveInLocalStorage(); - this.selectDrawing(this._editGraphic); + //Other params + this._editorConfig["graphicCurrent"] = false; - this._initEditSymbolChooser(); - this.activateGeometryEdit(this._editGraphic); - } - - break; - default: - this._editGraphic = false; - this.selectDrawing(false); - } - return true; - }, - - _generateDrawTable:function(){ - //Generate draw features table - var graphics = this.drawBox.drawLayer.graphics; - var nb_graphics = graphics.length; - - //Table - this.drawsTableBody.innerHTML = ""; - - for(var i = nb_graphics-1; i>=0;i--){ - var graphic = graphics[i]; - var num = i+1; - var symbol = graphic.symbol; - - var selected = (this._editGraphic && this._editGraphic==graphic); - - if(selected) - this.selectDrawing(graphic); - - if(symbol.type=="textsymbol"){ - var json = symbol.toJson(); - var txt = (json.text.length>4) ? json.text.substr(0,4)+"..." : json.text - var font = (json.font.size < 14) ? 'font-size:'+json.font.size+'px;' : 'font-size:14px; font-weight:bold;'; - var color = (json.color.lenght==4) ? 'rgba('+json.color.join(",")+')' : 'rgba('+json.color.join(",")+')'; - var symbolHtml = ''+txt+''; - }else{ - var symbolNode = jimuSymbolUtils.createSymbolNode(symbol, {width:50, height:50}); - var symbolHtml = symbolNode.innerHTML; - } - var name = (graphic.attributes && graphic.attributes['name']) ? graphic.attributes['name'] : ''; - var html = ''+name+'' - + ''+symbolHtml+'' - + '' - + ' ' - + ' ' - + '  ' - + ' ' - + ' ' - + '  ' - + ' ' - + ''; - - - var tr = domConstruct.create( - "tr", - { - id : 'draw-tr--'+i, - innerHTML : html, - className:(selected) ? 'selected' : '' - }, - this.drawsTableBody - ); - - //Bind actions - on(dom.byId('draw-action-edit--'+i), "click", this.onActionClick); - on(dom.byId('draw-action-up--'+i), "click", this.onActionClick); - on(dom.byId('draw-action-down--'+i), "click", this.onActionClick); - on(dom.byId('draw-action-delete--'+i), "click", this.onActionClick); - on(dom.byId('draw-action-zoom--'+i), "click", this.onActionClick); - } - }, - - _clickAddButon:function(){ - this.setTab("add"); - }, - _clickListButon:function(){ - this.setTab("list"); - }, - _clickImportExportButon:function(){ - this.setTab("importExport"); - }, - _clickEditSaveButon:function(){ - if(this._EditSymbolChooser.type=="text"){ - this._EditSymbolChooser.inputText.value = this.editNameField.value; - this._update_edit_textSymbol(); + this.TabViewStack.switchView(this.listSection); + + break; + case 'importExport': + this.setMenuState('importExport'); + + //Other params + this._editorConfig["graphicCurrent"] = false; + + this.TabViewStack.switchView(this.importExportSection); + + this.setInfoWindow(false); + + break; } - - this._editGraphic.attributes["name"] = this.editNameField.value; - this._editGraphic.attributes["description"] = this.editDescriptionField.value; - this._editGraphic.setSymbol(this._EditSymbolChooser.symbol); - this.setTab("list"); - }, - _clickEditCancelButon:function(){ - this.resetGeometryEdit(); - this.activateGeometryEdit(false); - this.setTab("list"); - }, - _clickResetCancelButon:function(){ - this.resetGeometryEdit(); - this.setTab("edit"); - }, - - - _initEditSymbolChooser:function(){ - if(!this._editGraphic) - return false; + }, - var geom_type = this._editGraphic.geometry.type; - var type = false; - switch(geom_type){ - case "point": - type = (this._editGraphic.symbol.type=="textsymbol") ? "text" : "marker"; - break; - case "polyline": - type = "line"; + showMessage : function (msg, type) { + + var class_icon = "message-info-icon"; + switch (type) { + case "error": + class_icon = "message-error-icon"; break; - case "fill": - type = "marker"; + case "warning": + class_icon = "message-warning-icon"; break; - } + } + + var content = ' ' + msg; + + new Message({ + message : content + }); + }, + + setMenuState : function (active, elements_shown) { + if(!elements_shown){ + elements_shown = ['add', 'list', 'importExport']; + } + else if(elements_shown.indexOf(active)<0) + elements_shown.push(active); + + for (var button_name in this._menuButtons){ + var menu_class = (button_name == active) ? 'menu-item-active' : 'menu-item'; + if(elements_shown.indexOf(button_name)<0 || (button_name=="importExport" && !this.config.allowImportExport)) + menu_class = "hidden"; + if(this._menuButtons[button_name]) + this._menuButtons[button_name].className = menu_class; + } + }, - //textPlus - this.EditSymbolTextPlusNode.style.display = (type=="text") ? 'block' : 'none'; + setInfoWindow : function (graphic) { + if (!this.map.infoWindow) + return false; + + if (!graphic) { + this.map.infoWindow.hide(); + return true; + } + + if(graphic.geometry.x) + var center = graphic.geometry; + else if(graphic.geometry.getCenter) + var center = graphic.geometry.getCenter(); + else if( graphic.geometry.getExtent) + var center = graphic.geometry.getExtent().getCenter(); + else + return false; + + this.map.infoWindow.setFeatures([graphic]); + this.map.infoWindow.show(center); + + }, + + saveInLocalStorage : function () { + if (!this.config.allowLocalStorage) + return; + + localStore.set(this._localStorageKey, this.drawingsGetJson()); + }, + + zoomAll : function () { + var graphics = this.drawBox.drawLayer.graphics; + var nb_graphics = graphics.length; + + if (nb_graphics < 1) + return; + + var ext = graphicsUtils.graphicsExtent(this.drawBox.drawLayer.graphics); + + this.map.setExtent(ext, true); + return true; + }, + + clear : function () { + if (!this.config.confirmOnDelete || confirm(this.nls.clear)) { + this.drawBox.drawLayer.clear(); + this.setInfoWindow(false); + this.setMode("list"); + } + }, - //Show (or create) symbolChooser - if(this._EditSymbolChooser){ - this._EditSymbolChooser.showBySymbol(this._editGraphic.symbol); - } - else{ - //Create symbolChooser dijit - this._EditSymbolChooser = new SymbolChooser( - {type:type, symbol:this._editGraphic.symbol, class:"full-width"}, - this.EditSymbolChooserDiv - ); - if(type=="text"){ - var tr = this._parentByTag(this._EditSymbolChooser.inputText, 'tr'); - if(tr) - tr.style.display = 'none'; + drawingsGetJson : function (asString) { + if (this.drawBox.drawLayer.graphics.length < 1) + return (asString) ? '' : false; + + var content = { + "features" : [], + "displayFieldName" : "", + "fieldAliases" : {}, + "spatialReference" : this.map.spatialReference.toJson(), + "fields" : [] + }; + + for (var i in this.drawBox.drawLayer.graphics) + content["features"].push(this.drawBox.drawLayer.graphics[i].toJson()); + + if (asString) { + content = JSON.stringify(content); } - } + return content; + }, + - //TEXT PLUS - if(type=="text"){ - this._drawPlus["edit"]["bold"] = (this._editGraphic.symbol.font.weight == esri.symbol.Font.WEIGHT_BOLD); - this._drawPlus["edit"]["italic"] = (this._editGraphic.symbol.font.style == esri.symbol.Font.STYLE_ITALIC); - this._drawPlus["edit"]["underline"] = (this._editGraphic.symbol.font.decoration == 'underline'); - // this.EditTextPlusPoliceNode.value = this._editGraphic.symbol.font.family; - this.EditTextPlusPoliceNode.set("value",this._editGraphic.symbol.font.family); - // this.EditTextAngleNode.value = this._editGraphic.symbol.angle; - this.EditTextAngleNode.set("value", this._editGraphic.symbol.angle); - - this._enableClass(this.EditTextPlusBoldNode, 'selected',this._drawPlus["edit"]["bold"]); - this._enableClass(this.EditTextPlusItalicNode, 'selected',this._drawPlus["edit"]["italic"]); - this._enableClass(this.EditTextPlusUnderlineNode, 'selected',this._drawPlus["edit"]["underline"]); - } +///////////////////////// MENU METHODS /////////////////////////////////////////////////////////// + menuOnClickAdd : function () { + this.setMode("add1"); + }, + menuOnClickList : function () { + this.setMode("list"); + }, + menuOnClickImportExport : function () { + this.setMode("importExport"); + }, + - }, - - __prevent_next_infowindow_slot:false, - _initDrawingPopupAndClick:function(){ - var infoTemplate = new esri.InfoTemplate("${name}","${description}"); - this.drawBox.drawLayer.setInfoTemplate(infoTemplate); - - //Catch with infowindow - if(this.map.infoWindow){ - this._onInfoWinHide=lang.hitch(this, function(){ - if(this.__prevent_next_infowindow_slot){ - this.__prevent_next_infowindow_slot = false; - return; - } - - this._editGraphic = false; - this.selectDrawing(false); - this.setTab("list"); - }); - this._onInfoWinShow=lang.hitch(this, function(evt){ - if(this.__prevent_next_infowindow_slot){ - this.__prevent_next_infowindow_slot = false; - return; +///////////////////////// LIST METHODS /////////////////////////////////////////////////////////// + listGenerateDrawTable : function () { + //Generate draw features table + var graphics = this.drawBox.drawLayer.graphics; + var nb_graphics = graphics.length; + + //Table + this.drawsTableBody.innerHTML = ""; + + for (var i = nb_graphics - 1; i >= 0; i--) { + var graphic = graphics[i]; + var num = i + 1; + var symbol = graphic.symbol; + + var selected = (this._editorConfig["graphicCurrent"] && this._editorConfig["graphicCurrent"] == graphic); + + if (symbol.type == "textsymbol") { + var json = symbol.toJson(); + var txt = (json.text.length > 4) ? json.text.substr(0, 4) + "..." : json.text + var font = (json.font.size < 14) ? 'font-size:' + json.font.size + 'px;' : 'font-size:14px; font-weight:bold;'; + var color = (json.color.length == 4) ? 'rgba(' + json.color.join(",") + ')' : 'rgba(' + json.color.join(",") + ')'; + var symbolHtml = '' + txt + ''; + } else { + var symbolNode = jimuSymbolUtils.createSymbolNode(symbol, { + width : 50, + height : 50 + }); + var symbolHtml = symbolNode.innerHTML; } + var name = (graphic.attributes && graphic.attributes['name']) ? graphic.attributes['name'] : ''; + name = (name.length > 8) ? '' + name.substr(0, 8) + "..." : name; + var html = '' + name + '' + + '' + symbolHtml + '' + + '' + + ' ' + + ' ' + + '  ' + + ' ' + + ' ' + + '  ' + + ' ' + + ''; + + var tr = domConstruct.create( + "tr", { + id : 'draw-tr--' + i, + innerHTML : html, + className : (selected) ? 'selected' : '' + }, + this.drawsTableBody + ); + + //Bind actions + on(dom.byId('draw-action-edit--' + i), "click", this.listOnActionClick); + on(dom.byId('draw-action-up--' + i), "click", this.listOnActionClick); + on(dom.byId('draw-action-down--' + i), "click", this.listOnActionClick); + on(dom.byId('draw-action-delete--' + i), "click", this.listOnActionClick); + on(dom.byId('draw-action-zoom--' + i), "click", this.listOnActionClick); + } + }, + + switch2DrawingGraphics : function (i1, i2) { + var g1 = this.drawBox.drawLayer.graphics[i1]; + var g2 = this.drawBox.drawLayer.graphics[i2]; + + if (!g1 || !g2) + return false; + + //Switch graphics + this.drawBox.drawLayer.graphics[i1] = g2; + this.drawBox.drawLayer.graphics[i2] = g1; + + //Redraw in good order + var nb = this.drawBox.drawLayer.graphics.length; + for (var i =0; i= i1 || i >= i2){ + var shape = g.getShape(); + if(shape) shape.moveToFront(); } - else - this._editGraphic = false; - - this.setTab("list"); - }); - this.map.infoWindow.on("hide", this._onInfoWinHide); - this.map.infoWindow.on("show", this._onInfoWinShow); - } - //If no infowindow catch click on draw - else{ - this._onDrawClick = lang.hitch(this, function(evt){ - if(!evt.graphic) - return; - - this._editGraphic = evt.graphic; - this.setTab("list"); - }); - this.drawBox.drawLayer.on("click", this._onDrawClick); - } - }, - - setInfoWindow:function(graphic){ - if(!this.map.infoWindow) - return false; - - //Prevent next e - this.__prevent_next_infowindow_slot=true; - - if(!graphic){ - this.map.infoWindow.hide(); + } return true; - } - - var center = (graphic.geometry.getExtent) ? graphic.geometry.getExtent() : graphic.geometry; - - this.map.infoWindow.setFeatures([graphic]); - this.map.infoWindow.show(center); - - }, - - - _saveInLocalStorage:function(){ - if(!this.config.allowLocalStorage) - return; - - localStore.set(this._localStorageKey, this.drawingsAsJson()); - }, - _initLocalStorage:function(){ - if(!this.config.allowLocalStorage) + }, + + listOnActionClick : function (evt) { + if (!evt.target || !evt.target.id) return; + + var tab = evt.target.id.split('--'); + var type = tab[0]; + var i = parseInt(tab[1]); + + var g = this.drawBox.drawLayer.graphics[i]; + this._editorConfig["graphicCurrent"] = g; + + switch (type) { + case 'draw-action-up': + this.switch2DrawingGraphics(i, i + 1); + this.listGenerateDrawTable(); + break; + case 'draw-action-down': + this.switch2DrawingGraphics(i, i - 1); + this.listGenerateDrawTable(); + break; + case 'draw-action-delete': + if (!this.config.confirmOnDelete || confirm(this.nls.confirmDrawDelete + ".")) { + g.getLayer().remove(g); + this._editorConfig["graphicCurrent"] = false; + this.listGenerateDrawTable(); + } + break; + case 'draw-action-edit': + this.setMode("edit"); + break; + case 'draw-action-zoom': + this.setInfoWindow(g); + + var extent = graphicsUtils.graphicsExtent([g]); + this.map.setExtent(extent, true); + this.listGenerateDrawTable(); + + break; + } + }, + + +///////////////////////// SYMBOL EDITOR METHODS /////////////////////////////////////////////////////////// + _editorConfig : { + drawPlus : { + "police" : false, + "bold" : false, + "italic" : false, + "underline" : false, + "angle" : false + }, + phantom : { + "point" : false, + "symbol" : false, + "layer" : false, + "handle" : false + } + }, + + editorPrepareForAdd : function (symbol) { + this.editorSymbolChooserConfigure(symbol); - this._localStorageKey = - (this.config.localStorageKey) - ? 'WebAppBuilder.2D.eDraw.'+this.config.localStorageKey - : 'WebAppBuilder.2D.eDraw'; + this.nameField.value = this.nls.nameFieldDefaultValue; + this.descriptionField.value = ''; - var content = localStore.get(this._localStorageKey); + this.editorTitle.innerHTML = this.nls.addDrawTitle; + this.editorFooterEdit.style.display = 'none'; + this.editorFooterAdd.style.display = 'block'; + this.editorAddMessage.style.display = 'block'; - if(!content || !content.features || content.features.length < 1) - return; + var commontype = this._editorConfig['commontype']; + + //Mouse preview + this._editorConfig["phantom"]["symbol"]=symbol; + this.editorEnableMapPreview((commontype == 'point' || commontype == 'text')); - //Closure with timeout to be sure widget is ready - (function(widget){ - setTimeout( - function(){ - widget._importJsonContent(content, "name", "description"); - widget.showMessage(widget.nls.localLoading); - } - ,200 - ); - })(this); + //If text prepare symbol + if(commontype=="text") + this.editorUpdateTextPlus(); + }, + + editorPrepareForEdit : function (graphic) { + this.nameField.value = graphic.attributes["name"]; + this.descriptionField.value = graphic.attributes["description"]; + + this.editorActivateGeometryEdit(graphic); + + this.editorSymbolChooserConfigure(graphic.symbol); - }, - - zoomAll:function(){ - var graphics = this.drawBox.drawLayer.graphics; - var nb_graphics = graphics.length; + this.editorTitle.innerHTML = this.nls.editDrawTitle; + this.editorFooterEdit.style.display = 'block'; + this.editorFooterAdd.style.display = 'none'; + this.editorAddMessage.style.display = 'none'; - if(nb_graphics<1) + this.editorEnableMapPreview(false); + }, + + editorSymbolChooserConfigure : function (symbol) { + if (!symbol) return; + + //Set this symbol in symbol chooser + this.editorSymbolChooser.showBySymbol(symbol); + + var type = symbol.type; + //Draw plus and specific comportment when text symbol. + if (type == "textsymbol") { + //show draw plus + this.editorSymbolTextPlusNode.style.display = 'block'; + + //Hide text label input (use name instead of) + var tr = this._UTIL__getParentByTag(this.editorSymbolChooser.inputText, 'tr'); + if (tr) + tr.style.display = 'none'; + + //Draw plus configuration + this._editorConfig["drawPlus"]["bold"] = (symbol.font.weight == esri.symbol.Font.WEIGHT_BOLD); + this._editorConfig["drawPlus"]["italic"] = (symbol.font.style == esri.symbol.Font.STYLE_ITALIC); + this._editorConfig["drawPlus"]["underline"] = (symbol.font.decoration == 'underline'); + this.editorTextPlusPoliceNode.set("value", symbol.font.family); + this.editorTextPlusAngleNode.set("value", symbol.angle); + this._UTIL__enableClass(this.editorTextPlusBoldNode, 'selected', this._editorConfig["drawPlus"]["bold"]); + this._UTIL__enableClass(this.editorTextPlusItalicNode, 'selected', this._editorConfig["drawPlus"]["italic"]); + this._UTIL__enableClass(this.editorTextPlusUnderlineNode, 'selected', this._editorConfig["drawPlus"]["underline"]); + } else { + //Hide draw plus + this.editorSymbolTextPlusNode.style.display = 'none'; + } + }, + + editorUpdateTextPlus : function () { + //Only if text + if(this.editorSymbolChooser.type != "text"){ + return; + } - var ext = graphicsUtils.graphicsExtent(this.drawBox.drawLayer.graphics); + //Get parameters + var text = this.nameField.value; + var family = this.editorTextPlusPoliceNode.value; + var angle = this.editorTextPlusAngleNode.value; + var weight = this._editorConfig["drawPlus"]["bold"] ? esri.symbol.Font.WEIGHT_BOLD : esri.symbol.Font.WEIGHT_NORMAL; + var style = this._editorConfig["drawPlus"]["italic"] ? esri.symbol.Font.STYLE_ITALIC : esri.symbol.Font.STYLE_NORMAL; + var decoration = this._editorConfig["drawPlus"]["underline"] ? 'underline' : 'none'; - this.map.setExtent(ext, true); - return true; - }, + //Set in symbol chooser + this.editorSymbolChooser.inputText.value = text; + this.editorSymbolChooser.symbol.text = text; + this.editorSymbolChooser.symbol.font.setFamily(family); + this.editorSymbolChooser.symbol.setAngle(angle); + this.editorSymbolChooser.symbol.font.setWeight(weight); + this.editorSymbolChooser.symbol.font.setStyle(style); + this.editorSymbolChooser.symbol.font.setDecoration(decoration); + + //Update in drawBox + this.drawBox.setTextSymbol(this.editorSymbolChooser.symbol); + + //Update preview + this.editorSymbolChooser.textPreview.innerHTML = text; + this.editorSymbolChooser.textPreview.style.fontFamily = family; + this.editorSymbolChooser.textPreview.style['font-style'] = (this._editorConfig["drawPlus"]["italic"]) ? 'italic' : 'normal'; + this.editorSymbolChooser.textPreview.style['font-weight'] = (this._editorConfig["drawPlus"]["bold"]) ? 'bold' : 'normal'; + this.editorSymbolChooser.textPreview.style['text-decoration'] = (this._editorConfig["drawPlus"]["underline"]) ? 'underline' : 'none'; + this.editorSymbolChooser.textPreview.style.transform = 'rotate(' + angle + 'deg)'; + this.editorSymbolChooser.textPreview.style['-ms-transform'] = 'rotate(' + angle + 'deg)'; - clear:function(){ - if(!this.config.confirmOnDelete || confirm(this.nls.clear)){ - this.drawBox.drawLayer.clear(); - this.selectDrawing(false); - this.setTab("list"); - } - }, - - import:function(){ - if (!window.FileReader) { - this.showMessage(this.nls.importErrorMessageNavigator, 'error'); - return false; - } - - var input = this.importFile.files[0]; + //Update angle preview + this.editorTextAnglePreviewNode.style['font-style'] = (this._editorConfig["drawPlus"]["italic"]) ? 'italic' : 'normal'; + this.editorTextAnglePreviewNode.style['font-weight'] = (this._editorConfig["drawPlus"]["bold"]) ? 'bold' : 'normal'; + this.editorTextAnglePreviewNode.style['text-decoration'] = (this._editorConfig["drawPlus"]["underline"]) ? 'underline' : 'none'; + this.editorTextAnglePreviewNode.style.transform = 'rotate(' + angle + 'deg)'; + this.editorTextAnglePreviewNode.style['-ms-transform'] = 'rotate(' + angle + 'deg)'; + + //Update phantom symbol + this.editorUpdateMapPreview(this.editorSymbolChooser.symbol); + }, - if(!input){ - this.showMessage(this.nls.importErrorWarningSelectFile, 'warning'); - return false; - } - var reader = new FileReader(); - reader.onload= this._importOnFileLoad; - var txt = reader.readAsText(input); - }, - - - _importJsonContent:function(json, nameField, descriptionField){ - try{ - if(typeof json == 'string'){ - json = JSON.parse(json); + editorSetDefaultSymbols : function () { + var symbol = this.editorSymbolChooser.getSymbol(); + switch (symbol.type.toLowerCase()) { + case "simplemarkersymbol": + this.drawBox.setPointSymbol(symbol); + break; + case "picturemarkersymbol": + this.drawBox.setPointSymbol(symbol); + break; + case "textsymbol": + this.drawBox.setPointSymbol(symbol); + break; + case "simplelinesymbol": + this.drawBox.setLineSymbol(symbol); + break; + case "cartographiclinesymbol": + this.drawBox.setLineSymbol(symbol); + break; + case "simplefillsymbol": + this.drawBox.setPolygonSymbol(symbol); + break; + case "picturefillsymbol": + this.drawBox.setPolygonSymbol(symbol); + break; } - - if(!json.features){ - this.showMessage(this.nls.importErrorFileStructure, 'error'); + }, + + +///////////////////////// IMPORT/EXPORT METHODS /////////////////////////////////////////////////////////// + import : function () { + if (!window.FileReader) { + this.showMessage(this.nls.importErrorMessageNavigator, 'error'); return false; } - if(json.features.length<1){ - this.showMessage(this.nls.importWarningNoDrawings, 'warning'); + var input = this.importFile.files[0]; + + if (!input) { + this.showMessage(this.nls.importErrorWarningSelectFile, 'warning'); return false; } + var reader = new FileReader(); + reader.onload = this.importOnFileLoad; + var txt = reader.readAsText(input); + }, - if(!nameField){ - var g = json.features[0]; - var fields_possible = ["name", "title", "label"]; - if(g.attributes){ - for(var i in fields_possible){ - if(g.attributes[fields_possible[i]]){ - nameField = fields_possible[i]; - break; - } + importJsonContent : function (json, nameField, descriptionField) { + try { + if (typeof json == 'string') { + json = JSON.parse(json); + } + + if (!json.features) { + this.showMessage(this.nls.importErrorFileStructure, 'error'); + return false; + } + + if (json.features.length < 1) { + this.showMessage(this.nls.importWarningNoDrawings, 'warning'); + return false; + } + + if (!nameField) { + var g = json.features[0]; + var fields_possible = ["name", "title", "label"]; + if (g.attributes) { + for (var i in fields_possible) { + if (g.attributes[fields_possible[i]]) { + nameField = fields_possible[i]; + break; + } + } } - } - } - - for(var i in json.features){ - var json_feat = json.features[i]; - - var g = new Graphic(json_feat); - - if(!g) - continue; - - if(!g.attributes) - g.attributes = {}; - - g.attributes["name"] = (!nameField || !g.attributes[nameField]) ? 'n°'+(i+1) : g.attributes[nameField]; - if(g.symbol && g.symbol.type=="textsymbol") - g.attributes["name"] = g.symbol.text; - g.attributes["description"] = (!descriptionField || !g.attributes[descriptionField]) ? '' : g.attributes[descriptionField]; - - if(g.symbol){ - this.drawBox.drawLayer.add(g); } - else{ - var symbol = false; - switch(g.geometry.type){ + + for (var i in json.features) { + var json_feat = json.features[i]; + + var g = new Graphic(json_feat); + + if (!g) + continue; + + if (!g.attributes) + g.attributes = {}; + + g.attributes["name"] = (!nameField || !g.attributes[nameField]) ? 'n°' + (i + 1) : g.attributes[nameField]; + if (g.symbol && g.symbol.type == "textsymbol") + g.attributes["name"] = g.symbol.text; + g.attributes["description"] = (!descriptionField || !g.attributes[descriptionField]) ? '' : g.attributes[descriptionField]; + + if (g.symbol) { + this.drawBox.drawLayer.add(g); + } else { + var symbol = false; + switch (g.geometry.type) { case 'point': var symbol = new SimpleMarkerSymbol(); break; @@ -626,826 +639,670 @@ define([ case 'polygon': var symbol = new SimpleFillSymbol(); break; - } - if(symbol){ - g.setSymbol(symbol); - this.drawBox.drawLayer.add(g); + } + if (symbol) { + g.setSymbol(symbol); + this.drawBox.drawLayer.add(g); + } } } + + this.setMode("list"); + } catch (e) { + this.showMessage(this.nls.importErrorFileStructure, 'error'); + return false; } - - this.setTab("list"); - } - catch(e){ - this.showMessage(this.nls.importErrorFileStructure, 'error'); - return false; - } - }, - - _importOnFileLoad:function(evt){ + }, + + importOnFileLoad : function (evt) { var content = evt.target.result; - this._importJsonContent(content); - this.importFile.files[0]=""; - }, - - drawingsAsJson:function(asString){ - if(this.drawBox.drawLayer.graphics.length<1) - return (asString) ? '' : false; - - var content = { - "features":[], - "displayFieldName" : "", - "fieldAliases" : {}, - "spatialReference" : this.map.spatialReference.toJson(), - "fields" : [] - }; - - for(var i in this.drawBox.drawLayer.graphics) - content["features"].push(this.drawBox.drawLayer.graphics[i].toJson()); - - if(asString){ - content = JSON.stringify(content); - } - return content; - }, - - - - export:function(){ - this.exportButton.href="#"; - if(this.drawBox.drawLayer.graphics.length < 1){ - this.showMessage(this.nls.importWarningNoExport0Draw, 'warning'); - return false; - } - else{ - //If not IE - if(!has("ie") && (!navigator.appName || navigator.appName != 'Microsoft Internet Explorer')){ - this.exportButton.href = 'data:application/json;charset=utf-8,'+this.drawingsAsJson(true); - this.exportButton.target = "_BLANK"; - this.exportButton.download = (this.config.exportFileName) ? (this.config.exportFileName) : 'myDrawings.json'; - return true; - } - - //if IE, specific. (ie doesn't accept data in link href) + this.importJsonContent(content); + this.importFile.files[0] = ""; + }, + + export : function () { this.exportButton.href = "#"; - this.exportButton.target = ""; - - var iframe = this.exportIframeForIE; - iframe = iframe.contentWindow || iframe.contentDocument; - - iframe.document.open("application/json", "replace"); - iframe.document.write(this.drawingsAsJson(true)); - iframe.document.close(); - iframe.focus(); - iframe.document.execCommand('SaveAs', true, this.config.exportFileName); - - return false; - } - }, - - showMessage:function(msg, type){ - - var class_icon = "message-info-icon"; - switch(type){ - case "error": - class_icon = "message-error-icon"; - break; - case "warning": - class_icon = "message-warning-icon"; - break; - } + if (this.drawBox.drawLayer.graphics.length < 1) { + this.showMessage(this.nls.importWarningNoExport0Draw, 'warning'); + return false; + } else { + //If not IE + if (!has("ie") && (!navigator.appName || navigator.appName != 'Microsoft Internet Explorer')) { + this.exportButton.href = 'data:application/json;charset=utf-8,' + this.drawingsGetJson(true); + this.exportButton.target = "_BLANK"; + this.exportButton.download = (this.config.exportFileName) ? (this.config.exportFileName) : 'myDrawings.json'; + return true; + } - var content = ' '+msg ; - - new Message({ - message:content - }); - }, - - _switchGraphics:function(i1, i2){ - var g1 = this.drawBox.drawLayer.graphics[i1]; - var g2 = this.drawBox.drawLayer.graphics[i2]; - - if(!g1 || !g2) - return false; - - //Switch graphics - this.drawBox.drawLayer.graphics[i1] = g2; - this.drawBox.drawLayer.graphics[i2] = g1; - - //Redraw in good order - for(var i in this.drawBox.drawLayer.graphics){ - if(i>=i1 || i >=i2) - this.drawBox.drawLayer.graphics[i].getShape().moveToFront(); - } - return true; - }, - - onActionClick:function(evt){ - if(!evt.target || !evt.target.id) - return; + //if IE, specific. (ie doesn't accept data in link href) + this.exportButton.href = "#"; + this.exportButton.target = ""; + + var iframe = this.exportIframeForIE; + iframe = iframe.contentWindow || iframe.contentDocument; + + iframe.document.open("application/json", "replace"); + iframe.document.write(this.drawingsGetJson(true)); + iframe.document.close(); + iframe.focus(); + iframe.document.execCommand('SaveAs', true, this.config.exportFileName); + + return false; + } + }, + + +///////////////////////// EDIT METHODS /////////////////////////////////////////////////////////// + editorOnClickEditSaveButon : function () { + if (this.editorSymbolChooser.type == "text") { + this.editorUpdateTextPlus(); + } + + this._editorConfig["graphicCurrent"].attributes["name"] = this.nameField.value; + this._editorConfig["graphicCurrent"].attributes["description"] = this.descriptionField.value; + this._editorConfig["graphicCurrent"].setSymbol(this.editorSymbolChooser.symbol); + this.setMode("list"); + }, + editorOnClickEditCancelButon : function () { + this.editorResetGeometry(); + this.editorActivateGeometryEdit(false); + this.setMode("list"); + }, + editorOnClickResetCancelButon : function () { + this.editorResetGeometry(); + this.setMode("edit"); + }, - var tab = evt.target.id.split('--'); - var type = tab[0]; - var i = parseInt(tab[1]); + editorResetGeometry : function () { + if (this._editorConfig["graphicSaved"] && this._editorConfig["graphicCurrent"]) { + var g = new Graphic(this._editorConfig["graphicSaved"]); + this._editorConfig["graphicCurrent"].setGeometry(g.geometry); + } + }, + + editorActivateGeometryEdit : function (graphic) { + if (!graphic && this._editorConfig["editToolbar"]) { + this._editorConfig["editToolbar"].deactivate(); + return; + } + + this._editorConfig["graphicSaved"] = graphic.toJson(); + + var tool = 0 | Edit.MOVE; + if (graphic.geometry.type != "point") + tool = tool | Edit.EDIT_VERTICES | Edit.SCALE | Edit.ROTATE; + + var options = { + allowAddVertices : true, + allowDeleteVertices : true, + uniformScaling : true + }; + this._editorConfig["editToolbar"].activate(tool, graphic, options); + }, - var g = this.drawBox.drawLayer.graphics[i]; - this._editGraphic = g; - this.setInfoWindow(false); - switch(type){ - case 'draw-action-up': - this._switchGraphics(i, i+1); - this._generateDrawTable(); - break; - case 'draw-action-down': - this._switchGraphics(i, i-1); - this._generateDrawTable(); - break; - case 'draw-action-delete': - if(!this.config.confirmOnDelete || confirm(this.nls.confirmDrawDelete + ".")){ - g.getLayer().remove(g); - this._editGraphic = false; - this.selectDrawing(false); - this._generateDrawTable(); +///////////////////////// ADD METHODS /////////////////////////////////////////////////////////// + drawBoxOnTypeSelected : function (target, geotype, commontype) { + if (!this._editorConfig["defaultSymbols"]) + this._editorConfig["defaultSymbols"] = {}; + this._editorConfig['commontype'] = commontype; + + var symbol = this._editorConfig["defaultSymbols"][commontype]; + if (!symbol) { + switch (commontype) { + case "point": + symbol = new SimpleMarkerSymbol(); + break; + case "polyline": + symbol = new SimpleLineSymbol(); + break; + case "polygon": + symbol = new SimpleFillSymbol(); + break; + case "text": + symbol = new TextSymbol(); + break; } - break; - case 'draw-action-edit': - this.setTab("edit"); - break; - case 'draw-action-zoom': - var extent = graphicsUtils.graphicsExtent([g]); - this.map.setExtent(extent, true); - this._generateDrawTable(); - break; - } - }, + } - - _getSelectionSymbol:function(graphic){ - if(!graphic || !graphic.symbol) - return false; - - var select_color = new Color([5,230,242]); - - switch(graphic.geometry.type){ - case "point": - if(graphic.symbol.type=="textsymbol"){ - var size=5; - var style = SimpleMarkerSymbol.STYLE_DIAMOND; + if (symbol) { + this._editorConfig["defaultSymbols"][commontype] = symbol; + this.setMode('add2'); + } + }, + + drawBoxOnDrawEnd : function (graphic, geotype, commontype) { + var geometry = graphic.geometry; + + this.editorEnableMapPreview(false); + + graphic.attributes = { + "name" : this.nameField.value, + "description" : this.descriptionField.value + } + + if (geometry.type === 'extent') { + var a = geometry; + var polygon = new Polygon(a.spatialReference); + var r = [[a.xmin, a.ymin], [a.xmin, a.ymax], [a.xmax, a.ymax], [a.xmax, a.ymin], [a.xmin, a.ymin]]; + polygon.addRing(r); + geometry = polygon; + + graphic.setGeometry(polygon); + var layer = graphic.getLayer(); + layer.remove(graphic); + layer.add(graphic); + + commontype = 'polygon'; + } + if (commontype === 'polyline') { + if (this.showMeasure.checked) { + this._addLineMeasure(geometry); } - else{ - var size=graphic.symbol.height; - var style = SimpleMarkerSymbol.STYLE_SQUARE; - } - return new SimpleMarkerSymbol( - style, - size, - new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, select_color, 2), - new Color([0,0,0,0]) - ); - break; - case "polyline": - return new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, select_color, 2) - break; - case "polygon": - return new SimpleFillSymbol( - SimpleFillSymbol.STYLE_NULL, - new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, select_color, 2), - new Color([0,0,0,0]) - ); - break; - case "extent": - return new SimpleFillSymbol( - SimpleFillSymbol.STYLE_NULL, - new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, select_color, 2), - new Color([0,0,0,0]) - ); - break; - default: - console.log("Pas de symbole de selection !!!!", graphic); - } - return graphic.symbol; - }, - - selectDrawing:function(graphic){ - this.map.graphics.clear(); - - if(!graphic) - return; - - var select_graphic = new Graphic(graphic.toJson()); - var symbol = this._getSelectionSymbol(select_graphic); - if(symbol){ - select_graphic.setSymbol(symbol); - this.map.graphics.add(select_graphic); - } - }, - - _resetUnitsArrays: function(){ - this.defaultDistanceUnits = []; - this.defaultAreaUnits = []; - this.configDistanceUnits = []; - this.configAreaUnits = []; - this.distanceUnits = []; - this.areaUnits = []; - }, - - _bindEvents: function() { - //bind DrawBox - this.own(on(this.drawBox,'IconSelected',lang.hitch(this,this._onIconSelected))); - this.own(on(this.drawBox,'DrawEnd',lang.hitch(this,this._onDrawEnd))); - - //bind symbol change events - this.own(on(this.pointSymChooser,'change',lang.hitch(this,function(){ - this._setDrawDefaultSymbols(); - this._phantomSymbol = this.pointSymChooser.getSymbol(); - this._enableMapPreview(true); - }))); - this.own(on(this.lineSymChooser,'change',lang.hitch(this,function(){ - this._setDrawDefaultSymbols(); - this._enableMapPreview(false); - }))); - this.own(on(this.fillSymChooser,'change',lang.hitch(this,function(){ - this._setDrawDefaultSymbols(); - this._enableMapPreview(false); - }))); - this.own(on(this.textSymChooser,'change',lang.hitch(this,function(symbol){ - this.drawBox.setTextSymbol(symbol); - this._controlTextIsWritten(); - this._update_add_textSymbol(); - this._phantomSymbol = this.textSymChooser.symbol; - this._enableMapPreview(true); - }))); - - //bind unit events - this.own(on(this.showMeasure,'click',lang.hitch(this,this._setMeasureVisibility))); - - //bind list event - this.onActionClick = lang.hitch(this, this.onActionClick); - this._importOnFileLoad = lang.hitch(this, this._importOnFileLoad); - - //Draw plus ! - this._update_add_textSymbol = lang.hitch(this, this._update_add_textSymbol); - this._update_edit_textSymbol = lang.hitch(this, this._update_edit_textSymbol); - - this.textPlusPoliceNode.on("change", this._update_add_textSymbol); - this.textAngleNode.on("change", this._update_add_textSymbol); - on(this.textPlusBoldNode, "click", lang.hitch(this, this._onAddBoldClick)); - on(this.textPlusItalicNode, "click", lang.hitch(this, this._onAddItalicClick)); - on(this.textPlusUnderlineNode, "click", lang.hitch(this, this._onAddUnderlineClick)); - - this.EditTextPlusPoliceNode.on("change", this._update_edit_textSymbol); - this.EditTextAngleNode.on("change", this._update_edit_textSymbol); - on(this.EditTextPlusBoldNode, "click", lang.hitch(this, this._onEditBoldClick)); - on(this.EditTextPlusItalicNode, "click", lang.hitch(this, this._onEditItalicClick)); - on(this.EditTextPlusUnderlineNode, "click", lang.hitch(this, this._onEditUnderlineClick)); - - }, - - _nameChanged:function(){ - this._update_add_textSymbol() - }, - - _editNameChanged:function(){ - this._update_edit_textSymbol() - }, - - _update_add_textSymbol:function(){ - var family = this.textPlusPoliceNode.value; - var angle = this.textAngleNode.value; - var weight = this._drawPlus["add"]["bold"] ? esri.symbol.Font.WEIGHT_BOLD : esri.symbol.Font.WEIGHT_NORMAL; - var style = this._drawPlus["add"]["italic"] ? esri.symbol.Font.STYLE_ITALIC : esri.symbol.Font.STYLE_NORMAL; - var decoration = this._drawPlus["add"]["underline"] ? 'underline' : 'none'; - - this.textSymChooser.symbol.text = this.nameField.value; - this.textSymChooser.symbol.font.setFamily(family); - this.textSymChooser.symbol.setAngle(angle); - this.textSymChooser.symbol.font.setWeight(weight); - this.textSymChooser.symbol.font.setStyle(style); - this.textSymChooser.symbol.font.setDecoration(decoration); - - this.drawBox.setTextSymbol(this.textSymChooser.symbol); - - this.textSymChooser.textPreview.innerHTML = this.nameField.value; - this.textSymChooser.textPreview.style.fontFamily = family; - this.textSymChooser.textPreview.style['font-style'] = (this._drawPlus["add"]["italic"]) ? 'italic' : 'normal'; - this.textSymChooser.textPreview.style['font-weight'] = (this._drawPlus["add"]["bold"]) ? 'bold' : 'normal'; - this.textSymChooser.textPreview.style['text-decoration'] = (this._drawPlus["add"]["underline"]) ? 'underline' : 'none'; - this.textSymChooser.textPreview.style.transform = 'rotate(' + angle + 'deg)'; - this.textSymChooser.textPreview.style['-ms-transform'] = 'rotate(' + angle + 'deg)'; + } else if (commontype === 'polygon') { + if (this.showMeasure.checked) { + this._addPolygonMeasure(geometry); + } + } else if (commontype == 'text' && this.editorSymbolChooser.inputText.value.trim() == "") { + //Message + this.showMessage(this.nls.textWarningMessage, 'warning'); + + //Remove empty feature (text symbol without text) + graphic.getLayer().remove(graphic); + } + + this.saveInLocalStorage(); + this._editorConfig["graphicCurrent"] = graphic; + this._editorConfig["defaultSymbols"][this._editorConfig['commontype']] = graphic.symbol; + this.setMode("list"); + }, - this.textAnglePreviewNode.style['font-style'] = (this._drawPlus["add"]["italic"]) ? 'italic' : 'normal'; - this.textAnglePreviewNode.style['font-weight'] = (this._drawPlus["add"]["bold"]) ? 'bold' : 'normal'; - this.textAnglePreviewNode.style['text-decoration'] = (this._drawPlus["add"]["underline"]) ? 'underline' : 'none'; - this.textAnglePreviewNode.style.transform = 'rotate(' + angle + 'deg)'; - this.textAnglePreviewNode.style['-ms-transform'] = 'rotate(' + angle + 'deg)'; + editorEnableMapPreview : function (bool) { + //if deactivate + if (!bool) { + //Hide point + if(this._editorConfig["phantom"]["point"]) + this._editorConfig["phantom"]["point"].hide(); + + this._editorConfig["phantom"]["symbol"] = false; + + //Remove map handlers + if (this._editorConfig["phantom"]["handle"]) { + dojo.disconnect(this._editorConfig["phantom"]["handle"]); + this._editorConfig["phantom"]["handle"] = false; + } + return; + } + + //Create layer if doesn't exist + if (!this._editorConfig["phantom"]["layer"]) { + this._editorConfig["phantom"]["layer"] = new GraphicsLayer({ + id : this.id + "__phantomLayer" + }); + // this._editorConfig["phantom"]["point"] + var center = this.map.extent.getCenter(); + this._editorConfig["phantom"]["point"] = new Graphic(center, this._editorConfig["phantom"]["symbol"], {}); + this._editorConfig["phantom"]["layer"].add(this._editorConfig["phantom"]["point"]); + this._editorConfig["phantom"]["point"].hide(); + + this.map.addLayer(this._editorConfig["phantom"]["layer"]); + } else { + this._editorConfig["phantom"]["point"].setSymbol(this._editorConfig["phantom"]["symbol"]); + } + + //Track mouse on map + if (!this._editorConfig["phantom"]["handle"]) { + this._editorConfig["phantom"]["handle"] = on(this.map, 'mouse-move, mouse-out, mouse-over', lang.hitch(this, function (evt) { + if (this.state === 'opened') { + switch (evt.type) { + case 'mousemove': + if (this._editorConfig["phantom"]["point"]) { + this._editorConfig["phantom"]["point"].setGeometry(evt.mapPoint); + this._editorConfig["phantom"]["point"].show(); + } + break; + case 'mouseout': + if (this._editorConfig["phantom"]["point"]) { + this._editorConfig["phantom"]["point"].hide(); + } + break; + case 'mouseover': + if (this._editorConfig["phantom"]["point"]) { + this._editorConfig["phantom"]["point"].setGeometry(evt.mapPoint); + this._editorConfig["phantom"]["point"].show(); + } + break; + } + } + })); + } + + }, - if(this._phantomSymbol && this._phantomSymbol.font){ - this._phantomSymbol.text = this.nameField.value; - this._phantomSymbol.font.setFamily(family); - this._phantomSymbol.setAngle(angle); - this._phantomSymbol.font.setWeight(weight); - this._phantomSymbol.font.setStyle(style); - this._phantomSymbol.font.setDecoration(decoration); - } - }, - - _update_edit_textSymbol:function(){ - var family = this.EditTextPlusPoliceNode.value; - var angle = this.EditTextAngleNode.value; - var weight = this._drawPlus["edit"]["bold"] ? esri.symbol.Font.WEIGHT_BOLD : esri.symbol.Font.WEIGHT_NORMAL; - var style = this._drawPlus["edit"]["italic"] ? esri.symbol.Font.STYLE_ITALIC : esri.symbol.Font.STYLE_NORMAL; - var decoration = this._drawPlus["edit"]["underline"] ? 'underline' : 'none'; + editorUpdateMapPreview:function(symbol){ + if(this.editorSymbolChooser.type != "text" && this.editorSymbolChooser.type != "marker"){ + return; + } + + if (this._editorConfig["phantom"]["handle"]&&this._editorConfig["phantom"]["point"]) { + this._editorConfig["phantom"]["symbol"] = symbol; + this._editorConfig["phantom"]["point"].setSymbol(symbol); + } + + }, - - this._EditSymbolChooser.symbol.text = this.editNameField.value; - this._EditSymbolChooser.symbol.font.setFamily(family); - this._EditSymbolChooser.symbol.setAngle(angle); - this._EditSymbolChooser.symbol.font.setWeight(weight); - this._EditSymbolChooser.symbol.font.setStyle(style); - this._EditSymbolChooser.symbol.font.setDecoration(decoration); + editorOnClickAddCancelButon : function () { + this.setMode("add1"); + }, - this._EditSymbolChooser.textPreview.innerHTML = this.editNameField.value; - this._EditSymbolChooser.textPreview.style.fontFamily = family; - this._EditSymbolChooser.textPreview.style['font-style'] = (this._drawPlus["edit"]["italic"]) ? 'italic' : 'normal'; - this._EditSymbolChooser.textPreview.style['font-weight'] = (this._drawPlus["edit"]["bold"]) ? 'bold' : 'normal'; - this._EditSymbolChooser.textPreview.style['text-decoration'] = (this._drawPlus["edit"]["underline"]) ? 'underline' : 'none'; - this._EditSymbolChooser.textPreview.style.transform = 'rotate(' + angle + 'deg)'; - this._EditSymbolChooser.textPreview.style['-ms-transform'] = 'rotate(' + angle + 'deg)'; - this.EditTextAnglePreviewNode.style['font-style'] = (this._drawPlus["edit"]["italic"]) ? 'italic' : 'normal'; - this.EditTextAnglePreviewNode.style['font-weight'] = (this._drawPlus["edit"]["bold"]) ? 'bold' : 'normal'; - this.EditTextAnglePreviewNode.style['text-decoration'] = (this._drawPlus["edit"]["underline"]) ? 'underline' : 'none'; - this.EditTextAnglePreviewNode.style.transform = 'rotate(' + angle + 'deg)'; - this.EditTextAnglePreviewNode.style['-ms-transform'] = 'rotate(' + angle + 'deg)'; - }, - - _enableClass:function(elt, className, bool){ - if(elt.classList){ - if(bool) - elt.classList.add(className); - else - elt.classList.remove(className); - return; - } - elt.className = elt.className.replace(className,"").replace(" ", " ").trim(); - if(bool) - elt.className += className; - }, - - _onAddBoldClick:function(evt){ - this._drawPlus["add"]["bold"] = !this._drawPlus["add"]["bold"]; - this._enableClass(this.textPlusBoldNode, 'selected',this._drawPlus["add"]["bold"]); - this._update_add_textSymbol(); +////////////////////////////////////// Measure methods ////////////////////////////////////////////// + _resetUnitsArrays : function () { + this.defaultDistanceUnits = []; + this.defaultAreaUnits = []; + this.configDistanceUnits = []; + this.configAreaUnits = []; + this.distanceUnits = []; + this.areaUnits = []; }, - _onAddItalicClick:function(evt){ - this._drawPlus["add"]["italic"] = !this._drawPlus["add"]["italic"]; - this._enableClass(this.textPlusItalicNode, 'selected',this._drawPlus["add"]["italic"]); - this._update_add_textSymbol(); + + _getDefaultDistanceUnitInfo : function (unit) { + for (var i = 0; i < this.defaultDistanceUnits.length; i++) { + var unitInfo = this.defaultDistanceUnits[i]; + if (unitInfo.unit === unit) { + return unitInfo; + } + } + return null; }, - _onAddUnderlineClick:function(evt){ - this._drawPlus["add"]["underline"] = !this._drawPlus["add"]["underline"]; - this._enableClass(this.textPlusUnderlineNode, 'selected',this._drawPlus["add"]["underline"]); - this._update_add_textSymbol(); + + _getDefaultAreaUnitInfo : function (unit) { + for (var i = 0; i < this.defaultAreaUnits.length; i++) { + var unitInfo = this.defaultAreaUnits[i]; + if (unitInfo.unit === unit) { + return unitInfo; + } + } + return null; }, - _onEditBoldClick:function(evt){ - this._drawPlus["edit"]["bold"] = !this._drawPlus["edit"]["bold"]; - this._enableClass(this.EditTextPlusBoldNode, 'selected',this._drawPlus["edit"]["bold"]); - this._update_edit_textSymbol(); + + _getDistanceUnitInfo : function (unit) { + for (var i = 0; i < this.distanceUnits.length; i++) { + var unitInfo = this.distanceUnits[i]; + if (unitInfo.unit === unit) { + return unitInfo; + } + } + return null; }, - _onEditItalicClick:function(evt){ - this._drawPlus["edit"]["italic"] = !this._drawPlus["edit"]["italic"]; - this._enableClass(this.EditTextPlusItalicNode, 'selected',this._drawPlus["edit"]["italic"]); - this._update_edit_textSymbol(); + + _getAreaUnitInfo : function (unit) { + for (var i = 0; i < this.areaUnits.length; i++) { + var unitInfo = this.areaUnits[i]; + if (unitInfo.unit === unit) { + return unitInfo; + } + } + return null; }, - _onEditUnderlineClick:function(evt){ - this._drawPlus["edit"]["underline"] = !this._drawPlus["edit"]["underline"]; - this._enableClass(this.EditTextPlusUnderlineNode, 'selected',this._drawPlus["edit"]["underline"]); - this._update_edit_textSymbol(); + + _setMeasureVisibility : function () { + var display = (this.showMeasure.checked) ? 'block' : 'none'; + html.setStyle(this.areaMeasure, 'display', display); + html.setStyle(this.distanceMeasure, 'display', display); }, - - _phantomPoint:false, - _phantomSymbol:false, - _phantomLayer:false, - _phantomHandle:false, - - _enableMapPreview:function(bool){ - if(!bool){ - if(this._phantomPoint) - this._phantomPoint.hide(); - if(this._phantomHandle){ - dojo.disconnect(this._phantomHandle); - this._phantomHandle = false; - } - return; - } - - //Create layer - if(!this._phantomLayer){ - this._phantomLayer = new GraphicsLayer({id:this.id+"__phantomLayer"}); - // this._phantomPoint - var center = this.map.extent.getCenter(); - this._phantomPoint = new Graphic(center, this._phantomSymbol, {}); - this._phantomLayer.add(this._phantomPoint); - this._phantomPoint.hide(); - - this.map.addLayer(this._phantomLayer); - } - else{ - this._phantomPoint.setSymbol(this._phantomSymbol); - } - - //Track mouse on map - if(!this._phantomHandle){ - this._phantomHandle = on(this.map, 'mouse-move, mouse-out, mouse-over', lang.hitch(this, function(evt) { - if (this.state === 'opened') { - switch (evt.type) { - case 'mousemove': - if (this._phantomPoint) { - this._phantomPoint.setGeometry(evt.mapPoint); - this._phantomPoint.show(); - } - break; - case 'mouseout': - if (this._phantomPoint) { - this._phantomPoint.hide(); - } - break; - case 'mouseover': - if (this._phantomPoint) { - this._phantomPoint.setGeometry(evt.mapPoint); - this._phantomPoint.show(); - } - break; - } - } - })); - } - }, - - _onIconSelected:function(target,geotype,commontype){ - this._setDrawDefaultSymbols(); - if(commontype === 'point'){ - this.viewStack.switchView(this.pointSection); - this._phantomSymbol = this.pointSymChooser.getSymbol(); - this._enableMapPreview(true); - } - else if(commontype === 'polyline'){ - this.viewStack.switchView(this.lineSection); - this._enableMapPreview(false); - } - else if(commontype === 'polygon'){ - this.viewStack.switchView(this.polygonSection); - this._enableMapPreview(false); - } - else if(commontype === 'text'){ - this.textSymChooser.inputText.value = this.nameField.value; - if(this.textSymChooser.inputText.value.trim() == ""){ - this.showMessage(this.nls.textWarningMessage, 'warning'); - return false; - } - - this._phantomSymbol = this.textSymChooser.getSymbol(); - this.drawBox.setTextSymbol(this._phantomSymbol); - this.viewStack.switchView(this.textSection); - this._controlTextIsWritten(); - - this._enableMapPreview(true); - } - this._setMeasureVisibility(); - - }, - - _controlTextIsWritten : function(){ - this.textSymChooser.inputText.value = this.nameField.value; + _addLineMeasure : function (geometry) { + var a = Font.STYLE_ITALIC; + var b = Font.VARIANT_NORMAL; + var c = Font.WEIGHT_BOLD; + var symbolFont = new Font("16px", a, b, c, "Courier"); + var fontColor = new Color([0, 0, 0, 1]); + var ext = geometry.getExtent(); + var center = ext.getCenter(); + var geoLine = webMercatorUtils.webMercatorToGeographic(geometry); + var unit = this.distanceUnitSelect.value; + var lengths = geodesicUtils.geodesicLengths([geoLine], esriUnits[unit]); + var abbr = this._getDistanceUnitInfo(unit).label; + var localeLength = jimuUtils.localizeNumber(lengths[0].toFixed(1)); + var length = localeLength + " " + abbr; + var textSymbol = new TextSymbol(length, symbolFont, fontColor); + var labelGraphic = new Graphic(center, textSymbol, { + "name" : textSymbol.text, + "description" : "" + }, null); + this.drawBox.drawLayer.add(labelGraphic); + }, + + _addPolygonMeasure : function (geometry) { + var a = Font.STYLE_ITALIC; + var b = Font.VARIANT_NORMAL; + var c = Font.WEIGHT_BOLD; + var symbolFont = new Font("16px", a, b, c, "Courier"); + var fontColor = new Color([0, 0, 0, 1]); + var ext = geometry.getExtent(); + var center = ext.getCenter(); + var geoPolygon = webMercatorUtils.webMercatorToGeographic(geometry); + var areaUnit = this.areaUnitSelect.value; + var areaAbbr = this._getAreaUnitInfo(areaUnit).label; + var areas = geodesicUtils.geodesicAreas([geoPolygon], esriUnits[areaUnit]); + var localeArea = jimuUtils.localizeNumber(areas[0].toFixed(1)); + var area = localeArea + " " + areaAbbr; + + var polyline = new Polyline(geometry.spatialReference); + var points = geometry.rings[0]; + points = points.slice(0, points.length - 1); + polyline.addPath(points); + var geoPolyline = webMercatorUtils.webMercatorToGeographic(polyline); + var lengthUnit = this.distanceUnitSelect.value; + var lengthAbbr = this._getDistanceUnitInfo(lengthUnit).label; + var lengths = geodesicUtils.geodesicLengths([geoPolyline], esriUnits[lengthUnit]); + var localeLength = jimuUtils.localizeNumber(lengths[0].toFixed(1)); + var length = localeLength + " " + lengthAbbr; + var text = area + " " + length; + + var textSymbol = new TextSymbol(text, symbolFont, fontColor); + var labelGraphic = new Graphic(center, textSymbol, { + "name" : textSymbol.text, + "description" : "" + }, null); + this.drawBox.drawLayer.add(labelGraphic); + }, - var tr = this._parentByTag(this.textSymChooser.inputText, 'tr'); - if(tr) - tr.style.display = 'none'; +//////// INIT METHODS //////////////////////////////////////////////////////////////////////////////////////////////////////// + _bindEvents : function () { + //bind DrawBox + this.own(on(this.drawBox, 'IconSelected', lang.hitch(this, this.drawBoxOnTypeSelected))); + this.own(on(this.drawBox, 'DrawEnd', lang.hitch(this, this.drawBoxOnDrawEnd))); + + //Bind symbol chooser change + this.own(on(this.editorSymbolChooser, 'change', lang.hitch(this, function () { + this.editorSetDefaultSymbols(); + if(this.editorSymbolChooser.type == "text") + this.editorUpdateTextPlus(); + else if(this.editorSymbolChooser.type == "marker") + this.editorUpdateMapPreview(this.editorSymbolChooser.getSymbol()); + + }))); + + //bind unit events + this.own(on(this.showMeasure, 'click', lang.hitch(this, this._setMeasureVisibility))); + + //hitch list event + this.listOnActionClick = lang.hitch(this, this.listOnActionClick); + //hitch import file loading + this.importOnFileLoad = lang.hitch(this, this.importOnFileLoad); + + //Bind draw plus event + this.editorUpdateTextPlus = lang.hitch(this, this.editorUpdateTextPlus); + this.editorTextPlusPoliceNode.on("change", this.editorUpdateTextPlus); + this.editorTextPlusAngleNode.on("change", this.editorUpdateTextPlus); + on(this.editorTextPlusBoldNode, "click", lang.hitch(this, function (evt) { + this._editorConfig["drawPlus"]["bold"] = !this._editorConfig["drawPlus"]["bold"]; + this._UTIL__enableClass(this.editorTextPlusBoldNode, 'selected', this._editorConfig["drawPlus"]["bold"]); + this.editorUpdateTextPlus(); + })); + on(this.editorTextPlusItalicNode, "click", lang.hitch(this, function (evt) { + this._editorConfig["drawPlus"]["italic"] = !this._editorConfig["drawPlus"]["italic"]; + this._UTIL__enableClass(this.editorTextPlusItalicNode, 'selected', this._editorConfig["drawPlus"]["italic"]); + this.editorUpdateTextPlus(); + })); + on(this.editorTextPlusUnderlineNode, "click", lang.hitch(this, function (evt) { + this._editorConfig["drawPlus"]["underline"] = !this._editorConfig["drawPlus"]["underline"]; + this._UTIL__enableClass(this.editorTextPlusUnderlineNode, 'selected', this._editorConfig["drawPlus"]["underline"]); + this.editorUpdateTextPlus(); + })); + + }, - var value = this.textSymChooser.inputText.value.trim(); - if(value==""){ - html.setStyle(this.nameField,'box-shadow','3px 3px 1px 1px rgba(200, 0, 0, 0.7)'); - this.nameField.focus(); - } - else{ - html.setStyle(this.nameField,'box-shadow','none'); - } - }, + _menuInit : function () { + this._menuButtons = { + "add" : this.menuAddButton, + "edit" : this.menuEditButton, + "list" : this.menuListButton, + "importExport" : this.menuListImportExport, + }; + + var views = [this.addSection, this.editorSection, this.listSection]; + + if (this.config.allowImportExport) { + views.push(this.importExportSection); + } else { + this.menuListImportExport.style.display = 'none'; + } - _onDrawEnd:function(graphic,geotype,commontype){ - var geometry = graphic.geometry; + this.TabViewStack = new ViewStack({ + viewType : 'dom', + views : views + }); + html.place(this.TabViewStack.domNode, this.settingAllContent); + }, - this._enableMapPreview(false); + _initLocalStorage : function () { + if (!this.config.allowLocalStorage) + return; + + this._localStorageKey = + (this.config.localStorageKey) + ? 'WebAppBuilder.2D.eDraw.' + this.config.localStorageKey + : 'WebAppBuilder.2D.eDraw'; + + var content = localStore.get(this._localStorageKey); + + if (!content || !content.features || content.features.length < 1) + return; + + //Closure with timeout to be sure widget is ready + (function (widget) { + setTimeout( + function () { + widget.importJsonContent(content, "name", "description"); + widget.showMessage(widget.nls.localLoading); + }, 200); + })(this); + + }, - graphic.attributes = { - "name":this.nameField.value, - "description":this.descriptionField.value - } + _initDrawingPopupAndClick : function () { + //Set popup template + var infoTemplate = new esri.InfoTemplate("${name}", "${description}"); + this.drawBox.drawLayer.setInfoTemplate(infoTemplate); + + //Set draw click + this._onDrawClick = lang.hitch(this, function (evt) { + if (!evt.graphic) + return; + + this._editorConfig["graphicCurrent"] = evt.graphic; + this.setMode("list"); + }); + this.drawBox.drawLayer.on("click", this._onDrawClick); + + }, - if(geometry.type === 'extent'){ - var a = geometry; - var polygon = new Polygon(a.spatialReference); - var r=[[a.xmin,a.ymin],[a.xmin,a.ymax],[a.xmax,a.ymax],[a.xmax,a.ymin],[a.xmin,a.ymin]]; - polygon.addRing(r); - geometry = polygon; - - graphic.setGeometry(polygon); - var layer = graphic.getLayer(); - layer.remove(graphic); - layer.add(graphic); - - commontype = 'polygon'; - } - if(commontype === 'polyline'){ - if(this.showMeasure.checked){ - this._addLineMeasure(geometry); - } - } - else if(commontype === 'polygon'){ - if(this.showMeasure.checked){ - this._addPolygonMeasure(geometry); - } - } - else if(commontype == 'text' && this.textSymChooser.inputText.value.trim() == ""){ - //Message - this.showMessage(this.nls.textWarningMessage, 'warning'); + _initUnitSelect : function () { + this._initDefaultUnits(); + this._initConfigUnits(); + var a = this.configDistanceUnits; + var b = this.defaultDistanceUnits; + this.distanceUnits = a.length > 0 ? a : b; + var c = this.configAreaUnits; + var d = this.defaultAreaUnits; + this.areaUnits = c.length > 0 ? c : d; + array.forEach(this.distanceUnits, lang.hitch(this, function (unitInfo) { + var option = { + value : unitInfo.unit, + label : unitInfo.label + }; + this.distanceUnitSelect.addOption(option); + })); + + array.forEach(this.areaUnits, lang.hitch(this, function (unitInfo) { + var option = { + value : unitInfo.unit, + label : unitInfo.label + }; + this.areaUnitSelect.addOption(option); + })); + }, - //Remove empty feature (text symbol without text) - graphic.getLayer().remove(graphic); - } + _initDefaultUnits : function () { + this.defaultDistanceUnits = [{ + unit : 'KILOMETERS', + label : this.nls.kilometers + }, { + unit : 'MILES', + label : this.nls.miles + }, { + unit : 'METERS', + label : this.nls.meters + }, { + unit : 'FEET', + label : this.nls.feet + }, { + unit : 'YARDS', + label : this.nls.yards + } + ]; + + this.defaultAreaUnits = [{ + unit : 'SQUARE_KILOMETERS', + label : this.nls.squareKilometers + }, { + unit : 'SQUARE_MILES', + label : this.nls.squareMiles + }, { + unit : 'ACRES', + label : this.nls.acres + }, { + unit : 'HECTARES', + label : this.nls.hectares + }, { + unit : 'SQUARE_METERS', + label : this.nls.squareMeters + }, { + unit : 'SQUARE_FEET', + label : this.nls.squareFeet + }, { + unit : 'SQUARE_YARDS', + label : this.nls.squareYards + } + ]; + }, + + _initConfigUnits : function () { + array.forEach(this.config.distanceUnits, lang.hitch(this, function (unitInfo) { + var unit = unitInfo.unit; + if (esriUnits[unit]) { + var defaultUnitInfo = this._getDefaultDistanceUnitInfo(unit); + unitInfo.label = defaultUnitInfo.label; + this.configDistanceUnits.push(unitInfo); + } + })); + + array.forEach(this.config.areaUnits, lang.hitch(this, function (unitInfo) { + var unit = unitInfo.unit; + if (esriUnits[unit]) { + var defaultUnitInfo = this._getDefaultAreaUnitInfo(unit); + unitInfo.label = defaultUnitInfo.label; + this.configAreaUnits.push(unitInfo); + } + })); + }, + +//////////////////////////// WIDGET CORE METHODS /////////////////////////////////////////////////////////////////////////////////////// + + postMixInProperties : function () { + this.inherited(arguments); + this._resetUnitsArrays(); + }, + + postCreate : function () { + this.inherited(arguments); + + //Create symbol chooser + this.editorSymbolChooser = new SymbolChooser( + { + class : "full-width", + "type" : "text", + "symbol" : new SimpleMarkerSymbol() + }, + this.editorSymbolChooserDiv + ); + + this.drawBox.setMap(this.map); + + //Initialize menu + this._menuInit(); + + //Init measure units + this._initUnitSelect(); + + //Bind and hitch events + this._bindEvents(); + + //load if drawings in localStorage + this._initLocalStorage(); + + //Popup or click init + this._initDrawingPopupAndClick(); + + //Create edit dijit + this._editorConfig["editToolbar"] = new Edit(this.map); + }, - this.viewStack.switchView(false); - this._setMeasureVisibility(); - this._saveInLocalStorage(); - this._editGraphic = graphic; - this.setTab("list"); - }, - - _initUnitSelect:function(){ - this._initDefaultUnits(); - this._initConfigUnits(); - var a = this.configDistanceUnits; - var b = this.defaultDistanceUnits; - this.distanceUnits = a.length > 0 ? a : b; - var c = this.configAreaUnits; - var d = this.defaultAreaUnits; - this.areaUnits = c.length > 0 ? c : d; - array.forEach(this.distanceUnits,lang.hitch(this,function(unitInfo){ - var option = { - value:unitInfo.unit, - label:unitInfo.label - }; - this.distanceUnitSelect.addOption(option); - })); - - array.forEach(this.areaUnits,lang.hitch(this,function(unitInfo){ - var option = { - value:unitInfo.unit, - label:unitInfo.label - }; - this.areaUnitSelect.addOption(option); - })); - }, - - _initDefaultUnits:function(){ - this.defaultDistanceUnits = [{ - unit: 'KILOMETERS', - label: this.nls.kilometers - }, { - unit: 'MILES', - label: this.nls.miles - }, { - unit: 'METERS', - label: this.nls.meters - }, { - unit: 'FEET', - label: this.nls.feet - }, { - unit: 'YARDS', - label: this.nls.yards - }]; - - this.defaultAreaUnits = [{ - unit: 'SQUARE_KILOMETERS', - label: this.nls.squareKilometers - }, { - unit: 'SQUARE_MILES', - label: this.nls.squareMiles - }, { - unit: 'ACRES', - label: this.nls.acres - }, { - unit: 'HECTARES', - label: this.nls.hectares - }, { - unit: 'SQUARE_METERS', - label: this.nls.squareMeters - }, { - unit: 'SQUARE_FEET', - label: this.nls.squareFeet - }, { - unit: 'SQUARE_YARDS', - label: this.nls.squareYards - }]; - }, - - _initConfigUnits:function(){ - array.forEach(this.config.distanceUnits,lang.hitch(this,function(unitInfo){ - var unit = unitInfo.unit; - if(esriUnits[unit]){ - var defaultUnitInfo = this._getDefaultDistanceUnitInfo(unit); - unitInfo.label = defaultUnitInfo.label; - this.configDistanceUnits.push(unitInfo); - } - })); - - array.forEach(this.config.areaUnits,lang.hitch(this,function(unitInfo){ - var unit = unitInfo.unit; - if(esriUnits[unit]){ - var defaultUnitInfo = this._getDefaultAreaUnitInfo(unit); - unitInfo.label = defaultUnitInfo.label; - this.configAreaUnits.push(unitInfo); - } - })); - }, - - _getDefaultDistanceUnitInfo:function(unit){ - for(var i=0;i 0) + this.setMode("list"); + else + this.setMode("add1"); + }, + + onClose : function () { + this.drawBox.deactivate(); + this.setInfoWindow(false); + this.editorEnableMapPreview(false); + this.editorActivateGeometryEdit(false); + this.map.infoWindow.hide(); + }, + + destroy : function () { + if (this.drawBox) { + this.drawBox.destroy(); + this.drawBox = null; + } + if (this.editorSymbolChooser) { + this.editorSymbolChooser.destroy(); + this.editorSymbolChooser = null; } - } - return null; + this.inherited(arguments); }, - destroy: function() { - if(this.drawBox){ - this.drawBox.destroy(); - this.drawBox = null; - } - if(this.pointSymChooser){ - this.pointSymChooser.destroy(); - this.pointSymChooser = null; - } - if(this.lineSymChooser){ - this.lineSymChooser.destroy(); - this.lineSymChooser = null; - } - if(this.fillSymChooser){ - this.fillSymChooser.destroy(); - this.fillSymChooser = null; - } - if(this.textSymChooser){ - this.textSymChooser.destroy(); - this.textSymChooser = null; - } - this.inherited(arguments); - } - }); - }); \ No newline at end of file +///////////////////////// UTILS METHODS //////////////////////////////////////////////////////////////////////////// + _UTIL__enableClass : function (elt, className, bool) { + if (elt.classList) { + if (bool) + elt.classList.add(className); + else + elt.classList.remove(className); + return; + } + elt.className = elt.className.replace(className, "").replace(" ", " ").trim(); + if (bool) + elt.className += className; + }, + + _UTIL__getParentByTag : function (el, tagName) { + tagName = tagName.toLowerCase(); + while (el && el.parentNode) { + el = el.parentNode; + if (el.tagName && el.tagName.toLowerCase() == tagName) { + return el; + } + } + return null; + } + + }); +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +}); diff --git a/css/style.css b/css/style.css index bb19b89..7e12ab4 100644 --- a/css/style.css +++ b/css/style.css @@ -1,74 +1,79 @@ - -.jimu-widget-draw { +.jimu-widget-edraw { font-size: 14px; height: 100%; min-height: 192px; min-width: 270px; width: 100%; } -.jimu-widget-draw .full-width { +.jimu-widget-edraw .full-width { width: 100% !important; } -.jimu-widget-draw .measure-section { - display: none; +.jimu-widget-edraw .editor-add-message{ + margin-top:10px; + font-style:italic; +} +.jimu-widget-edraw .measure-section { margin-top: 12px; width: 100%; + margin-bottom: 12px; + padding-right: 3px; + padding-bottom: 10px; } -.jimu-widget-draw .area-units-tip { +.jimu-widget-edraw .area-units-tip { height: 30px; line-height: 30px; padding-left: 17px; } -.jimu-rtl .jimu-widget-draw .area-units-tip { +.jimu-rtl .jimu-widget-edraw .area-units-tip { padding-left: 0; padding-right: 17px; } -.jimu-widget-draw .distance-units-tip { +.jimu-widget-edraw .distance-units-tip { height: 30px; line-height: 30px; padding-left: 17px; } -.jimu-rtl .jimu-widget-draw .distance-units-tip { +.jimu-rtl .jimu-widget-edraw .distance-units-tip { padding-left: 0; padding-right: 17px; } -.jimu-widget-draw .dijitArrowButtonContainer { +.jimu-widget-edraw .dijitArrowButtonContainer { width: 40px; } -.jimu-widget-draw .dijitSelect { +.jimu-widget-edraw .dijitSelect { height: 40px; width: 100%; } -.jimu-widget-draw .dijitReset.dijitLeft.dijitButtonNode.dijitArrowButton.dijitDownArrowButton { +.jimu-widget-edraw .dijitReset.dijitLeft.dijitButtonNode.dijitArrowButton.dijitDownArrowButton { width: 100%; } -.jimu-widget-draw .dijitReset.dijitLeft.dijitButtonNode.dijitArrowButton.dijitUpArrowButton { +.jimu-widget-edraw .dijitReset.dijitLeft.dijitButtonNode.dijitArrowButton.dijitUpArrowButton { width: 100%; } -.jimu-widget-draw .dijitReset.dijitLeft.dijitButtonNode.dijitArrowButton.dijitDownArrowButton .dijitArrowButtonInner { +.jimu-widget-edraw .dijitReset.dijitLeft.dijitButtonNode.dijitArrowButton.dijitDownArrowButton .dijitArrowButtonInner { width: 100%; } -.jimu-widget-draw .dijitReset.dijitLeft.dijitButtonNode.dijitArrowButton.dijitUpArrowButton .dijitArrowButtonInner { +.jimu-widget-edraw .dijitReset.dijitLeft.dijitButtonNode.dijitArrowButton.dijitUpArrowButton .dijitArrowButtonInner { width: 100%; } -.jimu-widget-draw .menu { +.jimu-widget-edraw .menu { border-bottom: 2px solid rgb(72, 85, 102); height: 36px; margin-bottom: 10px; width: 100%; } -.jimu-widget-draw .menu-item { +.jimu-widget-edraw .menu-item { background-color: rgba(72, 85, 102, 0.4); border: 1px solid rgba(72, 85, 102, 0.8); float: left; margin-right: 5px; width: 36px; } -.jimu-widget-draw .menu-item:hover { +.jimu-widget-edraw .menu-item:hover { background-color: rgba(72, 85, 102, 0.6); cursor: pointer; } -.jimu-widget-draw .menu-item-active { +.jimu-widget-edraw .menu-item-active { -moz-border-bottom-colors: none; -moz-border-left-colors: none; -moz-border-right-colors: none; @@ -83,37 +88,37 @@ margin-right: 5px; width: 36px; } -.jimu-widget-draw .menu-item-active:hover { +.jimu-widget-edraw .menu-item-active:hover { } -.jimu-widget-draw .hidden { +.jimu-widget-edraw .hidden { display: none; } -.jimu-widget-draw .draw-table tr { +.jimu-widget-edraw .draw-table tr { border: 1px solid white; } -.jimu-widget-draw .draw-table th { +.jimu-widget-edraw .draw-table th { background-color: #8d989e; font-weight: bold; text-align: center; } -.jimu-widget-draw .draw-table tr:hover th { +.jimu-widget-edraw .draw-table tr:hover th { background-color: #8d989e; } -.jimu-widget-draw .draw-table .td-center { +.jimu-widget-edraw .draw-table .td-center { text-align: center; } -.jimu-widget-draw .draw-table .selected td { +.jimu-widget-edraw .draw-table .selected td { background-color: rgba(15, 108, 159, 0.2); } -.jimu-widget-draw .draw-table .selected:hover td { +.jimu-widget-edraw .draw-table .selected:hover td { background-color: rgba(15, 108, 159, 0.3); } -.jimu-widget-draw .list-draw-actions { +.jimu-widget-edraw .list-draw-actions { height: 100%; vertical-align: middle; width: 197px; } -.jimu-widget-draw .list-draw-actions span { +.jimu-widget-edraw .list-draw-actions span { border-radius: 5px; color: white; display: block; @@ -127,44 +132,44 @@ vertical-align: middle; width: 30px; } -.jimu-widget-draw .list-draw-actions span.text { +.jimu-widget-edraw .list-draw-actions span.text { background: none repeat scroll 0 0 rgba(0, 0, 0, 0); color: black; font-size: 1em; position: relative; width: auto; } -.jimu-widget-draw .list-draw-actions span.text:hover { +.jimu-widget-edraw .list-draw-actions span.text:hover { border: medium none; cursor: auto; font-size: 1em; } -.jimu-widget-draw .list-draw-actions span.clear { +.jimu-widget-edraw .list-draw-actions span.clear { background-image: url("images/clear.png"); } -.jimu-widget-draw .list-draw-actions span.edit { +.jimu-widget-edraw .list-draw-actions span.edit { background-image: url("images/edit.png"); } -.jimu-widget-draw .list-draw-actions span.zoom { +.jimu-widget-edraw .list-draw-actions span.zoom { background-image: url("images/zoom.png"); } -.jimu-widget-draw .list-draw-actions span.up { +.jimu-widget-edraw .list-draw-actions span.up { background-image: url("images/up.png"); } -.jimu-widget-draw .list-draw-actions span.down { +.jimu-widget-edraw .list-draw-actions span.down { background-image: url("images/down.png"); } -.jimu-widget-draw .list-draw-actions span.export { +.jimu-widget-edraw .list-draw-actions span.export { background-image: url("images/download.png"); } -.jimu-widget-draw .list-draw-actions span.import { +.jimu-widget-edraw .list-draw-actions span.import { background-image: url("images/upload.png"); } -.jimu-widget-draw .list-draw-actions span:hover { +.jimu-widget-edraw .list-draw-actions span:hover { border: 1px solid rgb(72, 85, 102); cursor: pointer; } -.jimu-widget-draw .title { +.jimu-widget-edraw .title { margin-left: 5px; margin-top: 5px; } @@ -186,57 +191,57 @@ height: 48px; width: 48px; } -.jimu-widget-draw p.no { +.jimu-widget-edraw p.no { display: none; } -.jimu-widget-draw p.info { +.jimu-widget-edraw p.info { background-color: lightblue; border-radius: 3px; padding: 3px; width: 100%; } -.jimu-widget-draw p.error { +.jimu-widget-edraw p.error { border-radius: 3px; padding: 3px; width: 100%; } -.jimu-widget-draw p.warning { +.jimu-widget-edraw p.warning { background-color: orange; border-radius: 3px; padding: 3px; width: 100%; } -.jimu-widget-draw h2 { +.jimu-widget-edraw h2 { margin-bottom: 0; margin-top: 2px; } -.jimu-widget-draw .draw-import { +.jimu-widget-edraw .draw-import { height: 50px; width: 100%; } -.jimu-widget-draw .draw-import .file { +.jimu-widget-edraw .draw-import .file { background-color: rgba(255, 255, 255, 0.5); border-radius: 5px; cursor: pointer; float: left; padding: 5px; } -.jimu-widget-draw .draw-import > a { +.jimu-widget-edraw .draw-import > a { float: left; height: 36px; width: 36px; } -.jimu-widget-draw #nameField { +.jimu-widget-edraw #nameField { width: 100%; } -.jimu-widget-draw #descriptionField { +.jimu-widget-edraw #descriptionField { min-height: 60px; width: 100%; } -.jimu-widget-draw label { +.jimu-widget-edraw label { font-weight: bold; } -.jimu-widget-draw .content { +.jimu-widget-edraw .content { background-color: rgba(78, 130, 138, 0.1); height: calc(100% - 100px); overflow-x: hidden; @@ -245,72 +250,72 @@ width: calc(100%); } -.jimu-widget-draw .bloc{ +.jimu-widget-edraw .bloc{ background-color: rgba(78, 130, 138, 0.1); } -.jimu-widget-draw .content hr { +.jimu-widget-edraw .content hr { color: rgba(78, 130, 138, 0.6); } -.jimu-widget-draw .footer { +.jimu-widget-edraw .footer { bottom: 0; position: absolute; width: 100%; } -.jimu-widget-draw .footer .jimu-input { +.jimu-widget-edraw .footer .jimu-input { border-radius: 5px; color: black; } -.jimu-widget-draw .footer .jimu-input:hover { +.jimu-widget-edraw .footer .jimu-input:hover { cursor: pointer; } -.jimu-widget-draw .blue-button { +.jimu-widget-edraw .blue-button { background-color: rgba(115, 185, 255, 0.7); } -.jimu-widget-draw .blue-button:hover { +.jimu-widget-edraw .blue-button:hover { background-color: rgba(115, 185, 255, 1); } -.jimu-widget-draw .red-button { +.jimu-widget-edraw .red-button { background-color: rgba(255, 150, 115, 0.7); } -.jimu-widget-draw .red-button:hover { +.jimu-widget-edraw .red-button:hover { background-color: rgba(255, 150, 115, 1); } -.jimu-widget-draw .grey-button { +.jimu-widget-edraw .grey-button { background-color: rgba(153, 153, 153, 0.7); } -.jimu-widget-draw .grey-button:hover { +.jimu-widget-edraw .grey-button:hover { background-color: rgba(153, 153, 153, 1); } -.jimu-widget-draw .symbol-set-table{ +.jimu-widget-edraw .symbol-set-table{ width:100%; } -.jimu-widget-draw div.symbol-section.text-symbol-section > table > colgroup > col:nth-child(1) { +.jimu-widget-edraw div.symbol-section.text-symbol-section > table > colgroup > col:nth-child(1) { width: 80px; } -.jimu-widget-draw .draw-plus.font-name { +.jimu-widget-edraw .draw-plus.font-name { width:145px; height:30px; float:left;" } -.jimu-widget-draw .draw-plus.text-angle { +.jimu-widget-edraw .draw-plus.text-angle { width: 50%; } -.jimu-widget-draw .draw-plus.text-angle-sample { +.jimu-widget-edraw .draw-plus.text-angle-sample { position: absolute; margin-left: 30px; margin-top: 7px; } -.jimu-widget-draw .draw-plus.text-options { +.jimu-widget-edraw .draw-plus.text-options { float:left; padding:4px; height:30px; } -.jimu-widget-draw .draw-plus.text-option { +.jimu-widget-edraw .draw-plus.text-option { width:22px; height:22px; line-height: 22px; @@ -325,19 +330,19 @@ font-weight: bold; display: table; } -.jimu-widget-draw .draw-plus.text-option.selected { +.jimu-widget-edraw .draw-plus.text-option.selected { background-color: #C0C0C0; border-width: 2px; border-radius:2px; } -.jimu-widget-draw .draw-plus.text-option:hover{ +.jimu-widget-edraw .draw-plus.text-option:hover{ background-color: #D1D1D1; cursor:pointer; } -.jimu-widget-draw .draw-plus.text-options div.draw-plus.text-option.text-italic { +.jimu-widget-edraw .draw-plus.text-options div.draw-plus.text-option.text-italic { font-style: italic; } -.jimu-widget-draw .draw-plus.text-options div.draw-plus.text-option.text-underline { +.jimu-widget-edraw .draw-plus.text-options div.draw-plus.text-option.text-underline { text-decoration: underline; } \ No newline at end of file diff --git a/manifest.json b/manifest.json index c4f116e..4dc96dc 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "eDraw", "platform": "HTML", - "version": "1.1", + "version": "1.1.2", "wabVersion": "1.1", "author": "Esri R&D Center Beijing modified by MAGIS NC", "description": "Enhanced draw widget for WebApp Builder for Arcgis.", diff --git a/nls/fr/strings.js b/nls/fr/strings.js index 1beb3fd..d2a49ae 100644 --- a/nls/fr/strings.js +++ b/nls/fr/strings.js @@ -69,12 +69,13 @@ define( cancelButton:"Annuler", textAngle: 'Angle', fontName: 'Police', - drawSampleRotatedText: 'Texte', + drawSampleRotatedText: 'angle', boldTitle: 'Gras', boldCharacter: 'B', italicTitle: 'Italique', italicCharacter: 'I', underlineTitle: 'Souligné', - underlineCharacter: 'U' + underlineCharacter: 'U', + addMessage:'Vous pouvez maintenant faire votre dessin sur la carte' }) ); \ No newline at end of file diff --git a/nls/strings.js b/nls/strings.js index 6e9445f..3bf2e01 100644 --- a/nls/strings.js +++ b/nls/strings.js @@ -69,13 +69,14 @@ define({ cancelButton:"Cancel", textAngle: 'Text Angle', fontName: 'Font Name', - drawSampleRotatedText: 'Text', + drawSampleRotatedText: 'angle', boldTitle: 'Bold', boldCharacter: 'B', italicTitle: 'Italic', italicCharacter: 'I', underlineTitle: 'Underline', - underlineCharacter: 'U' + underlineCharacter: 'U', + addMessage:'You can now make your drawing on map' }), "ar": 1, "cs": 1,