Javascript class definition for geographic encapsulation Based on Arcgis Server

Source: Internet
Author: User

Zookeeper

Javascript class definition for geographic encapsulation Based on Arcgis Server

MapCwgisAOClass. js

// Web map encapsulation class // MapCwgisAOClass class definition // vp: hsg // create date: 2013-09-10 // The Library dojo needs to be loaded when calling the page. require ("esri. map "); // class prototype defines var MapCwgisAOClass = function () {// Environment Parameter this. map = null; this. layerList = []; this. layers_visible = [];} MapCwgisAOClass. prototype = {// property ProxyHost: null, wms_url: null, map_divid: null, map_toc_divid: null, map: null, LayerList: null, // navToolbar: null, navDraw: null, // m_Curren, the currently executing tool TTool: null, // map initialization method init: function () {this. map = new esri. map (this. map_divid, {logo: false, maxScale: 500, minScale: 5000000}); map = this. map; // assign mapWrap = this to the global variable map; // assign a value to the global variable // load the layer var ms_url = this. wms_url; this. layerList = new esri. layers. arcGISDynamicMapServiceLayer (ms_url); dojo. connect (this. layerList, "onLoad", this. event_loadLayerList); // Add the event this. map. addLayer (this. layerLi St); // var china_ms_url = "http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaCities_Community_BaseMap_CHN/BeiJing_Community_BaseMap_CHN/MapServer"; // this. layerList = new esri. layers. arcGISTiledMapServiceLayer (china_ms_url); // dojo. connect (this. layerList, "onLoad", this. event_loadLayerList); // Add events // this. map. addLayer (this. layerList); // dojo. connect (this. map, "onLoad", this. event_onLoad ); This. map. infoWindow. resize (500,300); // dojo. connect (this. map, "onMouseMove", event_showCoordinates); // register the event. Note that the event name is case-sensitive. connect (this. map, "onClick", this. event_identify); // initialize the navigation toolbar this. navToolbar = new esri. toolbars. navigation (this. map); dojo. connect (this. navToolbar, "onExtentHistoryChange", this. event_extentHistoryChangeHandler); // initialize the toolbar this. navDraw = new esri. toolbars. draw (this. map ); Dojo. connect (this. navDraw, "onDrawEnd", this. event_draw); // sets the proxy esri. config. defaults. io. proxyUrl = this. proxyHost; // "ProxyPage/proxy. aspx "; esri. config. defaults. map. sliderLabel = false; esri. config. defaults. map. slider = {right: "10px", top: "10px", width: "20px", height: "100px"}; // window. alert (this. map. spatialReference); // map = this. map; // assign mapWrap = this to the global variable map; // assign a value to the global variable }, // Used to record the display layer id. Use Layers_visible: null, // load the map name to the list on the right. Only event_loadLayerList objects such as map and mapWrap can be called: function (layers) {var html = ""; // obtain the layer information var infos = layers. layerInfos; for (var I = 0; I <infos. length; I ++) {var info = infos [I]; // Add the layer id to visible if (info. defaultVisibility) {mapWrap. layers_visible.push (info. id);} // html = html + "<div> <input id = '" + info. id + "'Nam E = 'layerlist' class = 'listcss 'Type = 'checkbox' value = 'checkbox' onclick = 'setlayervisibility () '"+ (info. defaultVisibility? "Checked": "") + "/>" + info. name + "</div>"} // sets the visual layer mapWrap. layerList. setVisibleLayers (mapWrap. layers_visible); // display the dojo layer name list on the right. byId (mapWrap. map_toc_divid ). innerHTML = html;}, // sets whether the layer is visible. setLayerVisibility: function () {// use dojo. query gets the array of elements whose css is listCss var inputs = dojo. query (". listCss "); mapWrap. layers_visible = []; // variable the checkbox array to add the selected id to visible for (var I = 0; I <inputs. length; I ++) {If (inputs [I]. checked) {mapWrap. layers_visible.push (inputs [I]. id) ;}} // sets the visual layer mapWrap. layerList. setVisibleLayers (mapWrap. layers_visible);}, event_onLoad: function () {/* map. infoWindow. resize (500,300); // dojo. connect (map, "onMouseMove", event_showCoordinates); // registers events. Note that the event name is case sensitive. connect (map, "onClick", this. event_identify); // initialize the navigation toolbar mapWrap. navToolbar = new esri. toolbars. naviga Tion (map); dojo. connect (mapWrap. navToolbar, "onExtentHistoryChange", this. event_extentHistoryChangeHandler); // initialize the toolbar mapWrap. navDraw = new esri. toolbars. draw (map); dojo. connect (mapWrap. navDraw, "onDrawEnd", this. event_draw); // sets the proxy // esriConfig. defaults. io. proxyUrl = "ProxyPage/proxy. aspx "; esriConfig. defaults. map. sliderLabel = false; esriConfig. defaults. map. slider = {right: "10px", top: "1 0px ", width:" 20px ", height:" 100px "}; // window. alert (map. spatialReference); // */}, event_draw: function (geometry) {var symbol; var graphic = null; switch (geometry. type) {case "point": {var m_outline = new esri. symbol. simpleLineSymbol (esri. symbol. simpleLineSymbol. STYLE_SOLID, new dojo. color ([255, 0, 0]), 1) symbol = new esri. symbol. simpleMarkerSymbol (esri. symbol. simpleMarkerSymbol. STYLE _ CIRCLE, 10, m_outline, new dojo. color ([0,255, 0, 0.25]); graphic = new esri. graphic (geometry, symbol);} case "polyline": {symbol = new esri. symbol. simpleLineSymbol (esri. symbol. simpleLineSymbol. STYLE_DASH, new dojo. color ([255, 0, 0]), 1); // window. alert ("line"); graphic = new esri. graphic (geometry, symbol); break;} case "polygon": {symbol = new esri. symbol. simpleFillSymbol (esri. symbol. simpleF IllSymbol. STYLE_NONE, new esri. symbol. simpleLineSymbol (esri. symbol. simpleLineSymbol. STYLE_DASHDOT, new dojo. color ([255, 0, 0]), 2), new dojo. color ([255,255, 0, 0.25]); graphic = new esri. graphic (geometry, symbol); break;} case "FREEHAND_POLYLINE": {break;} default: {liangsuan_type = null; break ;}} // call the self-written algorithm to calculate the distance // cal_Distance (); // geometryService. project ([graphic], new esri. spatialReferen Ce ({"wkid": 4326}); // 4326 32618 // geometryService. lengths (graphic); map. graphics. add (graphic) ;}, event_identify: function (evt) {var mp = evt. mapPoint; var screenPt = map. toScreen (mp); var str = "screen coordinates (x, y) :(" + screenPt. x + "," + screenPt. y + ") map coordinates (x, y) :(" + mp. x + "," + mp. y + ")"; // map. infoWindow. setTitle ("Identify"); map. infoWindow. setContent (str); map. infoWindow. show (evt. screenPoint, Map. getinfow.wanchor (evt. screenPoint);}, event_extentHistoryChangeHandler: function () {// dijit. byId ("zoomprev "). disabled = navToolbar. isFirstExtent (); // dijit. byId ("zoomnext "). disabled = navToolbar. isLastExtent () ;}, // hide the Coordinate Position prompt box hide_infoWindow: function () {if (this. map. infoWindow = null) return; if (this. map. infoWindow. isShowing) {this. map. infoWindow. hide () ;}}, // clear screen function js_map_clear: f Unction () {if (this. map. graphics! = Null) {this. map. graphics. clear ();} this. hide_infoWindow () ;}, // getCurrentTool: function () {return this. m_CurrentTool;}, setCurrentTool: function (p_tool) {if (this. m_CurrentTool! = Null) {try {this. m_CurrentTool.deactivate ();} catch (e) {}} this. m_CurrentTool = p_tool; try {this. m_CurrentTool.activate ();} catch (e) {}}, // method CLASS_NAME: "MapCwgisAOClass "}; // set global variables and initialize map controls // ================================ ==================================================/// define the global variable var map = null; var mapWrap = null; // PAGE map loading // assign mapWrap = new MapCwgisAOClass () to the global variable; mapWrap. wms_url = wms_url; mapWrap. map_divid = "map"; mapWrap. map_toc_divid = "toc"; mapWrap. proxyHost = 'proxy. ashx'; // function g_init () {mapWrap. init ();} dojo. addOnLoad (g_init ); // ================================================ ======================================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.