djConfig = { parseOnLoad:false, debug:false, locale: 'en', afterOnLoad: true, dojoBlankHtmlUrl: 'blank.html', baseUrl: 'https://maps.panevezys.lt/geodas/webmap/', modulePaths:{ egov: "https://maps.panevezys.lt/geodas/webmap/Scripts/build/egov", hb: "https://maps.panevezys.lt/geodas/webmap/Scripts/build/hb" } }; hbConfig={ scripts: [{ script: 'https://maps.panevezys.lt/arcgis_js_api/library/2.4/arcgis/', checkString: "esri" },{ script: 'https://maps.panevezys.lt/extjs/3.4.0/adapter/ext/ext-base.js', checkString: "Ext" },{ script: "https://maps.panevezys.lt/extjs/3.4.0/ext-all.js", checkString: "Ext.DomHelper" },{ script: "https://maps.panevezys.lt/extjs/3.4.0/src/locale/ext-lang-lt.js", checkString: "Ext.DomHelper" },{ script: "https://maps.panevezys.lt/geodas/webmap/Scripts/build/egov/egov_layer.js", checkString: "hbWebMapAppLoadRequires" },{ script: "https://maps.panevezys.lt/arcgis_js_api/library/2.4/arcgis/js/esri/layers/FeatureLayer.js", checkString: "esri.layers.FeatureLayer" }], styles: [{ style: "https://maps.panevezys.lt/geodas/webmap/Styles/map.ashx" }], appUrl: 'https://maps.panevezys.lt/geodas/webmap/', alwaysUseProxy: false }; /** * hb map class. Loads libraries and creates map. * @param params - configuration object: * * @return */ function HbMap(params) { this.params = params||{}; /* * naudojamas scroll top timeris * * žemÄ—lapis įdÄ—tas į position:fixed elementÄ…, dÄ—l to * kai dokumentas yra pascrolintas, ESRI (gal dojo?) klaidingai * iÅsiskaičiuoja koordinates atlikinÄ—dami selection'us ir t.t. */ this._scrollTopTimer=null; } /** * adds script tags and loads all scripts. * calls callback when all libs are loaded. If libs are loaded, callback is called instantly */ HbMap.prototype.scriptsQue = []; HbMap.prototype.scriptsAdded = false; HbMap.prototype.scriptsLoaded = false; HbMap.prototype.callbackque = []; HbMap.prototype.loadScripts = function(callback,context){ if(!HbMap.prototype.scriptsAdded) { //change style try { if(this.params && this.params.target) { var el = document.getElementById(this.params.target); el.className = "hbMapLoading"; var innerEl = document.createElement("div"); innerEl.className = "hbMapLoadingInner"; innerEl.style.margin = "0"; innerEl.style.border = "solid 1px #bbbbbb"; innerEl.style.position = "absolute"; innerEl.style.top = "0"; innerEl.style.left = "0"; innerEl.style.right = "0"; innerEl.style.bottom = "0"; el.appendChild(innerEl); } }catch(e) { console.warn("Failed set style",e); } //HbMap.prototype.scriptsQue if(hbConfig&&hbConfig.styles&&hbConfig.styles.length>0) { var headNode = document.getElementsByTagName("head")[0]; var refNode = headNode.childNodes[0]; for(var i=0;i0) { HbMap.prototype.scriptsQue = hbConfig.scripts; } var self = this; var load = function(){ //schedule next loading of script var config = HbMap.prototype.scriptsQue.shift(); if(config!=null) { self.loadScript(config,load); }else { HbMap.prototype.scriptsLoaded = true; self.loadScripts(); } }; load(); } HbMap.prototype.scriptsAdded = true; if(HbMap.prototype.scriptsLoaded) { //scripts are loaded, call waiting que var item; while(item=HbMap.prototype.callbackque.shift()) { item.callback.call(item.context); } callback&&callback.call&&callback.call(context); } else { //add all requests to que callback&&callback.call&&HbMap.prototype.callbackque.push({ callback:callback, context:context }); } }; HbMap.prototype.loadScript = function(config,onReady){ if(typeof dojo == "undefined") { var script = document.createElement("script"); script.src = config.script; script.type="text/javascript"; document.body.appendChild(script); var checkInterval = setInterval(function(){ if(typeof dojo != "undefined") { clearInterval(checkInterval); onReady(); } },10); }else { dojo.io.script.get({ url:config.script, checkString:config.checkString, error:HbMap.prototype.loadScriptError, load:dojo.hitch(this,onReady) }); } }; HbMap.prototype.loadScriptError = function(e){ alert("Klaida užkraunant žemÄ—lapį"); }; HbMap.prototype.loaded = false; /** * first called by extjs later by dojo */ HbMap.prototype.initScripts = function(){ //console.log("Loaded libs "+HbMap.prototype.loadCounter, arguments); if( typeof dojo=="undefined" || typeof Ext == "undefined" || typeof Ext.DomHelper == "undefined" || !dojo.byId(dojo.body())){ var self=this; return setTimeout(function(){self.initScripts();},10); } if(!Ext.isReady) { Ext.isReady = true;//Ext is loaded, so forcing isReady variable //console.log("Ext is not ready. Waiting for load."); return Ext.onReady(HbMap.prototype.initScripts); } //console.log("HB map libraries loaded"); HbMap.prototype.loaded = true; HbMap.prototype.loadScripts(); }; /** * called when dojo is ready for configuration laod * * @param callback - function to call after config is loaded * @param context - function's context */ HbMap.prototype.loadConfig = function(callback, context){ if(!this.configDfr) { var content = { config:"public" }; if(this.params) { if(this.params.config) { content.config = this.params.config; }else if(this.params.configuration) { content.config = this.params.configuration; } if(this.params.sessionId) { content.sessionId = this.params.sessionId; } } HbMap.prototype.configDfr = dojo.io.script.get({ url: hbConfig.appUrl+"Scripts/Config.aspx", content:content, callbackParamName: "callback", load: dojo.hitch(this, function(config){ this.config = config||{}; egov.problemStatuses = config.problemStatuses; return config; }), error:esri.config.defaults.io.errorHandler }); } this.configDfr.then(function(config){ if(context) { callback = dojo.hitch(context,callback); } callback(config); }); }; HbMap.prototype._createWindow = function(){ if (!this.window) { if (this.params.target) { var box = dojo.contentBox(this.params.target); this.window = new Ext.Panel({ cls: 'hb', renderTo: this.params.target, layout: "fit", width: box.w, height: box.h, tbar: [], listeners: { afterrender: { buffer: 1, //load map after 1 ms to avoid loop scope: this, fn: this._createMap } }, show: function () { }, hide: function () { } }); } else { this.window = new Ext.Window({ cls: 'hb hbMapWindow', closable: false, closeAction: 'hide', draggable: false, modal: true, maximized: true, autoScroll: false, headerCfg: { style: "display:none;" }, bodyCfg: { style: "position:relative;background-color:#f7f6f3;" }, listeners: { afterrender: { buffer: 1, //load map after 1 ms to avoid loop scope: this, fn: this._createMap }, beforeshow: function () { try { dojo.body() && dojo.addClass(dojo.body(), "x-window-maximized-ct"); window.scroll(0, 0); } catch (e) { console.warn("Failed add class to body or scroll to top", e); } }, hide: function () { try { dojo.body() && dojo.removeClass(dojo.body(), "x-window-maximized-ct"); } catch (e) { console.warn("Failed remove class from body", e); } } }, tbar: { height: 35 } }); this.window.show(); } } }; HbMap.prototype._createMap = function () { if (!this.map) { var config = this.config; //create dom node for map and add it to DOM tree var mapNode = dojo.create("div", { id: this.window.id + "-map" }); dojo.place(mapNode, this.window.body ? this.window.body.dom : this.window.dom); // configure map layers if (this.params.mapType) { var layerOptions = this.params.layerOptions = this.params.layerOptions || {}; dojo.forEach(config.layerDefs, function (def) { if (def.mapTypes) { var opt = layerOptions[def.id] = layerOptions[def.id] || {}; opt.enabled = dojo.indexOf(def.mapTypes, this.params.mapType) != -1; } }, this); } if (this.params.layerOptions) { for (id in this.params.layerOptions) { var options = this.params.layerOptions[id]; if (options.enabled === false) config.layerDefs = dojo.filter(config.layerDefs, function (d) { return d.id !== id; }); else { var def = dojo.filter(config.layerDefs, function (d) { return d.id === id; }); if (!def || !def.length) continue; def = def[0]; if (options.visible != null) def.visible = options.visible; if (options.tooltipUrl && def.options && def.options.infoTemplate) { def.options.infoTemplate.title = egov.getInfoWindowTitleFn(options.tooltipUrl); def.options.infoTemplate.content = egov.getInfoWindowContentFn(options.tooltipUrl); } else if (options.toolltipUrl === null) { def.options.infoTemplate = null; } } } } //configure map tools for (var i = 0; i < config.toolDefs.length; i++) { var tooldef = config.toolDefs[i]; if (tooldef.params && tooldef.params.mapTypes) { if (dojo.indexOf(tooldef.params.mapTypes, this.params.mapType) == -1) { config.toolDefs.splice(i, 1); i--; } } } //create map if (this.params.mapOptions) dojo.mixin(config, this.params.mapOptions); this.map = new hb.ext.Map(dojo.mixin(config, { extMapBox: this.window }), mapNode); this.map.startup(); this.map.addOnLoad(dojo.hitch(this.map.esriMap, "disableKeyboardNavigation")); this.map.addOnLoad(dojo.hitch(this.map.esriMap, "hidePanArrows")); if (this.params && this.params.target) { this.map.addOnLoad(dojo.hitch(dojo, "removeClass", this.params.target, "hbMapLoading")); } // // show operational layers switcher // var switcher = new egov.OperationalLayersSwitcher({ layers: this.map.layers, menuButtonToolTipOptions: this.config.menuButtonToolTipOptions }); if (switcher.layersCount()) switcher.getMenuButton().render(this.map.bgSwitcherNode, 0); // hide tools if needed if (this.params.hideTools) { this.map.toolbar.addOnToolsLoaded(this.hideTools, this); } //console.log("Map created",this.map); this.window.on("show", this.map.show, this.map); this.window.on("hide", this.map.hide, this.map); //call listener for map this.mapDfr.callback(this.map); } }; /** * @param callback(map) a function which returns map to callback */ HbMap.prototype.getMap = function (callback, context) { if (this.mapDfr) { if (callback){ if (context) callback = dojo.hitch(context, callback); this.mapDfr.then(callback); } } else { //jei neturime dar žemÄ—lapio, tai užkrauname script'us this.loadScripts(function () { this.loadConfig(function (config) { egov.config = config; dojo.addOnLoad(this, function () { if (!this.mapDfr){ // previous calls might have already created deferred and window this.mapDfr = new dojo.Deferred(); this._createWindow(); } // now we have mapDfr - register callback with map deferred this.getMap(callback, context); }); }, this); }, this); } }; /* * hide tools */ HbMap.prototype.hideTools = function () { dojo.forEach(this.params.hideTools, dojo.hitch(this, function (toolId) { this.map.toolbar.setToolVisibility(toolId, false); })); }; /** * @param callback(list) a function which returns problems list widget to callback */ HbMap.prototype.getProblemsList = function(callback,context){ if (this.problemsList) { callback && callback.call && callback.call(context,this.problemsList); } else { //jei neturime dar žemÄ—lapio, tai užkrauname script'us this.loadScripts(function(){ this.loadConfig(function(config){ dojo.addOnLoad(this, function(){ if (!this.problemsList){ this.problemsList = new egov.problems.List(dojo.mixin({ hbMap: this, config: config }, this.params.listOptions), this.params.target); this.problemsList.startup(); } this.getProblemsList(callback, context); }); }, this); }, this); } }; /** * @param params - object with parameters: * * @return */ HbMap.prototype.editCoordinates = function(params){ this.getMap(function(map){ new egov.tasks.SelectPointTask(dojo.mixin(params,{ map:map })).startup(); }, this); }; /** * @param params - object with parameters: * * @return */ HbMap.prototype.selectRectangle = function (params) { this.getMap(function (map) { new egov.tasks.SelectRectangleTask(dojo.mixin(params, { map: map })).startup(); }, this); }; /** * @param params - object with parameters: * * @return */ HbMap.prototype.drawObject = function (params) { this.getMap(function (map) { new egov.tasks.DrawObjectTask(dojo.mixin(params, { map: map, blankImage: this.map.blankImage })).startup(); }, this); }; /** * @param params - object with parameters: * * @return */ HbMap.prototype.showObject = function (params) { params.ids = [params.id]; this.getMap(function (map) { var task = new egov.tasks.ShowObjectsTask(dojo.mixin(params, { map: map, blankImage: this.map.blankImage })); task.startup(); task.showObjects(params.ids); }, this); }; /** * @param params - object with parameters: * * @return */ HbMap.prototype.showObjects = function (params) { this.getMap(function (map) { var task = new egov.tasks.ShowObjectsTask(dojo.mixin(params, { map: map, blankImage: this.map.blankImage })); task.startup(); task.showObjects(params.ids); }, this); }; /** * @param params - object with parameters: * * @return */ HbMap.prototype.showObjectInfo = function (params) { params.pointZoomLevel = 8; this.getMap(function (map) { var task = new egov.tasks.ShowObjectsTask(dojo.mixin(params, { map: map, blankImage: this.map.blankImage })); task.startup(); task.showInfo(params.id, params.info, params.showGraphic); }, this); }; /** * @param params - object with parameters: * * @return */ HbMap.prototype.selectProblem = function(params){ this.getMap(function(map){ new egov.tasks.SelectProblemTask(dojo.mixin(params,{ map:map })).startup(); }, this); }; /** * @param params - object with parameters: * * @return */ HbMap.prototype.showInformation = function(params){ this.getMap(function(map){ new egov.tasks.ShowProblemTask(dojo.mixin(params,{ map:map })).startup(); }, this); }; /** * @param params - object with parameters: * * @return */ HbMap.prototype.registerProblem = function(params){ var loginUrl = this.params.loginUrl; var ownForm = this.params.ownForm; var requireLogin = this.params.requireLogin; this.getMap(function(map){ new egov.tasks.RegisterProblemTask(dojo.mixin(params,{ map:map, loginUrl: loginUrl, requireLogin: requireLogin, ownForm: ownForm })).startup(); }, this); }; /** * @return */ HbMap.prototype.showStatistics = function(){ this.getMap(function(map){ map.toolbar.getTool("egov.stats.StatsForSelectionTask", function(t){ t.activate(); }); }, this); }; /** * @return */ HbMap.prototype.updateSize = function(){ this.getMap(function(map){ var win = this.window; if (this._resizeTimeout) clearTimeout(this._resizeTimeout); this._resizeTimeout = setTimeout(function(){ var box = dojo.contentBox(win.container.dom); var winBox = win.getBox(); if (winBox.width != box.w || winBox.height != box.h){ if (dojo.isIE <= 8){ var connect = dojo.connect(map.esriMap, "onResize", function(){ dojo.disconnect(connect); setTimeout(function(){ dojo.forEach(map.esriMap.graphicsLayerIds, function(id){ var layer = map.esriMap.getLayer(id); if (layer.visible){ layer.hide(); layer.show(); } }); var gfx = map.esriMap.graphics.graphics.slice(); map.esriMap.graphics.clear(); dojo.forEach(gfx, function(g){ map.esriMap.graphics.add(g); }); }); }); } win.setSize(box.w, box.h); } }, 100); }, this); };