MapClass420.js 141 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533
  1. var m_map;
  2. var m_view;
  3. var m_sceneLayer;
  4. var m_zoom;
  5. var dyLayer;
  6. var m_drawtool;
  7. var m_printTool;
  8. var queryExtent;
  9. var xmlQueryExtend;
  10. var layerList;
  11. var symble = [];
  12. var initExtent;
  13. var FullExtent;
  14. var geometryService;
  15. var GraphicsLayer_labelLayer;
  16. var GraphicsLayer_myLayer;
  17. var GraphicsLayer_areaNameLayer;
  18. var GraphicsLayer_identityLayer;
  19. var GraphicsLayer_extendLayer;
  20. var GraphicsLayer_fickerLayer;
  21. var GraphicsLayer_DrawLayer;
  22. var GraphicsLayer_flyTipLayer;
  23. var lengthMeasureWidget;
  24. var groundColor = [0, 0, 0];
  25. var currentMapMode;
  26. var currentExtent;
  27. var currentScale;
  28. var highlightSelect;
  29. var highlightSelectExtra;
  30. //2020 2 hm
  31. var m_mapClickdraw = false;
  32. var m_mapAttribute = '{ "ID": "1","名称": "测试点1" }';
  33. var m_mapToolTip = '测试点1';
  34. var m_mapImgUrl = 'https://static.arcgis.com/images/Symbols/Shapes/BlackStarLargeB.png';
  35. var m_mapImgWidth = '32px';
  36. var m_mapImgHeight = '32px';
  37. var m_mapAddress;
  38. var m_maphitPoint;
  39. var m_resizetime = null;
  40. var isInLightArea = "";//判断区域高亮移出移入
  41. var isInDrawLayer = "";//判断DrawLayer移出移入
  42. var spatialReferenceJson = {
  43. wkt: 'PROJCS["shanghaicity_chy",GEOGCS["GCS_Beijing_1954",DATUM["D_Beijing_1954",SPHEROID["Krasovsky_1940",6378245.0,298.3]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",-3457147.81],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",121.2751921],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]'
  44. };
  45. var isMapLoaded = false;
  46. var fe0;
  47. var fe1;
  48. var fe2;
  49. var fe3;
  50. var fe4;
  51. var fe5;
  52. var fe6;
  53. var fe7;
  54. var fe8;
  55. var fe9;
  56. var fe10;
  57. function init3DScene() {
  58. currentMapMode = "3D";
  59. require(["esri/Map", "esri/Graphic", "esri/geometry/Extent", "esri/geometry/Polygon", "esri/geometry/Point", "esri/views/MapView", "esri/views/SceneView", "esri/layers/MapImageLayer", "esri/layers/TileLayer", "esri/layers/VectorTileLayer", "esri/layers/GraphicsLayer", "esri/tasks/GeometryService", "esri/portal/Portal", "esri/WebScene", "esri/widgets/LayerList", "esri/config", "esri/widgets/ScaleBar", "esri/layers/FeatureLayer", "esri/layers/SceneLayer", "esri/layers/support/LabelClass", "esri/widgets/NavigationToggle", "esri/widgets/Zoom", "esri/widgets/Compass", "esri/Color", "esri/core/watchUtils", "esri/symbols/TextSymbol", "esri/Camera"],
  60. function (Map, Graphic, Extent, Polygon, Point, MapView, SceneView, MapImageLayer, TileLayer, VectorTileLayer, GraphicsLayer, GeometryService, Portal, WebScene, LayerList, esriConfig, ScaleBar, FeatureLayer, SceneLayer, LabelClass, NavigationToggle, Zoom, Compass, Color, watchUtils, TextSymbol, Camera) {
  61. esriConfig.request.corsEnabledServers.push("http://10.101.35.50");
  62. m_map = new Map({
  63. ground: {
  64. surfaceColor: groundColor
  65. }
  66. });
  67. dyAddMapLayerByConfig();
  68. AddMapGraphicLayers();
  69. m_view = new SceneView({
  70. container: "mapDiv",
  71. constraints: {
  72. collision: {
  73. enabled: false
  74. },
  75. tilt: {
  76. max: 179.99,
  77. min: 0
  78. }
  79. },
  80. map: m_map,
  81. viewingMode: "local",
  82. alphaCompositingEnabled: true,
  83. environment: {
  84. background: {
  85. type: "color",
  86. color: [0, 0, 0, 1]
  87. },
  88. starsEnabled: false,
  89. atmosphereEnabled: false
  90. },
  91. ui: {
  92. components: ["attribution"]
  93. }
  94. });
  95. AddSceneViewWidget();
  96. m_view.when(function () {
  97. var centerPoint = new Point({
  98. //x: 43184,
  99. //y: -37270,
  100. x:0,
  101. y:0,
  102. z: 258000,
  103. spatialReference: m_view.spatialReference
  104. });
  105. setCameraBypoint(0, centerPoint, 0, 0, currentScale);
  106. var displaynoneDiv1 = document.getElementsByClassName("esri-attribution__powered-by");
  107. for (var i = 0; i < displaynoneDiv1.length; i++) {
  108. displaynoneDiv1[i].style.display = "none"
  109. }
  110. var displaynoneDiv2 = document.getElementsByClassName("esri-widget-button");
  111. for (var i = 0; i < displaynoneDiv2.length; i++) {
  112. displaynoneDiv2[i].style.display = "none"
  113. }
  114. m_view.watch("camera", updateIndicator);
  115. watchUtils.when(m_view, "animation", watchAnimation);
  116. /*m_zoom = new Zoom({
  117. view: m_view
  118. });
  119. m_view.ui.add(m_zoom, {
  120. position: "top-right"
  121. });
  122. var m_navigateToggle = new NavigationToggle({
  123. view: m_view
  124. });
  125. m_view.ui.add(m_navigateToggle, {
  126. position: "top-right"
  127. });
  128. var m_compass = new Compass({
  129. view: m_view
  130. });
  131. m_view.ui.add(m_compass, {
  132. position: "top-right"
  133. });*/
  134. m_view.ui.remove('zoom');
  135. //m_view.ui.add("info", "top-right");
  136. if (currentExtent != null) {
  137. m_view.extent = currentExtent;
  138. setCameraBypoint(1, currentExtent.center, 0, 0, currentScale)
  139. }
  140. setTimeout("onMapLoadInfo()",1000);
  141. });
  142. m_view.on("pointer-move", function (event) {
  143. m_view.hitTest(event, GraphicsLayer).then(getGraphics);
  144. function getGraphics(response) {
  145. if (response.results.length) {
  146. var result = response.results[0];
  147. if (result.graphic) {
  148. m_view.whenLayerView(result.graphic.layer).then(function (layerView) {
  149. /*if (highlightSelect) {
  150. highlightSelect.remove();
  151. }
  152. try{
  153. highlightSelect = layerView.highlight(result.graphic);
  154. }catch (e){ }*/
  155. if (result.graphic.attributes && result.graphic.layer.id == "myGLayer") {
  156. if (isInDrawLayer != "") {
  157. postToParentPageMethed("moveOutDrawLayerReturn", [isInDrawLayer]);
  158. isInDrawLayer = "";
  159. }
  160. if (isInLightArea == "") {
  161. isInLightArea = result.graphic.attributes;
  162. postToParentPageMethed("moveInLightAreaReturn", [isInLightArea]);
  163. } else {
  164. if (isInLightArea.OBJECTID != result.graphic.attributes.OBJECTID) {
  165. postToParentPageMethed("moveOutLightAreaReturn", [isInLightArea]);
  166. isInLightArea = result.graphic.attributes;
  167. postToParentPageMethed("moveInLightAreaReturn", [isInLightArea]);
  168. }
  169. }
  170. } else if (result.graphic.attributes && result.graphic.layer.id == "myDrawGLayer") {
  171. if (isInDrawLayer == "") {
  172. isInDrawLayer = result.graphic.attributes;
  173. postToParentPageMethed("moveInDrawLayerReturn", [isInDrawLayer]);
  174. } else {
  175. if (isInDrawLayer != result.graphic.attributes) {
  176. postToParentPageMethed("moveOutDrawLayerReturn", [isInDrawLayer]);
  177. isInDrawLayer = result.graphic.attributes;
  178. postToParentPageMethed("moveInDrawLayerReturn", [isInDrawLayer]);
  179. }
  180. }
  181. } else {
  182. if (isInLightArea != "") {
  183. postToParentPageMethed("moveOutLightAreaReturn", [isInLightArea]);
  184. isInLightArea = "";
  185. }
  186. if (isInDrawLayer != "") {
  187. postToParentPageMethed("moveOutDrawLayerReturn", [isInDrawLayer]);
  188. isInDrawLayer = "";
  189. }
  190. }
  191. });
  192. }
  193. } else {
  194. // if(highlightSelect){
  195. // highlightSelect.remove();
  196. // }
  197. if (isInLightArea != "") {
  198. postToParentPageMethed("moveOutLightAreaReturn", [isInLightArea]);
  199. isInLightArea = "";
  200. }
  201. if (isInDrawLayer != "") {
  202. postToParentPageMethed("moveOutDrawLayerReturn", [isInDrawLayer]);
  203. isInDrawLayer = "";
  204. }
  205. }
  206. }
  207. });
  208. m_view.on("click", function (event) {
  209. popupCloseAll("viewClick");
  210. m_view.hitTest(event).then(function (response) {
  211. if (response.results.length) {
  212. var result = response.results[0];
  213. if (result.graphic) {
  214. m_view.whenLayerView(result.graphic.layer).then(function (layerView) {
  215. if (highlightSelect) {
  216. try{
  217. highlightSelect.remove();
  218. }catch (e){ }
  219. }
  220. try{
  221. highlightSelect = layerView.highlight(result.graphic);
  222. }catch (e){ }
  223. })
  224. switch (result.graphic.layer.id) {
  225. case "WZXYFeature":{
  226. var jsonStr=result.graphic.attributes;
  227. jsonStr.x=result.graphic.geometry.extent.center.x;
  228. jsonStr.y=result.graphic.geometry.extent.center.y;
  229. postToParentPageMethed("clickWZXYFeatureReturn", [jsonStr]);
  230. break;
  231. }
  232. case "水箱": {
  233. queryWaterTank(result.graphic.attributes.OBJECTID);
  234. break;
  235. }
  236. case "myDrawGLayer":
  237. var returnList = []
  238. var graphicList = GraphicsLayer_DrawLayer.graphics.items;
  239. for (var i = 0; i < graphicList.length; i++) {
  240. if (result.graphic.geometry.x == graphicList[i].geometry.x && result.graphic.geometry.y == graphicList[i].geometry.y) {
  241. if (graphicList[i].attributes) {
  242. returnList.push(graphicList[i].attributes);
  243. }
  244. }
  245. }
  246. postToParentPageMethed("clickDrawLayerReturn", [returnList]);
  247. break;
  248. case "myGLayer":
  249. {
  250. // m_view.goTo(result.graphic)
  251. postToParentPageMethed("clickLightAreaReturn", [result.graphic.attributes]);
  252. break;
  253. }
  254. default:
  255. {
  256. if (result.graphic.layer.declaredClass == "esri.layers.FeatureLayer") {
  257. var queryTask = new QueryTask({
  258. url: GetConfigDataByName("QueryLayer") + "/250"
  259. });
  260. var query = new Query();
  261. query.geometry = null;
  262. query.outFields = ["*"];
  263. query.returnGeometry = true;
  264. //query.geometry = option.geometry || null;
  265. query.spatialRelationship = "intersects";
  266. query.where = "1=1";
  267. query.geometry = result.graphic.geometry;
  268. queryTask.execute(query).then(function (results1) {
  269. if (results1.features.length > 0) {
  270. }
  271. // window.parent.postMessage(
  272. // {
  273. // method: "mapOnclickCallback",
  274. // data:[JSON.stringify(result.graphic.attributes).replace(/\"/g,'"'),
  275. // JSON.stringify(results1.features[0].attributes["网格编码"]).replace(/\"/g,'"')
  276. // ]
  277. // },
  278. // '*'
  279. // );
  280. else {
  281. // window.parent.postMessage(
  282. // {
  283. // method: "mapOnclickCallback",
  284. // data:[JSON.stringify(result.graphic.attributes).replace(/\"/g,'"'),'']
  285. // },
  286. // '*'
  287. // );
  288. }
  289. });
  290. }
  291. break;
  292. }
  293. }
  294. }
  295. }
  296. });
  297. });
  298. function setContentInfo(center, scale, floorNumber) {
  299. var popupDiv = document.createElement("div");
  300. popupDiv.setAttribute("style", "height: 400px;width:600px;border: 1px solid #A8A8A8;");
  301. var layerFloor = new MapImageLayer({
  302. url: "http://120.55.160.15:6080/arcgis/rest/services/HKLZM/MapServer",
  303. id: "楼层"
  304. });
  305. var popupView = new MapView({
  306. container: popupDiv,
  307. map: new Map({
  308. layers: [layerFloor]
  309. }),
  310. center: new Point({
  311. x: 589.976,
  312. y: 4146.679
  313. }),
  314. constraints: {
  315. rotationEnabled: false
  316. },
  317. ui: {
  318. components: []
  319. }
  320. });
  321. popupView.when(function () {
  322. popupView.extent = new Extent({
  323. xmin: 480,
  324. ymin: 4050,
  325. xmax: 680,
  326. ymax: 4250,
  327. spatialReference: popupView.spatialReference
  328. });
  329. if (floorNumber) {
  330. if (floorNumber.length > 0) {
  331. var number = parseInt(floorNumber.substr(0, floorNumber.length - 1));
  332. if (number > 7) {
  333. number = Math.ceil(number / 2)
  334. }
  335. openLayer(popupView.map, "F" + number)
  336. }
  337. }
  338. });
  339. return popupView.container
  340. }
  341. function openLayer(openMap, layerName) {
  342. var layers = openMap.layers.items[0].allSublayers;
  343. if (layers.length > 0) {
  344. for (var i = 0; i < layers.length; i++) {
  345. var layer = layers.items[i];
  346. if (layer.title == layerName) {
  347. layer.visible = true;
  348. if (layer.sublayers) {
  349. for (var j = 0; j < layer.sublayers.length; j++) {
  350. layer.sublayers.items[j].visible = true
  351. }
  352. }
  353. } else {
  354. if (layer.sublayers) {
  355. layer.visible = false
  356. }
  357. }
  358. }
  359. }
  360. }
  361. function updateIndicator(camera) {
  362. }
  363. function watchAnimation(animation) {
  364. console.log("animation.state:", animation.state);
  365. animation.when(function (animation) {
  366. console.log("animation:", animation)
  367. }).catch(function (animation) {
  368. console.log(animation.state)
  369. })
  370. }
  371. function watchCircle(pointX, pointY, pointZ, headingValue, tiltValue) {
  372. require(["esri/Camera", "esri/geometry/Point"],
  373. function (Camera, Point) {
  374. currentCircle = 0;
  375. var pt = new Point({
  376. x: pointX,
  377. y: pointY,
  378. z: pointZ,
  379. spatialReference: m_view.spatialReference
  380. });
  381. var cam = new Camera({
  382. heading: headingValue,
  383. tilt: tiltValue,
  384. position: pt
  385. });
  386. m_view.camera = cam;
  387. beginCircle(pointX, pointY, pointZ, currentCircle, tiltValue)
  388. })
  389. }
  390. var currentCircle = 0;
  391. isCircle = false;
  392. function beginCircle(pointX, pointY, pointZ, headingValue, tiltValue) {
  393. var duringTime = 1e3;
  394. var R = pointZ * Math.tan(tiltValue * Math.PI / 180);
  395. var viewX = pointX - R * Math.cos((90 - headingValue) * Math.PI / 180);
  396. var viewY = pointY - R * Math.sin((90 - headingValue) * Math.PI / 180);
  397. m_view.goTo({
  398. center: [viewX, viewY, pointZ, m_view.spatialReference],
  399. heading: headingValue,
  400. tilt: tiltValue
  401. },
  402. {
  403. easing: "linear",
  404. duration: duringTime
  405. }).then(function () {
  406. if (isCircle) {
  407. if (currentCircle > 360) {
  408. currentCircle = 0
  409. }
  410. if (currentCircle < 0) {
  411. currentCircle = 360
  412. }
  413. currentCircle -= 1;
  414. console.log(currentCircle);
  415. beginCircle(pointX, pointY, pointZ, currentCircle, tiltValue)
  416. }
  417. })
  418. }
  419. function AddSceneViewWidget() {
  420. // var viewTest = document.getElementById("viewTest");
  421. // m_view.ui.add(viewTest, "bottom-right")
  422. }
  423. function dyAddMapLayerByConfig() {
  424. var serverUrl;
  425. var serverType;
  426. var serverLabel;
  427. var serverVisible;
  428. GetConfigData();
  429. var mapXml = xmlDoc.getElementsByTagName("map");
  430. var mapNodes = mapXml[0].childNodes;
  431. for (var i = 0; i < mapNodes.length; i++) {
  432. var nodeObj = mapNodes[i];
  433. if (nodeObj.nodeType == 1) {
  434. var tagName = xmlUtil.getNodeTagName(nodeObj);
  435. var value = xmlUtil.getNodeValue(nodeObj);
  436. if (tagName == "geometryservice") {
  437. serverType = "geometryservice";
  438. serverUrl = value;
  439. dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible)
  440. } else if (tagName == "fullextent") {
  441. var extentArray = value.split(",");
  442. fullExtent = new Extent(parseFloat(extentArray[0]), parseFloat(extentArray[1]), parseFloat(extentArray[2]), parseFloat(extentArray[3]))
  443. } else {
  444. if (tagName == "basemaps" && currentMapMode == "2D") {
  445. var childNodes = nodeObj.childNodes;
  446. for (var j = 0; j < childNodes.length; j++) {
  447. var childNode = childNodes[j];
  448. if (childNode.nodeType == 1) {
  449. for (var k = 0; k < childNode.attributes.length; k++) {
  450. var attribute = childNode.attributes[k];
  451. var attributeName = attribute.name;
  452. if (attributeName == "label") {
  453. serverLabel = attribute.value
  454. }
  455. if (attributeName == "type") {
  456. serverType = attribute.value
  457. }
  458. if (attributeName == "visible") {
  459. if (attribute.value == "false") serverVisible = false;
  460. else serverVisible = true
  461. }
  462. }
  463. serverUrl = xmlUtil.getNodeValue(childNode);
  464. dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible)
  465. }
  466. }
  467. }
  468. if (tagName == "basemaps3D" && currentMapMode == "3D") {
  469. var childNodes = nodeObj.childNodes;
  470. for (var j = 0; j < childNodes.length; j++) {
  471. var childNode = childNodes[j];
  472. if (childNode.nodeType == 1) {
  473. for (var k = 0; k < childNode.attributes.length; k++) {
  474. var attribute = childNode.attributes[k];
  475. var attributeName = attribute.name;
  476. if (attributeName == "label") {
  477. serverLabel = attribute.value
  478. }
  479. if (attributeName == "type") {
  480. serverType = attribute.value
  481. }
  482. if (attributeName == "visible") {
  483. if (attribute.value == "false") serverVisible = false;
  484. else serverVisible = true
  485. }
  486. }
  487. serverUrl = xmlUtil.getNodeValue(childNode);
  488. dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible)
  489. }
  490. }
  491. }
  492. }
  493. }
  494. }
  495. }
  496. function dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible) {
  497. var layer;
  498. switch (serverType) {
  499. case "geometryservice":
  500. {
  501. geometryService = new GeometryService(serverUrl);
  502. break
  503. }
  504. case "tiled":
  505. {
  506. // if (currentMapMode == "2D") {
  507. layer = new TileLayer({
  508. url: serverUrl,
  509. id: serverLabel
  510. });
  511. layer.visible = serverVisible;
  512. m_map.add(layer)
  513. // }
  514. break
  515. }
  516. case "dynamic":
  517. {
  518. dyLayer = new MapImageLayer({
  519. url: serverUrl,
  520. id: serverLabel
  521. });
  522. dyLayer.visible = serverVisible;
  523. var currentElevationInfo = {
  524. mode: "relative-to-ground",
  525. offset: -1,
  526. unit: "meters"
  527. };
  528. dyLayer.elevationInfo = currentElevationInfo;
  529. m_map.add(dyLayer);
  530. break
  531. }
  532. case "density":
  533. {
  534. dyLayer = new MapImageLayer({
  535. url: serverUrl,
  536. id: serverLabel
  537. });
  538. dyLayer.visible = serverVisible;
  539. m_map.add(dyLayer);
  540. dyLayer.on("layerview-create", function(event){
  541. createWZXYFeature();
  542. });
  543. break;
  544. }
  545. case "featurelayer":
  546. {
  547. m_map.add(layer);
  548. break;
  549. }
  550. case "scene":
  551. {
  552. m_sceneLayer = new SceneLayer({
  553. url: serverUrl,
  554. id: serverLabel,
  555. popupEnabled: false
  556. });
  557. m_sceneLayer.visible=serverVisible;
  558. var color=[120,120,120,0.6];
  559. var color1=[27, 68, 130, 0.6];
  560. if(serverLabel=="水箱"){
  561. color=[15,154,224,0.6];
  562. color1=[27, 68, 130, 0.6];
  563. }
  564. if(serverLabel=="建筑物"){
  565. color=[0,224,247,0.6];
  566. color1=[0,224,247,0.6];
  567. }
  568. var locationRenderer = {
  569. type: "simple",
  570. symbol: {
  571. type: "mesh-3d",
  572. symbolLayers: [{
  573. type: "fill",
  574. material: {
  575. color: color,
  576. colorMixMode: "replace"
  577. },
  578. edges: {
  579. type: "solid",
  580. color: color1,
  581. size: 1.5
  582. }
  583. }]
  584. }
  585. };
  586. m_sceneLayer.renderer = locationRenderer;
  587. m_map.add(m_sceneLayer);
  588. break
  589. }
  590. case "vector":
  591. {
  592. var vlayer = new VectorTileLayer({
  593. url: serverUrl,
  594. id: serverLabel
  595. });
  596. m_map.add(vlayer);
  597. break
  598. }
  599. }
  600. }
  601. function AddMapGraphicLayers() {
  602. GraphicsLayer_labelLayer = new GraphicsLayer;
  603. GraphicsLayer_labelLayer.listMode = "hide";
  604. GraphicsLayer_myLayer = new GraphicsLayer({id: "myGLayer"});
  605. GraphicsLayer_myLayer.listMode = "hide";
  606. GraphicsLayer_areaNameLayer = new GraphicsLayer;
  607. GraphicsLayer_areaNameLayer.listMode = "hide";
  608. GraphicsLayer_identityLayer = new GraphicsLayer;
  609. GraphicsLayer_identityLayer.listMode = "hide";
  610. GraphicsLayer_extendLayer = new GraphicsLayer;
  611. GraphicsLayer_extendLayer.listMode = "hide";
  612. GraphicsLayer_fickerLayer = new GraphicsLayer;
  613. GraphicsLayer_fickerLayer.listMode = "hide";
  614. GraphicsLayer_DrawLayer = new GraphicsLayer({id: "myDrawGLayer"});
  615. GraphicsLayer_DrawLayer.listMode = "hide";
  616. GraphicsLayer_flyTipLayer = new GraphicsLayer;
  617. GraphicsLayer_flyTipLayer.listMode = "hide";
  618. m_map.add(GraphicsLayer_areaNameLayer);
  619. m_map.add(GraphicsLayer_labelLayer);
  620. m_map.add(GraphicsLayer_identityLayer);
  621. m_map.add(GraphicsLayer_extendLayer);
  622. m_map.add(GraphicsLayer_DrawLayer);
  623. m_map.add(GraphicsLayer_myLayer);
  624. m_map.add(GraphicsLayer_flyTipLayer);
  625. m_map.add(GraphicsLayer_fickerLayer)
  626. }
  627. })
  628. }
  629. function GetIFrameInfoWinContent(type, url) {
  630. var str = " <div style='width:600px;height:500px;'><iframe src='" + url + "' width='100%' height='100%' frameborder='0' scrolling='yes'></iframe></div>";
  631. return str
  632. }
  633. function setCamera(isAnimation, pointX, pointY, pointZ, headingValue, tiltValue, scaleValue) {
  634. require(["esri/Camera", "esri/geometry/Point"],
  635. function (Camera, Point) {
  636. var pt = new Point({
  637. x: pointX,
  638. y: pointY,
  639. z: pointZ,
  640. spatialReference: m_view.spatialReference
  641. });
  642. if (isAnimation) {
  643. m_view.goTo({
  644. target: pt,
  645. heading: headingValue,
  646. tilt: tiltValue,
  647. scale: scaleValue
  648. })
  649. } else {
  650. var cam = new Camera({
  651. heading: headingValue,
  652. tilt: tiltValue,
  653. position: pt
  654. });
  655. m_view.camera = cam
  656. }
  657. })
  658. }
  659. function setCameraBypoint(isAnimation, centerPoint, headingValue, tiltValue, scaleValue) {
  660. require(["esri/Camera", "esri/geometry/Point"],
  661. function (Camera, Point) {
  662. var R = centerPoint.z * Math.tan(tiltValue * Math.PI / 180);
  663. var viewX = centerPoint.x - R * Math.cos((90 - headingValue) * Math.PI / 180);
  664. var viewY = centerPoint.y - R * Math.sin((90 - headingValue) * Math.PI / 180);
  665. var viewZ = centerPoint.z;
  666. //console.log("viewX:" + viewX + ",viewY:" + viewY + ",viewZ:" + viewZ);
  667. if (isAnimation) {
  668. m_view.goTo({
  669. center: [viewX, viewY, viewZ, m_view.spatialReference],
  670. heading: headingValue,
  671. tilt: tiltValue
  672. })
  673. } else {
  674. var point = new Point({
  675. x: viewX,
  676. y: viewY,
  677. z: viewZ,
  678. spatialReference: m_view.spatialReference
  679. });
  680. var cam = new Camera({
  681. heading: headingValue,
  682. tilt: tiltValue,
  683. position: point
  684. });
  685. m_view.camera = cam
  686. }
  687. })
  688. }
  689. function switchTo2DMap() {
  690. currentExtent = m_view.extent;
  691. currentScale = m_view.scale;
  692. currentExtent.spatialReference = m_view.spatialReference;
  693. initMap()
  694. }
  695. function switchTo3DMap() {
  696. currentExtent = m_view.extent;
  697. currentScale = m_view.scale;
  698. currentExtent.spatialReference = m_view.spatialReference;
  699. init3DScene()
  700. }
  701. function getLayerByLayerId(layerID) {
  702. for (var i = 0; i < m_map.layers.items.length; i++) {
  703. if (m_map.layers.items[i].id == layerID) {
  704. return m_map.layers.items[i]
  705. }
  706. }
  707. }
  708. function getSubLayerIdbyName(layer, name) {
  709. var items = layer.allSublayers.items;
  710. for (var j = 0; j < items.length; j++) {
  711. var currnetLayer = items[j];
  712. if (currnetLayer.title == name) {
  713. return currnetLayer.id
  714. }
  715. }
  716. return -1
  717. }
  718. function highLightByObjectIDs(objIDArray) {
  719. m_view.whenLayerView(m_sceneLayer).when(function (lyrView) {
  720. if (highlightSelect) {
  721. highlightSelect.remove()
  722. }
  723. highlightSelect = lyrView.highlight(objIDArray)
  724. })
  725. }
  726. function highLightByGeomtry(geometry) {
  727. require(["esri/tasks/support/Query", "esri/tasks/QueryTask", "esri/core/watchUtils", "esri/geometry/Geometry"],
  728. function (Query, QueryTask, watchUtils, Geometry) {
  729. var query = new Query;
  730. query.geometry = geometry.extent;
  731. query.spatialRelationship = "intersects";
  732. query.outFields = ["OBJECTID"];
  733. m_view.whenLayerView(m_sceneLayer).when(function (lyrView) {
  734. if (highlightSelect) {
  735. highlightSelect.remove()
  736. }
  737. var objids = [];
  738. watchUtils.whenNotOnce(lyrView, "updating").when(function () {
  739. lyrView.queryObjectIds(query).when(function (ids) {
  740. console.log(ids);
  741. objids = ids
  742. },
  743. function (error) {
  744. objids = ids
  745. })
  746. });
  747. highlightSelect = lyrView.highlight(objids)
  748. })
  749. })
  750. }
  751. function hitTest(geomtry) {
  752. m_view.hitTest(geomtry).when(function (response) {
  753. var result = response.results[0];
  754. if (result) {
  755. var x = result.mapPoint.x;
  756. var y = result.mapPoint.y;
  757. if (result.graphic) {
  758. m_view.whenLayerView(result.graphic.layer).when(function (lyrView) {
  759. if (highlightSelect) {
  760. highlightSelect.remove()
  761. }
  762. highlightSelect = lyrView.highlight(result.graphic);
  763. m_view.popup.open({
  764. title: "Reverse geocode",
  765. features: result.graphic,
  766. content: "This is a point of interest"
  767. })
  768. })
  769. }
  770. }
  771. })
  772. }
  773. var viewxmax;
  774. var viewxmin;
  775. var viewymax;
  776. var viewymin;
  777. var x;
  778. var y;
  779. function initMap() {
  780. currentMapMode = "2D";
  781. require(["esri/Map", "esri/views/MapView", "esri/layers/MapImageLayer", "esri/layers/TileLayer", "esri/geometry/Geometry", "esri/geometry/Extent",
  782. "esri/tasks/GeometryService", "esri/layers/GraphicsLayer", "esri/layers/FeatureLayer", "esri/widgets/ScaleBar",
  783. "esri/WebMap", "esri/geometry/SpatialReference", "esri/Graphic", "esri/views/2d/draw/Draw",
  784. "esri/geometry/Polygon", "esri/widgets/Zoom", "esri/widgets/Compass", "esri/widgets/LayerList",
  785. "esri/geometry/geometryEngine", "esri/tasks/QueryTask", "esri/tasks/support/Query",
  786. "esri/geometry/Point", "esri/core/watchUtils", "esri/config", "dojo/on"],
  787. function (Map, MapView, MapImageLayer, TileLayer, Geometry, Extent, GeometryService,
  788. GraphicsLayer, FeatureLayer, ScaleBar, WebMap, SpatialReference, Graphic, Draw, Polygon,
  789. Zoom, Compass, LayerList, geometryEngine, QueryTask, Query, Point, watchUtils, esriConfig, on) {
  790. esriConfig.fontsUrl = "http://10.101.35.50/fonts";
  791. m_map = new Map({
  792. logo: false,
  793. slider: false
  794. });
  795. dyAddMapLayerByConfig();
  796. // AddMapGraphicLayers();放到动态图层加载前
  797. viewxmax = xmlDoc.getElementsByTagName("viewxmax")[0].innerHTML;
  798. viewxmin = xmlDoc.getElementsByTagName("viewxmin")[0].innerHTML;
  799. viewymax = xmlDoc.getElementsByTagName("viewymax")[0].innerHTML;
  800. viewymin = xmlDoc.getElementsByTagName("viewymin")[0].innerHTML;
  801. m_view = new MapView({
  802. container: "mapDiv",
  803. map: m_map,
  804. popup: {
  805. dockEnabled: false,
  806. dockOptions: {
  807. position: "top-right",
  808. breakpoint: false
  809. }
  810. }
  811. });
  812. m_view.constraints = {
  813. rotationEnabled: false // Disables map rotation
  814. };
  815. m_zoom = new Zoom({
  816. view: m_view
  817. });
  818. // m_view.ui.add(m_zoom, {
  819. // position: "top-right"
  820. // });
  821. layerList = new LayerList({
  822. view: m_view
  823. });
  824. AddSceneViewWidget();
  825. m_view.when(function (evt) {
  826. //createInfoDiv();
  827. // m_view.ui.add("info", "top-right");
  828. //doToolTip();
  829. var displaynoneDiv1 = document.getElementsByClassName("esri-attribution__powered-by");
  830. for (var i = 0; i < displaynoneDiv1.length; i++) {
  831. displaynoneDiv1[i].style.display = "none"
  832. }
  833. var displaynoneDiv2 = document.getElementsByClassName("esri-widget-button");
  834. for (var i = 0; i < displaynoneDiv2.length; i++) {
  835. displaynoneDiv2[i].style.display = "none"
  836. }
  837. m_zoom = new Zoom({
  838. view: m_view
  839. });
  840. // m_view.ui.add(m_zoom, {
  841. // position: "top-right"
  842. // });
  843. var m_compass = new Compass({
  844. view: m_view
  845. });
  846. // m_view.ui.add(m_compass, {
  847. // position: "top-left"
  848. // });
  849. m_view.ui.remove('zoom');
  850. m_view.ui.remove('attribution');
  851. m_drawtool = new Draw({
  852. view: m_view
  853. })
  854. var centerx = m_view.center.x;
  855. var centery = m_view.center.y;
  856. // m_view.on("resize",function (event) {
  857. //
  858. // });
  859. m_view.watch("animation", function (response) {
  860. if (response && response.state === "running") {
  861. // console.log("Animation in progress");
  862. // window.parent.postMessage(
  863. // {
  864. // method: "mapAnimationInProgressCallback"
  865. // },
  866. // '*'
  867. // );
  868. }
  869. // else{
  870. // console.log("No animation");
  871. // }
  872. });
  873. m_view.on("drag", function (event) {
  874. if (event.action == 'end') {
  875. // event.startPropagation();
  876. }
  877. else {
  878. // console.log("drag in progress");
  879. sjDraging = true;
  880. window.parent.postMessage(
  881. {
  882. method: "mapDragingCallback"
  883. },
  884. '*'
  885. );
  886. }
  887. });
  888. m_view.on("pointer-move", function (event) {
  889. m_view.hitTest(event, GraphicsLayer).then(getGraphics);
  890. function getGraphics(response) {
  891. if (response.results.length) {
  892. var result = response.results[0];
  893. if (result.graphic) {
  894. m_view.whenLayerView(result.graphic.layer).then(function (layerView) {
  895. if (highlightSelect) {
  896. try{
  897. highlightSelect.remove();
  898. }catch (e){ }
  899. }
  900. try{
  901. highlightSelect = layerView.highlight(result.graphic);
  902. }catch (e){ }
  903. if (result.graphic.attributes && result.graphic.layer.id == "myGLayer") {
  904. if (isInDrawLayer != "") {
  905. postToParentPageMethed("moveOutDrawLayerReturn", [isInDrawLayer]);
  906. isInDrawLayer = "";
  907. }
  908. if (isInLightArea == "") {
  909. isInLightArea = result.graphic.attributes;
  910. postToParentPageMethed("moveInLightAreaReturn", [isInLightArea]);
  911. } else {
  912. if (isInLightArea.OBJECTID != result.graphic.attributes.OBJECTID) {
  913. postToParentPageMethed("moveOutLightAreaReturn", [isInLightArea]);
  914. isInLightArea = result.graphic.attributes;
  915. postToParentPageMethed("moveInLightAreaReturn", [isInLightArea]);
  916. }
  917. }
  918. } else if (result.graphic.attributes && result.graphic.layer.id == "myDrawGLayer") {
  919. if (isInDrawLayer == "") {
  920. isInDrawLayer = result.graphic.attributes;
  921. postToParentPageMethed("moveInDrawLayerReturn", [isInDrawLayer]);
  922. } else {
  923. if (isInDrawLayer != result.graphic.attributes) {
  924. postToParentPageMethed("moveOutDrawLayerReturn", [isInDrawLayer]);
  925. isInDrawLayer = result.graphic.attributes;
  926. postToParentPageMethed("moveInDrawLayerReturn", [isInDrawLayer]);
  927. }
  928. }
  929. } else {
  930. if (isInLightArea != "") {
  931. postToParentPageMethed("moveOutLightAreaReturn", [isInLightArea]);
  932. isInLightArea = "";
  933. }
  934. if (isInDrawLayer != "") {
  935. postToParentPageMethed("moveOutDrawLayerReturn", [isInDrawLayer]);
  936. isInDrawLayer = "";
  937. }
  938. }
  939. });
  940. }
  941. } else {
  942. // if(highlightSelect){
  943. // highlightSelect.remove();
  944. // }
  945. if (isInLightArea != "") {
  946. postToParentPageMethed("moveOutLightAreaReturn", [isInLightArea]);
  947. isInLightArea = "";
  948. }
  949. if (isInDrawLayer != "") {
  950. postToParentPageMethed("moveOutDrawLayerReturn", [isInDrawLayer]);
  951. isInDrawLayer = "";
  952. }
  953. }
  954. }
  955. });
  956. m_view.on("click", function (event) {
  957. popupCloseAll("viewClick");
  958. // if(m_mapClickdraw){
  959. // var screenPoint = {
  960. // x: event.x,
  961. // y: event.y
  962. // };
  963. // GraphicsLayer_DrawLayer.removeAll();
  964. // var hitPoint = m_view.toMap(screenPoint);
  965. // m_maphitPoint = hitPoint;
  966. // var point = hitPoint.x+","+hitPoint.y;
  967. // var jsonStr = '{"ExChangeRoot": {"Features": [' +
  968. // ' { "type": "point", "featureName": "兴趣点", "Feature":[ { "Geometry": { "Points":[ { "Point": "'+point+'" } ]},' +
  969. // '"Attribute": '+m_mapAttribute+', "ToolTip": "'+m_mapToolTip+'",' +
  970. // '"ImgUrl":"'+m_mapImgUrl +'" ,"ImgWidth":"'+ m_mapImgWidth +'","ImgHeight":"'+m_mapImgHeight +'" } ] } ]}}';
  971. // doGetGraphicByJson(jsonStr,false);
  972. // m_mapClickdraw = false;
  973. // // var url = GetConfigDataByName("WebServiceExtraURL");
  974. // // WsCommonClass("GetAddress",["x","y"],[hitPoint.x,hitPoint.y],mapClickdrawCallback,null,url);
  975. // GetAddressByXY(hitPoint.x,hitPoint.y,50);
  976. // function mapClickdrawCallback(evt){
  977. // if(evt[0] == null) {
  978. // window.parent.postMessage(
  979. // {
  980. // method: "clicklocationcallbackfun",
  981. // data: []
  982. // },
  983. // '*'
  984. // );
  985. // return;
  986. // }
  987. // m_mapAddress = evt[0].textContent;
  988. // var url = GetConfigDataByName("WebServiceConvertCoordinateURL");
  989. // WsCommonClass("ConvertXYToLonLat",["lon","lat"],[m_maphitPoint.x,m_maphitPoint.y],mapClickdrawCallback1,null,url);
  990. // }
  991. // function mapClickdrawCallback1(evt){
  992. // if(evt[0] == null) {
  993. // console.log("");
  994. // return;
  995. // }
  996. // var point = evt[0].textContent;
  997. // window.parent.postMessage(
  998. // {
  999. // method: "clicklocationcallbackfun",
  1000. // data: [point,m_mapAddress]
  1001. // },
  1002. // '*'
  1003. // );
  1004. // }
  1005. // }
  1006. m_view.hitTest(event).then(function (response) {
  1007. if (response.results.length) {
  1008. var result = response.results[0];
  1009. if (result.graphic) {
  1010. m_view.whenLayerView(result.graphic.layer).then(function (layerView) {
  1011. if (highlightSelect) {
  1012. try{
  1013. highlightSelect.remove();
  1014. }catch (e){ }
  1015. }
  1016. try{
  1017. highlightSelect = layerView.highlight(result.graphic);
  1018. }catch (e){ }
  1019. })
  1020. switch (result.graphic.layer.id) {
  1021. case "WZXYFeature":{
  1022. var jsonStr=result.graphic.attributes;
  1023. jsonStr.x=result.graphic.geometry.extent.center.x;
  1024. jsonStr.y=result.graphic.geometry.extent.center.y;
  1025. postToParentPageMethed("clickWZXYFeatureReturn", [jsonStr]);
  1026. break;
  1027. }
  1028. case "myDrawGLayer":
  1029. var returnList = []
  1030. var graphicList = GraphicsLayer_DrawLayer.graphics.items;
  1031. for (var i = 0; i < graphicList.length; i++) {
  1032. if (result.graphic.geometry.x == graphicList[i].geometry.x && result.graphic.geometry.y == graphicList[i].geometry.y) {
  1033. if (graphicList[i].attributes) {
  1034. returnList.push(graphicList[i].attributes);
  1035. }
  1036. }
  1037. }
  1038. postToParentPageMethed("clickDrawLayerReturn", [returnList]);
  1039. break;
  1040. case "myGLayer":
  1041. {
  1042. // m_view.goTo(result.graphic)
  1043. postToParentPageMethed("clickLightAreaReturn", [result.graphic.attributes]);
  1044. break;
  1045. }
  1046. default:
  1047. {
  1048. if (result.graphic.layer.declaredClass == "esri.layers.FeatureLayer") {
  1049. var queryTask = new QueryTask({
  1050. url: GetConfigDataByName("QueryLayer") + "/250"
  1051. });
  1052. var query = new Query();
  1053. query.geometry = null;
  1054. query.outFields = ["*"];
  1055. query.returnGeometry = true;
  1056. //query.geometry = option.geometry || null;
  1057. query.spatialRelationship = "intersects";
  1058. query.where = "1=1";
  1059. query.geometry = result.graphic.geometry;
  1060. queryTask.execute(query).then(function (results1) {
  1061. if (results1.features.length > 0) {
  1062. }
  1063. // window.parent.postMessage(
  1064. // {
  1065. // method: "mapOnclickCallback",
  1066. // data:[JSON.stringify(result.graphic.attributes).replace(/\"/g,'"'),
  1067. // JSON.stringify(results1.features[0].attributes["网格编码"]).replace(/\"/g,'"')
  1068. // ]
  1069. // },
  1070. // '*'
  1071. // );
  1072. else {
  1073. // window.parent.postMessage(
  1074. // {
  1075. // method: "mapOnclickCallback",
  1076. // data:[JSON.stringify(result.graphic.attributes).replace(/\"/g,'"'),'']
  1077. // },
  1078. // '*'
  1079. // );
  1080. }
  1081. });
  1082. }
  1083. break;
  1084. }
  1085. }
  1086. }
  1087. }
  1088. });
  1089. });
  1090. m_view.watch("scale", function (event) {
  1091. if (m_view.zoom % 1 === 0) { //整数
  1092. //chartLayer点放大缩小
  1093. if (chartLayer) {
  1094. var imgsize = chartLayerSize - (chartLayerSize * (12 - m_view.zoom) * 0.05);//zoom每级差5%
  1095. var list = chartLayer.chartOption.series;
  1096. for (var i = 0; i < list.length; i++) {
  1097. list[i].effect.symbolSize = imgsize
  1098. }
  1099. var option = {
  1100. series: list
  1101. };
  1102. chartLayer.setChartOption(option);
  1103. }
  1104. //GraphicsLayer_DrawLayer点放大缩小
  1105. var DrawLayerGraphics = GraphicsLayer_DrawLayer.graphics;
  1106. if (DrawLayerGraphics.length > 0) {
  1107. if (imgSizeList == []) {
  1108. return;
  1109. }
  1110. for (var i = 0; i < DrawLayerGraphics.length; i++) {
  1111. if (DrawLayerGraphics.items[i].symbol.type == "picture-marker") {
  1112. if(DrawLayerGraphics.items[i].attributes.newImgWidth){
  1113. var width=DrawLayerGraphics.items[i].attributes.newImgWidth;
  1114. var height=DrawLayerGraphics.items[i].attributes.newImgHeight;
  1115. var newImgWidth = width - (width * (14 - m_view.zoom) * 0.05);//zoom每级差5%
  1116. var newImgHeight = height - (height * (14 - m_view.zoom) * 0.05)
  1117. var symbol = {
  1118. type: "picture-marker",
  1119. url: DrawLayerGraphics.items[i].symbol.url,
  1120. width: newImgWidth + "px",
  1121. height: newImgHeight + "px"
  1122. }
  1123. DrawLayerGraphics.items[i].symbol = symbol
  1124. }
  1125. }
  1126. }
  1127. }
  1128. }
  1129. });
  1130. setTimeout("onMapLoadInfo()",1000);
  1131. // dyAddMapLayerByConfig();
  1132. // AddMapGraphicLayers();
  1133. });
  1134. var scaleBar = new ScaleBar({
  1135. view: m_view
  1136. });
  1137. // m_view.ui.add(scaleBar, {
  1138. // position: "bottom-left"
  1139. // });
  1140. if (currentExtent != null) {
  1141. m_view.extent = currentExtent
  1142. }
  1143. function dyAddMapLayerByConfig() {
  1144. var serverUrl;
  1145. var serverType;
  1146. var serverLabel;
  1147. var serverVisible;
  1148. GetConfigData();
  1149. var mapXml = xmlDoc.getElementsByTagName("map");
  1150. var mapNodes = mapXml[0].childNodes;
  1151. for (var i = 0; i < mapNodes.length; i++) {
  1152. var nodeObj = mapNodes[i];
  1153. if (nodeObj.nodeType == 1) {
  1154. var tagName = xmlUtil.getNodeTagName(nodeObj);
  1155. var value = xmlUtil.getNodeValue(nodeObj);
  1156. if (tagName == "geometryservice") {
  1157. serverType = "geometryservice";
  1158. serverUrl = value;
  1159. dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible)
  1160. } else if (tagName == "fullextent") {
  1161. var extentArray = value.split(",");
  1162. fullExtent = new Extent(parseFloat(extentArray[0]), parseFloat(extentArray[1]), parseFloat(extentArray[2]), parseFloat(extentArray[3]))
  1163. } else if (tagName == "basemaps") {
  1164. var childNodes = nodeObj.childNodes;
  1165. for (var j = 0; j < childNodes.length; j++) {
  1166. var childNode = childNodes[j];
  1167. if (childNode.nodeType == 1) {
  1168. for (var k = 0; k < childNode.attributes.length; k++) {
  1169. var attribute = childNode.attributes[k];
  1170. var attributeName = attribute.name;
  1171. if (attributeName == "label") {
  1172. serverLabel = attribute.value
  1173. }
  1174. if (attributeName == "type") {
  1175. serverType = attribute.value
  1176. }
  1177. if (attributeName == "visible") {
  1178. if (attribute.value == "false") serverVisible = false;
  1179. else serverVisible = true
  1180. }
  1181. }
  1182. serverUrl = xmlUtil.getNodeValue(childNode);
  1183. dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible)
  1184. }
  1185. }
  1186. }
  1187. }
  1188. }
  1189. }
  1190. function dyAddMapLayer(serverUrl, serverType, serverLabel, serverVisible) {
  1191. var layer;
  1192. switch (serverType) {
  1193. case "geometryservice":
  1194. {
  1195. geometryService = new GeometryService(serverUrl);
  1196. break
  1197. }
  1198. case "tiled":
  1199. {
  1200. layer = new TileLayer({
  1201. url: serverUrl,
  1202. id: serverLabel
  1203. });
  1204. layer.visible = serverVisible;
  1205. m_map.add(layer);
  1206. break;
  1207. }
  1208. case "dynamic":
  1209. {
  1210. AddMapGraphicLayers()
  1211. if (serverLabel == "卫监所动态数据") {
  1212. layer = new MapImageLayer({
  1213. url: serverUrl,
  1214. sublayers: [{
  1215. id: 0,
  1216. popupTemplate: {
  1217. title: "{COUNTY}",
  1218. content: "{POP2007} people lived in this county in 2007"
  1219. }
  1220. },
  1221. {
  1222. id: 1,
  1223. popupTemplate: {
  1224. title: "{COUNTY}",
  1225. content: "{POP2007} people lived in this county in 2007"
  1226. }
  1227. }]
  1228. });
  1229. } else {
  1230. dyLayer = new MapImageLayer({
  1231. url: serverUrl,
  1232. id: serverLabel
  1233. });
  1234. dyLayer.visible = serverVisible;
  1235. }
  1236. m_map.add(dyLayer);
  1237. on(dyLayer, "load",
  1238. function (evt) {
  1239. dynamicLayerLoaded(evt)
  1240. });
  1241. dyLayer.when(function () {
  1242. var layerInfo = GetDynamicServiceLayer();
  1243. for (var i = 0; i < layerInfo.length; i++) {
  1244. GetLayerRestData(i)
  1245. }
  1246. });
  1247. break;
  1248. }
  1249. case "density":
  1250. {
  1251. dyLayer = new MapImageLayer({
  1252. url: serverUrl,
  1253. id: serverLabel
  1254. });
  1255. dyLayer.visible = serverVisible;
  1256. m_map.add(dyLayer);
  1257. dyLayer.on("layerview-create", function(event){
  1258. createWZXYFeature();
  1259. });
  1260. break;
  1261. }
  1262. case "featurelayer":
  1263. {
  1264. var restUrl = serverUrl + "?f=pjson";
  1265. var xmlHttpRest = GetXmlHttpObject();
  1266. xmlHttpRest.open("GET", restUrl, true);
  1267. xmlHttpRest.send();
  1268. xmlHttpRest.onreadystatechange = function () {
  1269. var responseText = xmlHttpRest.responseText;
  1270. if (xmlHttpRest.readyState == 4) {
  1271. var LayerJsonData = JSON.parse(responseText);
  1272. if (LayerJsonData != "") {
  1273. var layers = LayerJsonData.layers;
  1274. if (layers.length > 0) {
  1275. // for (var i = 0; i < layers.length; i++) {
  1276. // if (layers[i].subLayerIds == null) {
  1277. // var layerId = layers[i].id;
  1278. // var layername = layers[i].name;
  1279. // if(layername)
  1280. // var dyLayer = new FeatureLayer({
  1281. // url: serverUrl+"/"+layerId,
  1282. // id: layerId
  1283. // });
  1284. // dyLayer.visible = serverVisible;
  1285. // // if(layername == "上水井盖")
  1286. // // dyLayer.visible = true;
  1287. // m_map.add(dyLayer);
  1288. // }
  1289. // }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. break;
  1295. }
  1296. case "vector":
  1297. {
  1298. var vlayer = new VectorTileLayer({
  1299. url: serverUrl,
  1300. id: serverLabel
  1301. });
  1302. m_map.add(vlayer);
  1303. break;
  1304. }
  1305. }
  1306. }
  1307. function dynamicLayerLoaded(event) {
  1308. m_view.zoom = 3
  1309. }
  1310. function AddMapGraphicLayers() {
  1311. // debugger;
  1312. GraphicsLayer_labelLayer = new GraphicsLayer;
  1313. GraphicsLayer_labelLayer.listMode = "hide";
  1314. GraphicsLayer_myLayer = new GraphicsLayer({id: "myGLayer"});
  1315. GraphicsLayer_myLayer.listMode = "hide";
  1316. GraphicsLayer_areaNameLayer = new GraphicsLayer();
  1317. GraphicsLayer_areaNameLayer.listMode = "hide";
  1318. GraphicsLayer_identityLayer = new GraphicsLayer;
  1319. GraphicsLayer_identityLayer.listMode = "hide";
  1320. GraphicsLayer_extendLayer = new GraphicsLayer;
  1321. GraphicsLayer_extendLayer.listMode = "hide";
  1322. GraphicsLayer_fickerLayer = new GraphicsLayer;
  1323. GraphicsLayer_fickerLayer.listMode = "hide";
  1324. GraphicsLayer_DrawLayer = new GraphicsLayer({id: "myDrawGLayer"});
  1325. GraphicsLayer_DrawLayer.listMode = "hide";
  1326. GraphicsLayer_flyTipLayer = new GraphicsLayer;
  1327. GraphicsLayer_flyTipLayer.listMode = "hide";
  1328. m_map.add(GraphicsLayer_myLayer);
  1329. m_map.add(GraphicsLayer_areaNameLayer);
  1330. m_map.add(GraphicsLayer_labelLayer);
  1331. m_map.add(GraphicsLayer_identityLayer);
  1332. m_map.add(GraphicsLayer_extendLayer);
  1333. m_map.add(GraphicsLayer_flyTipLayer);
  1334. m_map.add(GraphicsLayer_fickerLayer);
  1335. m_map.add(GraphicsLayer_DrawLayer);
  1336. }
  1337. function AddSceneViewWidget() {
  1338. // var viewTest = document.getElementById("viewTest");
  1339. // m_view.ui.add(viewTest, "bottom-right")
  1340. }
  1341. watchUtils.whenTrue(m_view, "stationary", function () {
  1342. // if (!m_view.center){
  1343. // console.log("move in progress");
  1344. // }
  1345. if (m_view.center) {
  1346. // if(isNewDragHandle){
  1347. // var test = myNewDragHandle();
  1348. // }
  1349. // return;
  1350. var xmax = m_view.extent.xmax;
  1351. var xmin = m_view.extent.xmin;
  1352. var ymax = m_view.extent.ymax;
  1353. var ymin = m_view.extent.ymin;
  1354. var extent = m_view.extent;
  1355. if (ecxtentChanged !== undefined && ecxtentChanged.xmin === extent.xmin && ecxtentChanged.ymin === extent.ymin
  1356. && ecxtentChanged.xmax === extent.xmax && ecxtentChanged.ymax === extent.ymax)
  1357. return;
  1358. var precision = 5000;//可以忽略超出的精度
  1359. var diff = 0;
  1360. var hasChanged = false;
  1361. if (isSetMapZoom) {
  1362. m_maxZoom = m_view.zoom;
  1363. isSetMapZoom = false;
  1364. }
  1365. if (viewxmin - xmin > precision) {
  1366. hasChanged = true;
  1367. diff = viewxmin - xmin;
  1368. xmin += diff;
  1369. xmax += diff;
  1370. //如果调整过后最大值超出,则调整回来,并把对应的y值也调整,否则会死循环
  1371. if (xmax > viewxmax) {
  1372. diff = xmax - viewxmax;
  1373. diff = (ymax - ymin) * diff / (xmax - xmin);
  1374. xmax = viewxmax;
  1375. ymin += diff / 2;
  1376. ymax -= diff / 2;
  1377. }
  1378. }
  1379. if (viewymin - ymin > precision) {
  1380. hasChanged = true;
  1381. diff = viewymin - ymin;
  1382. ymin += diff;
  1383. ymax += diff;
  1384. //如果调整过后最大值超出,则调整回来,并把对应的x值也调整,否则会死循环
  1385. if (ymax > viewymax) {
  1386. diff = ymax - viewymax;
  1387. diff = (xmax - xmin) * diff / (ymax - ymin);
  1388. ymax = viewymax;
  1389. xmin += diff / 2;
  1390. xmax -= diff / 2;
  1391. }
  1392. }
  1393. if (xmax - viewymax > precision) {
  1394. hasChanged = true;
  1395. diff = xmax - viewymax;
  1396. xmin -= diff;
  1397. xmax -= diff;
  1398. //如果调整过后最小值超出,则调整回来,并把对应的y值也调整,否则会死循环
  1399. if (xmin < viewxmin) {
  1400. diff = viewxmin - xmin;
  1401. diff = (ymax - ymin) * diff / (xmax - xmin);
  1402. xmin = viewxmin;
  1403. ymin += diff / 2;
  1404. ymax -= diff / 2;
  1405. }
  1406. }
  1407. if (ymax - viewymax > precision) {
  1408. hasChanged = true;
  1409. diff = ymax - viewymax;
  1410. ymin -= diff;
  1411. ymax -= diff;
  1412. //如果调整过后最小值超出,则调整回来,并把对应的x值也调整,否则会死循环
  1413. if (ymin < viewymin) {
  1414. diff = viewymin - ymin;
  1415. diff = (xmax - xmin) * diff / (ymax - ymin);
  1416. ymin = viewymin;
  1417. xmin += diff / 2;
  1418. xmax -= diff / 2;
  1419. }
  1420. }
  1421. if (hasChanged) {
  1422. ecxtentChanged = extent;
  1423. m_view.extent = new Extent({
  1424. xmin: xmin,
  1425. ymin: ymin,
  1426. xmax: xmax,
  1427. ymax: ymax,
  1428. spatialReference: m_view.spatialReference
  1429. });
  1430. // return;
  1431. }
  1432. window.parent.postMessage(
  1433. {
  1434. method: "resizeCallback"
  1435. },
  1436. '*'
  1437. );
  1438. if (sjDraging) {
  1439. sjDraging = false;
  1440. if (m_resizetime) {
  1441. clearTimeout(m_resizetime);
  1442. }
  1443. m_resizetime = setTimeout(function () {
  1444. // 执行地图中心点查询地址 or 地图中心点查询查询部件
  1445. // sj_type 0 关闭 1 地址 2 部件 3 地址和部件
  1446. sj_mapResize();
  1447. }, 300);
  1448. }
  1449. // window.parent.postMessage(
  1450. // {
  1451. // method: "resizeCallback"
  1452. // },
  1453. // '*'
  1454. // );
  1455. x = m_view.center.x;
  1456. y = m_view.center.y;
  1457. document.addEventListener("touchstart", function (e) {
  1458. x = m_view.center.x;
  1459. y = m_view.center.y;
  1460. x = x - 0;
  1461. y = y - 0;
  1462. });
  1463. //监听 touchmove 事件 手指 移动时 做的事情
  1464. document.addEventListener("touchmove", function (e) {
  1465. e.preventDefault();
  1466. // 2 根 手指执行 目标元素放大操作
  1467. if (e.touches.length >= 2) {
  1468. x = x - 0;
  1469. y = y - 0;
  1470. m_view.center = new Point({
  1471. x: x - 0,
  1472. y: y - 0,
  1473. spatialReference: m_view.spatialReference
  1474. });
  1475. }
  1476. ;
  1477. });
  1478. //监听 手指离开屏幕时
  1479. document.addEventListener("touchend", function (e) {
  1480. });
  1481. }
  1482. });
  1483. });
  1484. }
  1485. var ecxtentChanged;
  1486. function initMapEdit() {
  1487. require([
  1488. "esri/Map",
  1489. "esri/views/MapView",
  1490. "esri/widgets/Editor",
  1491. "esri/layers/FeatureLayer"
  1492. ], function (Map, MapView, Editor, FeatureLayer) {
  1493. var editConfigCrimeLayer, editConfigPoliceLayer;
  1494. m_map = new Map({
  1495. logo: false
  1496. });
  1497. m_view = new MapView({
  1498. container: "viewDiv",
  1499. map: m_map,
  1500. });
  1501. // var url = GetConfigDataByName("EditLayer")+"/0";
  1502. // var featurelayer = new FeatureLayer({
  1503. // url:url,
  1504. // title:"房屋"
  1505. // });
  1506. // m_map.add(featurelayer);
  1507. // var url1 = GetConfigDataByName("EditLayer")+"/1";
  1508. // var featurelayer1 = new FeatureLayer({
  1509. // url:url1,
  1510. // title:"土地"
  1511. // });
  1512. // featurelayer1.visible = true;
  1513. // m_map.add(featurelayer);
  1514. var serverUrl = GetConfigDataByName("EditLayer");
  1515. var xmlHttpRest = GetXmlHttpObject();
  1516. xmlHttpRest.open("GET", serverUrl + "?f=pjson", true);
  1517. xmlHttpRest.send();
  1518. xmlHttpRest.onreadystatechange = function () {
  1519. var responseText = xmlHttpRest.responseText;
  1520. if (xmlHttpRest.readyState == 4) {
  1521. var LayerJsonData = JSON.parse(responseText);
  1522. if (LayerJsonData != "") {
  1523. var layers = LayerJsonData.layers;
  1524. if (layers.length > 0) {
  1525. for (var i = 0; i < layers.length; i++) {
  1526. if (layers[i].subLayerIds == null) {
  1527. var layerId = layers[i].id;
  1528. var layername = layers[i].name;
  1529. var dyLayer = new FeatureLayer({
  1530. url: serverUrl + "/" + layerId,
  1531. id: layername,
  1532. title: layername
  1533. });
  1534. dyLayer.visible = true;
  1535. m_map.add(dyLayer);
  1536. }
  1537. }
  1538. m_view.when(function () {
  1539. function customGroup(grouping) {
  1540. var groupHeading = "";
  1541. switch (grouping.template.drawingTool) {
  1542. case "point":
  1543. groupHeading = "点";
  1544. break;
  1545. case "polyline":
  1546. groupHeading = "线";
  1547. break;
  1548. case "polygon":
  1549. groupHeading = "面";
  1550. break;
  1551. }
  1552. return groupHeading;
  1553. }
  1554. var editor = new Editor({
  1555. view: m_view,
  1556. supportingWidgetDefaults: {
  1557. featureTemplates: {
  1558. groupBy: customGroup
  1559. }
  1560. }
  1561. });
  1562. // var editor = new Editor({view: m_view});
  1563. m_view.ui.add(editor, "top-right");
  1564. });
  1565. }
  1566. }
  1567. }
  1568. }
  1569. });
  1570. }
  1571. function GetLayer(layerName) {
  1572. var layer;
  1573. for (var i = 0; i < m_map.layerIds.length; i++) {
  1574. var layeridName = m_map.layerIds[i];
  1575. if (layeridName == layerName) {
  1576. layer = m_map._layers[layeridName];
  1577. return layer
  1578. }
  1579. }
  1580. }
  1581. function QueryObjectByWhere(LayerName, where, returnFields, KeyValue) {
  1582. KeyValue = KeyValue ? KeyValue : "Query";
  1583. require(["esri/tasks/support/Query", "esri/tasks/QueryTask"],
  1584. function (Query, QueryTask) {
  1585. var query = new Query;
  1586. if (GetConfigDataByName("QueryLayer")) {
  1587. dynamicLayerURL = GetConfigDataByName("QueryLayer")
  1588. }
  1589. var QueryLayerID = GetLayerIdbyName(LayerName);
  1590. if (QueryLayerID == -1) {
  1591. return "无查询图层"
  1592. }
  1593. var queryTask = new QueryTask(dynamicLayerURL + "/" + QueryLayerID);
  1594. queryTask.where = " 1=1 ";
  1595. if (where != "") {
  1596. query.where = where
  1597. }
  1598. query.outSpatialReference = m_map.spatialReference;
  1599. query.returnGeometry = true;
  1600. query.outFields = ["*"];
  1601. if (returnFields != "") {
  1602. query.outFields = returnFields
  1603. }
  1604. queryTask.execute(query,
  1605. function handleQueryResult(results) {
  1606. QueryObjectByWhereCompHandle(results, KeyValue)
  1607. },
  1608. function errorHandler(err) {
  1609. QueryObjectByWhereFaultHandle("查询不成功!", KeyValue)
  1610. })
  1611. })
  1612. }
  1613. function GetLayerIdbyName(name) {
  1614. var layerInfo;
  1615. layerInfo = GetDynamicServiceLayer();
  1616. if (layerInfo != null) {
  1617. for (var j = 0; j < layerInfo.length; j++) {
  1618. var currnetLayer = layerInfo.getItemAt(j);
  1619. if (currnetLayer.title == name) {
  1620. return currnetLayer.id
  1621. }
  1622. }
  1623. }
  1624. return -1
  1625. }
  1626. function GetLayerNamebyId(id) {
  1627. var layerInfo;
  1628. layerInfo = GetDynamicServiceLayer();
  1629. if (layerInfo != null) {
  1630. for (var j = 0; j < layerInfo.length; j++) {
  1631. var currnetLayer = layerInfo.getItemAt(j);
  1632. if (currnetLayer.id == id) {
  1633. return currnetLayer.title
  1634. }
  1635. }
  1636. }
  1637. return -1
  1638. }
  1639. function GetDynamicServiceLayer() {
  1640. var layerInfo;
  1641. for (var i = 0; i < m_map.layers.length; i++) {
  1642. var BaseLayer = m_map.layers.getItemAt(i);
  1643. if (BaseLayer.declaredClass == "esri.layers.MapImageLayer" && BaseLayer.id == "动态数据") {
  1644. layerInfo = m_map.layers.getItemAt(i).sublayers;
  1645. dynamicLayerURL = BaseLayer.url;
  1646. return layerInfo
  1647. } else {
  1648. }
  1649. }
  1650. return null;
  1651. }
  1652. function ClearMap() {
  1653. GraphicsLayer_labelLayer.clear();
  1654. GraphicsLayer_myLayer.clear();
  1655. GraphicsLayer_identityLayer.clear();
  1656. GraphicsLayer_extendLayer.clear();
  1657. GraphicsLayer_fickerLayer.clear();
  1658. GraphicsLayer_DrawLayer.clear();
  1659. GraphicsLayer_flyTipLayer.clear();
  1660. if (chartLayer) {
  1661. chartLayer.removeLayer();
  1662. chartLayer = null;
  1663. }
  1664. if (chartLayer2) {
  1665. chartLayer2.removeLayer();
  1666. chartLayer2 = null;
  1667. }
  1668. if (chartLayer3) {
  1669. chartLayer3.removeLayer();
  1670. chartLayer3 = null;
  1671. }
  1672. }
  1673. function OpenLayer(layerName, layerVisible) {
  1674. require(["esri/Map", "esri/views/MapView", "esri/layers/MapImageLayer", "dojo/on"],
  1675. function (Map, MapView, MapImageLayer, on) {
  1676. var layer;
  1677. var layerid = GetLayerIdbyName(layerName);
  1678. for (var i = 0; i < m_map.layers.length; i++) {
  1679. var BaseLayer = m_map.layers.getItemAt(i);
  1680. if (BaseLayer.declaredClass == "esri.layers.MapImageLayer") {
  1681. layer = m_map.layers.getItemAt(i);
  1682. break
  1683. }
  1684. }
  1685. var sublayer = layer.findSublayerById(parseInt(layerid));
  1686. sublayer.visible = layerVisible
  1687. })
  1688. }
  1689. function OpenFeatureLayerByID(layerid, layerVisible) {
  1690. var layer;
  1691. for (var i = 0; i < m_map.layers.length; i++) {
  1692. var BaseLayer = m_map.layers.getItemAt(i);
  1693. if (BaseLayer.declaredClass == "esri.layers.FeatureLayer") {
  1694. layer = m_map.layers.getItemAt(i);
  1695. if (layer.layerId == layerid) {
  1696. layer.visible = layerVisible;
  1697. break
  1698. }
  1699. }
  1700. }
  1701. }
  1702. function closeMapImageLayerByName() {
  1703. var layer = getLayerByLayerId("density_1");
  1704. var items = layer.allSublayers.items;
  1705. for (var i = 0; i < items.length; i++) {
  1706. if (items[i].sublayers == null) {
  1707. items[i].visible = false;
  1708. }
  1709. }
  1710. }
  1711. // function OpenMapImageLayerByName(layerName,layerVisible){
  1712. //
  1713. //
  1714. // var layerId = GetFeatureLayerIdbyName(layerName);
  1715. //
  1716. // for (var i = 0; i < m_view.allLayerViews.length; i++) {
  1717. // var layer = m_view.allLayerViews.getItemAt(i).layer;
  1718. // if (layer.id == "动态数据") {
  1719. // // layer.allSublayers.items[3].visible = true;
  1720. // // break;
  1721. // var arr = layer.allSublayers.items;
  1722. // for(var j=0;j<arr.length;j++){
  1723. // if(arr[j].id==layerId){
  1724. // arr[j].visible = layerVisible;
  1725. // //layer.sublayers.items.push(arr[j]);
  1726. // break;
  1727. // }
  1728. // }
  1729. // }
  1730. // }
  1731. // }
  1732. function OpenFeatureLayerByName(layerName, layerVisible) {
  1733. var layerid = "";
  1734. for (var i = 0; i < m_map.layers.length; i++) {
  1735. var BaseLayer = m_map.layers.getItemAt(i);
  1736. if (BaseLayer.declaredClass == "esri.layers.FeatureLayer") {
  1737. layer = m_map.layers.getItemAt(i);
  1738. if (layer.id == layerName) {
  1739. layer.visible = layerVisible;
  1740. }
  1741. // else {
  1742. // layer.visible = false;
  1743. // }
  1744. }
  1745. }
  1746. }
  1747. function OpenFeatureLayerByID1(layerid, layerVisible) {
  1748. switch (parseInt(layerid)) {
  1749. case 0:
  1750. fe0.visible = layerVisible;
  1751. if (layerVisible) {
  1752. fe1.visible = false;
  1753. fe2.visible = false;
  1754. fe3.visible = false;
  1755. fe4.visible = false;
  1756. fe5.visible = false;
  1757. fe6.visible = false;
  1758. fe7.visible = false;
  1759. fe8.visible = false;
  1760. fe9.visible = false;
  1761. fe10.visible = false
  1762. }
  1763. break;
  1764. case 1:
  1765. fe1.visible = layerVisible;
  1766. if (layerVisible) {
  1767. fe0.visible = false;
  1768. fe2.visible = false;
  1769. fe3.visible = false;
  1770. fe4.visible = false;
  1771. fe5.visible = false;
  1772. fe6.visible = false;
  1773. fe7.visible = false;
  1774. fe8.visible = false;
  1775. fe9.visible = false;
  1776. fe10.visible = false
  1777. }
  1778. break;
  1779. case 2:
  1780. fe2.visible = layerVisible;
  1781. if (layerVisible) {
  1782. fe0.visible = false;
  1783. fe1.visible = false;
  1784. fe3.visible = false;
  1785. fe4.visible = false;
  1786. fe5.visible = false;
  1787. fe6.visible = false;
  1788. fe7.visible = false;
  1789. fe8.visible = false;
  1790. fe9.visible = false;
  1791. fe10.visible = false
  1792. }
  1793. break;
  1794. case 3:
  1795. fe3.visible = layerVisible;
  1796. if (layerVisible) {
  1797. fe0.visible = false;
  1798. fe1.visible = false;
  1799. fe2.visible = false;
  1800. fe4.visible = false;
  1801. fe5.visible = false;
  1802. fe6.visible = false;
  1803. fe7.visible = false;
  1804. fe8.visible = false;
  1805. fe9.visible = false;
  1806. fe10.visible = false
  1807. }
  1808. break;
  1809. case 4:
  1810. fe4.visible = layerVisible;
  1811. if (layerVisible) {
  1812. fe0.visible = false;
  1813. fe1.visible = false;
  1814. fe2.visible = false;
  1815. fe3.visible = false;
  1816. fe5.visible = false;
  1817. fe6.visible = false;
  1818. fe7.visible = false;
  1819. fe8.visible = false;
  1820. fe9.visible = false;
  1821. fe10.visible = false
  1822. }
  1823. break;
  1824. case 5:
  1825. fe5.visible = layerVisible;
  1826. if (layerVisible) {
  1827. fe0.visible = false;
  1828. fe1.visible = false;
  1829. fe2.visible = false;
  1830. fe3.visible = false;
  1831. fe4.visible = false;
  1832. fe6.visible = false;
  1833. fe7.visible = false;
  1834. fe8.visible = false;
  1835. fe9.visible = false;
  1836. fe10.visible = false
  1837. }
  1838. break;
  1839. case 6:
  1840. fe6.visible = layerVisible;
  1841. if (layerVisible) {
  1842. fe0.visible = false;
  1843. fe1.visible = false;
  1844. fe2.visible = false;
  1845. fe3.visible = false;
  1846. fe4.visible = false;
  1847. fe5.visible = false;
  1848. fe7.visible = false;
  1849. fe8.visible = false;
  1850. fe9.visible = false;
  1851. fe10.visible = false
  1852. }
  1853. break;
  1854. case 7:
  1855. fe7.visible = layerVisible;
  1856. if (layerVisible) {
  1857. fe0.visible = false;
  1858. fe1.visible = false;
  1859. fe2.visible = false;
  1860. fe3.visible = false;
  1861. fe4.visible = false;
  1862. fe5.visible = false;
  1863. fe6.visible = false;
  1864. fe8.visible = false;
  1865. fe9.visible = false;
  1866. fe10.visible = false
  1867. }
  1868. break;
  1869. case 8:
  1870. fe8.visible = layerVisible;
  1871. if (layerVisible) {
  1872. fe0.visible = false;
  1873. fe1.visible = false;
  1874. fe2.visible = false;
  1875. fe3.visible = false;
  1876. fe4.visible = false;
  1877. fe5.visible = false;
  1878. fe6.visible = false;
  1879. fe7.visible = false;
  1880. fe9.visible = false;
  1881. fe10.visible = false
  1882. }
  1883. break;
  1884. case 9:
  1885. fe9.visible = layerVisible;
  1886. if (layerVisible) {
  1887. fe0.visible = false;
  1888. fe1.visible = false;
  1889. fe2.visible = false;
  1890. fe3.visible = false;
  1891. fe4.visible = false;
  1892. fe5.visible = false;
  1893. fe6.visible = false;
  1894. fe7.visible = false;
  1895. fe8.visible = false;
  1896. fe10.visible = false
  1897. }
  1898. break;
  1899. case 10:
  1900. fe10.visible = layerVisible;
  1901. if (layerVisible) {
  1902. fe0.visible = false;
  1903. fe1.visible = false;
  1904. fe2.visible = false;
  1905. fe3.visible = false;
  1906. fe4.visible = false;
  1907. fe5.visible = false;
  1908. fe6.visible = false;
  1909. fe7.visible = false;
  1910. fe8.visible = false;
  1911. fe9.visible = false
  1912. }
  1913. break
  1914. }
  1915. }
  1916. function buffer(point) {
  1917. require(["esri/tasks/GeometryService", "esri/tasks/support/BufferParameters"],
  1918. function (GeometryService, BufferParameters) {
  1919. var webMerPoint = webMercatorUtils.geographicToWebMercator(point);
  1920. var params = new BufferParameters;
  1921. params.distances = [560];
  1922. params.unit = "kilometers";
  1923. params.geodesic = true;
  1924. params.bufferSpatialReference = new SpatialReference({
  1925. wkid: 3857
  1926. });
  1927. params.outSpatialReference = m_view.spatialReference;
  1928. params.geometries = [webMerPoint];
  1929. geometryService.buffer(params).when(function (results) {
  1930. bufferLayer.add(new Graphic({
  1931. geometry: results[0]
  1932. }))
  1933. })
  1934. })
  1935. }
  1936. function bufferPoint(point) {
  1937. if (!bufferEnabled) {
  1938. console.log("buffering not enabled. Hit the space bar key and click/drag to buffer.");
  1939. return
  1940. }
  1941. clearGraphics();
  1942. point.hasZ = false;
  1943. point.z = undefined;
  1944. pointLayer.add(new Graphic({
  1945. geometry: point,
  1946. symbol: pointSym
  1947. }));
  1948. var buffer = geometryEngine.geodesicBuffer(point, 560, "kilometers");
  1949. bufferLayer.add(new Graphic({
  1950. geometry: buffer,
  1951. symbol: polySym
  1952. }))
  1953. }
  1954. function GetLayerRestData(layerID) {
  1955. var restUrl = dynamicLayerURL + "/" + layerID + "?f=pjson";
  1956. var xmlHttpRest = GetXmlHttpObject();
  1957. xmlHttpRest.open("GET", restUrl, true);
  1958. xmlHttpRest.send();
  1959. xmlHttpRest.onreadystatechange = function () {
  1960. var responseText = xmlHttpRest.responseText;
  1961. if (xmlHttpRest.readyState == 4) {
  1962. symble.push(responseText);
  1963. var layerInfo = GetDynamicServiceLayer();
  1964. if (layerInfo.length - 1 == layerID) {
  1965. isMapLoaded = true;
  1966. onMapLoaded();
  1967. }
  1968. }
  1969. }
  1970. }
  1971. function GetXmlHttpObject() {
  1972. var xmlHttpRest = null;
  1973. try {
  1974. xmlHttpRest = new XMLHttpRequest
  1975. } catch (e) {
  1976. try {
  1977. xmlHttpRest = new ActiveXObject("Msxml2.XMLHTTP")
  1978. } catch (e) {
  1979. xmlHttpRest = new ActiveXObject("Microsoft.XMLHTTP")
  1980. }
  1981. }
  1982. if (xmlHttpRest == null) {
  1983. return
  1984. }
  1985. return xmlHttpRest
  1986. }
  1987. function ClearLightLayerStatus() {
  1988. if (highlightSelect) {
  1989. highlightSelect.remove()
  1990. }
  1991. if (highlightSelectExtra) {
  1992. highlightSelectExtra.remove()
  1993. }
  1994. }
  1995. function flashLayerStatus(featureLayer, statusFieldName, statusValue) {
  1996. require(["esri/tasks/support/Query", "esri/tasks/QueryTask", "esri/core/watchUtils", "esri/geometry/Geometry", "esri/geometry/Polygon"],
  1997. function (Query, QueryTask, watchUtils, Geometry, Polygon) {
  1998. var query = new Query;
  1999. query.where = statusFieldName + "=" + statusValue;
  2000. query.returnGeometry = true;
  2001. query.outFields = ["*"];
  2002. featureLayer.queryFeatures(query).when(function (resultsObjectIDs) {
  2003. m_view.whenLayerView(featureLayer).when(function (lyrView) {
  2004. if (highlightSelectExtra) {
  2005. highlightSelectExtra.remove()
  2006. }
  2007. highlightSelectExtra = lyrView.highlight(resultsObjectIDs.features)
  2008. });
  2009. console.log("resultsObjectIDs:", resultsObjectIDs)
  2010. })
  2011. })
  2012. }
  2013. function setCenterExtent(x, y, radius) {
  2014. require(["esri/geometry/Extent"],
  2015. function (Extent) {
  2016. var ext = new Extent({
  2017. xmin: x - radius,
  2018. ymin: y - radius,
  2019. xmax: x + radius,
  2020. ymax: y + radius,
  2021. spatialReference: m_view.spatialReference
  2022. });
  2023. m_view.extent = ext
  2024. })
  2025. }
  2026. function setExtent(xmin, ymin, xmax, ymax) {
  2027. require(["esri/geometry/Extent"],
  2028. function (Extent) {
  2029. var ext = new Extent({
  2030. xmin: xmin,
  2031. ymin: ymin,
  2032. xmax: xmax,
  2033. ymax: ymax,
  2034. spatialReference: m_view.spatialReference
  2035. });
  2036. m_view.extent = ext
  2037. })
  2038. }
  2039. function goToPoint(point) {
  2040. if (currentMapMode == "3D") {
  2041. var newCam = m_view.camera.clone();
  2042. newCam.position = point;
  2043. newCam.tilt = 0;
  2044. var ai = m_view.goTo(newCam).when(function (ani) {
  2045. tiltView(45)
  2046. })
  2047. }
  2048. }
  2049. function tiltView() {
  2050. var tilt = m_view.camera.tilt + .001;
  2051. if (tilt >= 80) {
  2052. tilt = 0
  2053. } else if (tilt >= 40) {
  2054. tilt = 80
  2055. } else {
  2056. tilt = 40
  2057. }
  2058. m_view.goTo({
  2059. tilt: tilt
  2060. })
  2061. }
  2062. function GetLayerMainRestInfo2(restURL) {
  2063. var restUrl = restURL + "?f=pjson";
  2064. var xmlHttpRest = GetXmlHttpObject();
  2065. xmlHttpRest.open("GET", restUrl, true);
  2066. xmlHttpRest.send();
  2067. xmlHttpRest.onreadystatechange = function () {
  2068. var responseText = xmlHttpRest.responseText;
  2069. if (xmlHttpRest.readyState == 4) {
  2070. GetLayerMainRestInfo_Complete2(restURL, responseText);
  2071. }
  2072. }
  2073. }
  2074. function GetLayerMainRestInfo_Complete2(restURL, data) {
  2075. extraLayerJsonData = JSON.parse(data);
  2076. // onMapLoadInfo();
  2077. // myNewDragHandle();
  2078. var restUrl1 = GetConfigDataByName("MYQXFeatureLayer") + "?f=pjson";
  2079. var xmlHttpRest1 = GetXmlHttpObject();
  2080. xmlHttpRest1.open("GET", restUrl1, true);
  2081. xmlHttpRest1.send();
  2082. xmlHttpRest1.onreadystatechange = function () {
  2083. var responseText = xmlHttpRest1.responseText;
  2084. if (xmlHttpRest1.readyState == 4) {
  2085. GetLayerMainRestInfo_Complete3("", responseText);
  2086. }
  2087. }
  2088. }
  2089. var qxLayerJsonData;
  2090. function GetLayerMainRestInfo_Complete3(restURL, data) {
  2091. qxLayerJsonData = JSON.parse(data);
  2092. onMapLoadInfo();
  2093. // myNewDragHandle();
  2094. }
  2095. function GetLayerMainRestInfo1(restURL) {
  2096. var restUrl = restURL + "?f=pjson";
  2097. $.ajax({
  2098. type: 'get',
  2099. url: restUrl,
  2100. crossDomain: true,
  2101. dataType: 'jsonp',
  2102. success: GetLayerMainRestInfo_Complete(restURL, data)
  2103. });
  2104. }
  2105. function GetLayerMainRestInfo(restURL) {
  2106. var restUrl = restURL + "?f=pjson";
  2107. var xmlHttpRest = GetXmlHttpObject();
  2108. xmlHttpRest.open("GET", restUrl, true);
  2109. xmlHttpRest.send();
  2110. xmlHttpRest.onreadystatechange = function () {
  2111. var responseText = xmlHttpRest.responseText;
  2112. if (xmlHttpRest.readyState == 4) {
  2113. GetLayerMainRestInfo_Complete(restURL, responseText)
  2114. }
  2115. }
  2116. }
  2117. var extraLayerJsonData;
  2118. function GetLayerMainRestInfo_Complete(restURL, data) {
  2119. extraLayerJsonData = JSON.parse(data);
  2120. var layers = extraLayerJsonData.layers;
  2121. require(["esri/layers/FeatureLayer"],
  2122. function (FeatureLayer) {
  2123. if (layers.length > 0) {
  2124. for (var i = 0; i < layers.length; i++) {
  2125. var fl = new FeatureLayer({
  2126. url: restURL + "/" + layers[i].id,
  2127. id: layers[i].name,
  2128. visible: false
  2129. });
  2130. var content = "{*}";
  2131. var url = "";
  2132. switch (layers[i].name) {
  2133. case "一级医疗机构":
  2134. url = "";
  2135. content = "机构名称:{COMP_NAME}<br>卫生许可:{HEALTH_LIC}<br>地址:{BUS_ADDR}<br>电话:{TELPHONE}<br><a onclick='showDetail(\"" + layers[i].name + '","' + url + '"' + ",1)'>详细信息</a>";
  2136. fl.popupTemplate = {
  2137. title: "一级医疗机构",
  2138. content: content
  2139. };
  2140. break;
  2141. case "二级医疗机构":
  2142. url = "";
  2143. content = "机构名称:{COMP_NAME}<br>卫生许可:{HEALTH_LIC}<br>地址:{BUS_ADDR}<br>电话:{TELPHONE}<br><a onclick='showDetail(\"" + layers[i].name + '","' + url + '"' + ",1)'>详细信息</a>";
  2144. fl.popupTemplate = {
  2145. title: "二级医疗机构",
  2146. content: content
  2147. };
  2148. break;
  2149. case "三级医疗机构":
  2150. url = "http://10.101.35.25:8080/wjsite/a/tWd3MedicalLicense/medicalDtails?id=cb885991548744a7aa02febd425d977d";
  2151. content = "机构名称:{COMP_NAME}<br>卫生许可:{HEALTH_LIC}<br>地址:{BUS_ADDR}<br>电话:{TELPHONE}<br><a onclick='showDetail(\"" + layers[i].name + '","' + url + '"' + ",1)'>档案信息</a>";
  2152. fl.popupTemplate = {
  2153. title: "三级医疗机构",
  2154. content: content
  2155. };
  2156. break;
  2157. case "空调机房":
  2158. url = "";
  2159. content = "描述:{描述}";
  2160. fl.popupTemplate = {
  2161. title: "空调机房",
  2162. content: content
  2163. };
  2164. break;
  2165. case "宾馆":
  2166. url = "";
  2167. content = "名称:{COMP_NAME}<br>地址:{BUS_ADDR}<br>卫生许可:{HEALTH_LIC}<br>联系方式:{TELPHONE}<br><a onclick='showDetail(\"" + layers[i].name + '","' + url + '"' + ",1)'>详细信息</a>";
  2168. fl.popupTemplate = {
  2169. title: "宾馆",
  2170. content: content
  2171. };
  2172. break;
  2173. case "重大活动保障医疗机构":
  2174. url = "";
  2175. content = "单位名称:{单位名称}<br>地址:{一户一档地址}<br><a onclick='showDetail(\"" + layers[i].name + '","' + url + '"' + ",1)'>详细信息</a>";
  2176. fl.popupTemplate = {
  2177. title: "重大活动保障医疗机构",
  2178. content: content
  2179. };
  2180. break;
  2181. case "监督机构":
  2182. url = "";
  2183. content = "名称:{区县名称}<br>地址:{地址}<br>电话:{电话}<br><a onclick='showDetail(\"" + layers[i].name + '","' + url + '"' + ",1)'>详细信息</a>";
  2184. fl.popupTemplate = {
  2185. title: "监督机构",
  2186. content: content
  2187. };
  2188. break;
  2189. case "管网水监测点":
  2190. url = "http://10.101.35.25:8088/#/?isMap=true&type=testResultsTable&id=60000000000";
  2191. var url2 = "http://10.101.35.25:8088/#/?isMap=true&type=patrolRecordsTable&id=60000000000";
  2192. content = "监测点编号:{JCDCODE}<br>监测点位置:{JCDADDR}<br>" +
  2193. "<a onclick='showDetail(\"" + layers[i].name + '","' + url + '"' + ",1)'>检验结果</a>&nbsp;&nbsp;" +
  2194. "<a onclick='showDetail(\"" + layers[i].name + '","' + url2 + '"' + ",1)'>监督员巡查</a>";
  2195. fl.popupTemplate = {
  2196. title: "管网水监测点",
  2197. content: content
  2198. };
  2199. break;
  2200. case "主要接待场所":
  2201. url = "http://10.101.35.25:8080/wjsite/a/document/obj/publicPlaceDtails?id={ID}";
  2202. var url2 = "http://10.101.35.25:8088/#/?isMap=true&type=ggcsWaterForm&id={ID}";
  2203. var url3 = "http://10.101.35.25:8088/#/?isMap=true&type=ggcsSampingTable&id={ID}";
  2204. var url4 = "http://10.101.35.25:8088/#/?isMap=true&type=waterSupplyCheckTable&code=00&id={ID}";
  2205. content = "名称:{COMP_NAME}<br>地址:{BUS_ADDR}<br>卫生许可:{HEALTH_LIC}<br>联系方式:{TELPHONE}<br>" +
  2206. "<a onclick='showDetail(\"" + layers[i].name + '","' + url + '"' + ",1)'>档案信息</a>&nbsp;&nbsp;" +
  2207. "<a onclick='showDetail(\"" + layers[i].name + '","' + url2 + '"' + ",1)'>饮用水档案</a>";
  2208. fl.popupTemplate = {
  2209. title: "主要接待场所",
  2210. content: content
  2211. };
  2212. break;
  2213. default:
  2214. fl.popupTemplate = {
  2215. title: "详细信息",
  2216. content: content
  2217. };
  2218. break
  2219. }
  2220. m_map.add(fl)
  2221. }
  2222. }
  2223. })
  2224. }
  2225. function showDetail(type, url, id) {
  2226. if (!url) {
  2227. return
  2228. }
  2229. m_view.popup.close();
  2230. var title = "详细信息";
  2231. switch (type) {
  2232. case "水箱":
  2233. title = "国家会展中心二次供水设施每日巡查录入表";
  2234. break;
  2235. case "空气在线监测点":
  2236. title = "国家会展中心空气在线监测每日巡查录入表";
  2237. break;
  2238. default:
  2239. title = "详细信息";
  2240. break;
  2241. }
  2242. var infoDiv = $("#infoDialog").dialog({
  2243. width: 620,
  2244. height: 550,
  2245. modal: true,
  2246. title: title
  2247. });
  2248. if (infoDiv.length > 0) {
  2249. infoDiv.attr("style", "width:600px;height:500px;");
  2250. infoDiv.html(GetIFrameInfoWinContent(type, url));
  2251. $(".ui-dialog-title").text(title);
  2252. } else {
  2253. alert("未发现详细信息");
  2254. }
  2255. }
  2256. //
  2257. var isSetMapZoom = false;
  2258. var m_maxZoom = 1;
  2259. //范围四至查询
  2260. function queryForExtent(Layername, where, precision) {
  2261. var layerId = GetFeatureLayerIdbyName(Layername);
  2262. if (layerId == -1) {
  2263. alert("没有此图层");
  2264. return;
  2265. }
  2266. require([
  2267. "esri/tasks/FindTask",
  2268. "esri/tasks/support/FindParameters",
  2269. "esri/tasks/IdentifyTask",
  2270. "esri/tasks/support/IdentifyParameters",
  2271. "esri/geometry/Point",
  2272. "esri/tasks/QueryTask", "esri/tasks/support/Query",
  2273. "esri/geometry/Extent",
  2274. "esri/Graphic",
  2275. "esri/geometry/geometryEngine",
  2276. "dojo/on",
  2277. ], function (FindTask, FindParameters, IdentifyTask, IdentifyParameters, Point,
  2278. QueryTask, Query, Extent, Graphic, geometryEngine, on) {
  2279. // dynamicLayerURL = GetConfigDataByName("QueryLayer")+"/250";
  2280. var queryTask = new QueryTask({
  2281. url: GetConfigDataByName("QueryLayer") + "/" + layerId
  2282. });
  2283. var query = new Query();
  2284. // query.geometry = geo;
  2285. query.outFields = ["*"];
  2286. query.returnGeometry = true;
  2287. //query.geometry = option.geometry || null;
  2288. // query.spatialRelationship = "intersects";
  2289. query.where = where;
  2290. queryTask.execute(query).then(function (results) {
  2291. if (results.features.length > 0) {
  2292. viewxmax = results.features[0].geometry.extent.xmax + 0;
  2293. viewxmin = results.features[0].geometry.extent.xmin - 0;
  2294. viewymax = results.features[0].geometry.extent.ymax + 0;
  2295. viewymin = results.features[0].geometry.extent.ymin - 0;
  2296. var extent = new Extent({
  2297. xmin: results.features[0].geometry.extent.xmin - 0,
  2298. ymin: results.features[0].geometry.extent.ymin - 0,
  2299. xmax: results.features[0].geometry.extent.xmax - 0,
  2300. ymax: results.features[0].geometry.extent.ymax - 0,
  2301. spatialReference: m_view.spatialReference
  2302. });
  2303. var point = new Point({
  2304. x: results.features[0].geometry.extent.center.x - 0,
  2305. y: results.features[0].geometry.extent.center.y - 0,
  2306. spatialReference: m_view.spatialReference
  2307. });
  2308. // m_view.extent = extent;
  2309. m_view.goTo({
  2310. target: point,
  2311. zoom: 8
  2312. }).then(function (ani) {
  2313. // alert("goT");
  2314. });
  2315. isSetMapZoom = true;
  2316. }
  2317. });
  2318. });
  2319. }
  2320. //点生产buffer
  2321. function getBufferByPoint(x, y, radius, layername, m_showGraphic, isGoTo) {
  2322. var buffer;
  2323. require([
  2324. "esri/geometry/Point",
  2325. "esri/geometry/geometryEngine",
  2326. "esri/geometry/Circle"
  2327. ], function (Point, geometryEngine, Circle) {
  2328. var point = new Point({
  2329. x: x - 0,
  2330. y: y - 0,
  2331. spatialReference: m_view.spatialReference
  2332. });
  2333. // buffer = geometryEngine.buffer(point, radius-0, "meters");
  2334. buffer = new Circle({
  2335. radius: radius,
  2336. radiusUnit: "meters",
  2337. center: {
  2338. x: x - 0,
  2339. y: y - 0,
  2340. spatialReference: m_view.spatialReference
  2341. }
  2342. });
  2343. newQuerybyWhereStr("", layername, GetConfigDataByName("MYQueryLayer"), buffer, m_showGraphic, isGoTo);
  2344. });
  2345. // return buffer;
  2346. }
  2347. //得到grid的geometry
  2348. function getGridGeometryByGridID(gridid, Layername) {
  2349. var gridgeo
  2350. require([
  2351. "esri/tasks/FindTask",
  2352. "esri/tasks/support/FindParameters",
  2353. "esri/tasks/IdentifyTask",
  2354. "esri/tasks/support/IdentifyParameters",
  2355. "esri/geometry/Point",
  2356. "esri/tasks/QueryTask", "esri/tasks/support/Query",
  2357. "esri/geometry/Extent",
  2358. "esri/Graphic",
  2359. "esri/geometry/geometryEngine",
  2360. "dojo/on",
  2361. ], function (FindTask, FindParameters, IdentifyTask, IdentifyParameters, Point,
  2362. QueryTask, Query, Extent, Graphic, geometryEngine, on) {
  2363. // dynamicLayerURL = GetConfigDataByName("QueryLayer")+"/250";
  2364. var queryTask = new QueryTask({
  2365. url: GetConfigDataByName("QueryLayer") + "/250"
  2366. });
  2367. var query = new Query();
  2368. query.geometry = null;
  2369. query.outFields = ["*"];
  2370. query.returnGeometry = true;
  2371. //query.geometry = option.geometry || null;
  2372. query.spatialRelationship = "intersects";
  2373. query.where = " 网格编码='" + gridid + "'";
  2374. queryTask.execute(query).then(function (results) {
  2375. if (results.features.length > 0) {
  2376. gridgeo = results.features[0].geometry;
  2377. //queryByGeometryAndLayer(gridgeo,Layername);
  2378. newQuerybyWhereStr("", Layername, GetConfigDataByName("MYQueryLayer"), gridgeo);
  2379. }
  2380. });
  2381. });
  2382. }
  2383. // 网格编码查询
  2384. function identifyTask(point, callbackfun) {
  2385. require([
  2386. "esri/tasks/FindTask",
  2387. "esri/tasks/support/FindParameters",
  2388. "esri/tasks/IdentifyTask",
  2389. "esri/tasks/support/IdentifyParameters",
  2390. "esri/geometry/Point",
  2391. "esri/tasks/QueryTask", "esri/tasks/support/Query",
  2392. "esri/geometry/Extent",
  2393. "esri/Graphic",
  2394. "esri/geometry/geometryEngine",
  2395. "dojo/on"
  2396. ], function (FindTask, FindParameters, IdentifyTask, IdentifyParameters, Point,
  2397. QueryTask, Query, Extent, Graphic, geometryEngine, on) {
  2398. // dynamicLayerURL = GetConfigDataByName("QueryLayer")+"/250";
  2399. var queryTask = new QueryTask({
  2400. url: GetConfigDataByName("QueryLayer") + "/250"
  2401. });
  2402. var query = new Query();
  2403. query.geometry = null;
  2404. query.outFields = ["*"];
  2405. query.returnGeometry = true;
  2406. //query.geometry = option.geometry || null;
  2407. query.spatialRelationship = "intersects";
  2408. query.where = "1=1";
  2409. query.geometry = new Point({
  2410. x: point.split(',')[0] - 0,
  2411. y: point.split(',')[1] - 0,
  2412. spatialReference: m_view.spatialReference
  2413. });
  2414. queryTask.execute(query).then(function (results) {
  2415. if (results.features.length > 0)
  2416. callbackfun(results.features[0].attributes["网格编码"]);
  2417. else {
  2418. callbackfun("error");
  2419. }
  2420. });
  2421. });
  2422. }
  2423. //空间查询展示
  2424. function showQueryResult(idResults) {
  2425. // //创建线符号
  2426. // var lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 100, 100]), 3);
  2427. // //创建面符号
  2428. // var fill = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, lineSymbol,new dojo.Color([0, 0, 0]), 0);
  2429. if (idResults.length > 0) {
  2430. var htmls = "<table style=\"width: 100%\">";
  2431. htmls = htmls + "<tr bgcolor=\"#E0E0E0\"><td> 图层 </td><td> 名 称</td></tr>";
  2432. for (var i = 0; i < idResults.length; i++) {
  2433. var result = idResults[i];
  2434. //获得图形graphic
  2435. var graphic = result.feature;
  2436. //设置图形的符号
  2437. // graphic.setSymbol(lineSymbol );
  2438. var namevalue = result.feature.attributes.Name;
  2439. console.log(namevalue)
  2440. if (i % 2 == 1) {
  2441. htmls = htmls + "<tr bgcolor=\"#E0E0E0\"><td>" +
  2442. result.layerName + "</td>" +
  2443. // "<td>" + namevalue + "</td>" +
  2444. "</tr>";
  2445. }
  2446. else {
  2447. htmls = htmls + "<tr><td>" + result.layerName + "</td><td>"
  2448. + namevalue + "</td></tr>";
  2449. }
  2450. map.graphics.add(graphic);
  2451. }
  2452. htmls = htmls + "</table>";
  2453. document.getElementById("divShowResult").innerHTML = htmls;
  2454. $("#divShowResult").show();
  2455. }
  2456. else {
  2457. document.getElementById("divShowResult").innerHTML = "";
  2458. $("#divShowResult").show();
  2459. }
  2460. }
  2461. // new拖拽地图handle
  2462. var isNewDragHandle = false;
  2463. function myNewDragHandle() {
  2464. var draghandle
  2465. require(["esri/core/watchUtils"],
  2466. function (watchUtils) {
  2467. draghandle = watchUtils.whenTrue(m_view, "drag", function (event) {
  2468. if (event.action == 'end') {
  2469. }
  2470. else {
  2471. var xmax = m_view.extent.xmax;
  2472. var xmin = m_view.extent.xmin;
  2473. var ymax = m_view.extent.ymax;
  2474. var ymin = m_view.extent.ymin;
  2475. var precision = 70;
  2476. var hasChanged = false;
  2477. if (viewxmin - xmin > precision) {
  2478. hasChanged = true;
  2479. }
  2480. if (viewymin - ymin > precision) {
  2481. hasChanged = true;
  2482. }
  2483. if (xmax - viewymax > precision) {
  2484. hasChanged = true;
  2485. }
  2486. if (ymax - viewymax > precision) {
  2487. hasChanged = true;
  2488. }
  2489. if (hasChanged) {
  2490. event.stopPropagation();
  2491. isNewDragHandle = true;
  2492. }
  2493. }
  2494. });
  2495. });
  2496. return draghandle;
  2497. }
  2498. var sj_type = 0;// 0 关闭 1 地址 2 部件 3 地址部件
  2499. //x,y,radius,layername,m_showGraphic,isGoTo
  2500. var sj_radius;
  2501. var sj_layername;
  2502. var sj_X;
  2503. var sj_Y;
  2504. var sjDraging = false;
  2505. function sj_mapResize() {
  2506. switch (sj_type) {
  2507. case 0:
  2508. {
  2509. return;
  2510. break;
  2511. }
  2512. case 1:
  2513. {
  2514. GetAddressByXY(m_view.center.x, m_view.center.y, 50);
  2515. break;
  2516. }
  2517. case 2:
  2518. case 3:
  2519. {
  2520. if (sj_type == 3) {
  2521. GetAddressByXY(m_view.center.x, m_view.center.y, 50);
  2522. }
  2523. var layerId = GetFeatureLayerIdbyName(sj_layername);
  2524. if (layerId == -1) {
  2525. // alert("没有此图层");
  2526. window.parent.postMessage(
  2527. {
  2528. method: "queryByGeometryAndLayer",
  2529. data: ["没有此图层"]
  2530. },
  2531. '*'
  2532. );
  2533. } else {
  2534. require([
  2535. "esri/geometry/Point",
  2536. "esri/geometry/geometryEngine",
  2537. "esri/geometry/Circle",
  2538. "esri/layers/FeatureLayer"
  2539. ], function (Point, geometryEngine, Circle, FeatureLayer) {
  2540. var buffer = new Circle({
  2541. radius: sj_radius,
  2542. radiusUnit: "meters",
  2543. center: {
  2544. x: m_view.center.x - 0,
  2545. y: m_view.center.y - 0,
  2546. spatialReference: m_view.spatialReference
  2547. }
  2548. });
  2549. var quakesUrl = dyLayer.url + "/" + layerId;
  2550. var quakesLayer = new FeatureLayer({
  2551. url: quakesUrl,
  2552. outFields: ["*"],
  2553. visible: false
  2554. });
  2555. var query = quakesLayer.createQuery();
  2556. // query.where = "mag >= " + magSlider.values[0];
  2557. query.geometry = buffer;
  2558. query.spatialRelationship = "intersects";
  2559. quakesLayer.queryFeatures(query).then(function (results) {
  2560. // var test = results;
  2561. var attributesArr = [];
  2562. if (results.features.length == 0) {
  2563. window.parent.postMessage(
  2564. {
  2565. method: "queryByGeometryAndLayer",
  2566. data: []
  2567. },
  2568. '*'
  2569. );
  2570. return;
  2571. }
  2572. for (var i = 0; i < results.features.length; i++) {
  2573. attributesArr.push(results.features[i].attributes);
  2574. }
  2575. window.parent.postMessage(
  2576. {
  2577. method: "queryByGeometryAndLayer",
  2578. data: [attributesArr]
  2579. },
  2580. '*'
  2581. );
  2582. });
  2583. ;
  2584. });
  2585. }
  2586. break;
  2587. }
  2588. }
  2589. }
  2590. function GetAddressByXY(x, y, radius) {
  2591. var layerId = GetFeatureLayerIdbyName("门牌");
  2592. require([
  2593. "esri/geometry/Point",
  2594. "esri/geometry/geometryEngine",
  2595. "esri/geometry/Circle",
  2596. "esri/layers/FeatureLayer"
  2597. ], function (Point, geometryEngine, Circle, FeatureLayer) {
  2598. // x = m_view.center.x;
  2599. // y = m_view.center.y;
  2600. // x = 0;
  2601. // y = 0;
  2602. var buffer = new Circle({
  2603. radius: radius - 0,
  2604. radiusUnit: "meters",
  2605. center: {
  2606. x: x - 0,
  2607. y: y - 0,
  2608. spatialReference: m_view.spatialReference
  2609. }
  2610. });
  2611. var quakesUrl = dyLayer.url + "/" + "253";//layerId;
  2612. var quakesLayer = new FeatureLayer({
  2613. url: quakesUrl,
  2614. outFields: ["*"],
  2615. visible: false
  2616. });
  2617. var query = quakesLayer.createQuery();
  2618. // query.where = "mag >= " + magSlider.values[0];
  2619. query.geometry = buffer;
  2620. query.spatialRelationship = "intersects";
  2621. quakesLayer.queryFeatures(query).then(function (results) {
  2622. // var test = results;
  2623. var attributesArr = [];
  2624. if (results.features.length == 0) {
  2625. if (radius == 50) {
  2626. GetAddressByXY(x, y, 200);
  2627. }
  2628. else {
  2629. window.parent.postMessage(
  2630. {
  2631. method: "addressdataCallback",
  2632. data: []
  2633. },
  2634. '*'
  2635. );
  2636. }
  2637. return;
  2638. }
  2639. for (var i = 0; i < results.features.length; i++) {
  2640. attributesArr.push(results.features[i]);
  2641. }
  2642. function sortAttributesArr(a, b) {
  2643. var dx = Math.abs(x - a.geometry.x);
  2644. var dy = Math.abs(y - a.geometry.y);
  2645. var dis = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
  2646. var dx1 = Math.abs(x - b.geometry.x);
  2647. var dy1 = Math.abs(y - b.geometry.y);
  2648. var dis1 = Math.sqrt(Math.pow(dx1, 2) + Math.pow(dy1, 2));
  2649. return dis - dis1;
  2650. }
  2651. attributesArr.sort(sortAttributesArr);
  2652. var addressdata = [];
  2653. addressdata.push(attributesArr[0].attributes.道路名 + ' ' +
  2654. attributesArr[0].attributes.门牌号 + ' ' + attributesArr[0].attributes.名称);
  2655. var temp = 5;
  2656. // if(attributesArr.length<5){
  2657. // temp = attributesArr.length;
  2658. // }
  2659. // for(var i =0;i<temp;i++){
  2660. // addressdata.push(attributesArr[i].attributes);
  2661. // }
  2662. window.parent.postMessage(
  2663. {
  2664. method: "addressdataCallback",
  2665. data: [addressdata]
  2666. },
  2667. '*'
  2668. );
  2669. });
  2670. ;
  2671. });
  2672. }
  2673. function ShowPolygonandText(type, name, text) {
  2674. var layername;
  2675. var typename;
  2676. var layer;
  2677. var layerId;
  2678. if (type == 1) {
  2679. layername = "街道乡镇";
  2680. typename = "街道名称";
  2681. layer = getLayerByLayerId("动态数据");
  2682. layerId = getSubLayerIdbyName(layer, "街道乡镇");
  2683. }
  2684. else if (type == 2) {
  2685. layername = "村居委会";
  2686. typename = "名称";
  2687. layer = getLayerByLayerId("density_1");
  2688. layerId = getSubLayerIdbyName(layer, layername);
  2689. }
  2690. if (layerId == -1)
  2691. return;
  2692. // 街道名称: 万祥镇
  2693. require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom", "esri/Graphic",
  2694. "esri/geometry/Point"],
  2695. function (QueryTask, Query, FeatureLayer, arrayUtils, dom, Graphic, Point) {
  2696. var urlI = dyLayer.url + "/" + layerId;
  2697. var qTask = new QueryTask({
  2698. url: layer.url + "/" + layerId
  2699. });
  2700. var params = new Query({
  2701. geometry: queryExtent,
  2702. returnGeometry: true,
  2703. outFields: ["*"]
  2704. });
  2705. // params.spatialRelationship = "intersects";
  2706. // params.geometry = geo || null;
  2707. params.where = typename + "='" + name + "'";
  2708. qTask.execute(params).then(getResults).otherwise(promiseRejected);
  2709. function getResults(response) {
  2710. if (response.features.length == 0) {
  2711. return;
  2712. }
  2713. var polygon = response.features[0].geometry;
  2714. var fillSymbol = {
  2715. type: "simple-fill",
  2716. color: [255, 255, 255, 0],
  2717. style: "solid",
  2718. outline: {
  2719. color: [255, 0, 0],
  2720. width: 3
  2721. }
  2722. };
  2723. var polygonGraphic = new Graphic({
  2724. geometry: polygon,
  2725. symbol: fillSymbol,
  2726. });
  2727. var point = point = {
  2728. type: "point",
  2729. x: polygon.extent.center.x,
  2730. y: polygon.extent.center.y,
  2731. spatialReference: m_view.spatialReference
  2732. };
  2733. // var textSymbol = {
  2734. // type: "text", // autocasts as new TextSymbol()
  2735. // color: [0,255,0],
  2736. // text: text, // esri-icon-map-pin
  2737. // font: {
  2738. // // autocasts as new Font()
  2739. // size: 36,
  2740. // family: "CalciteWebCoreIcons"
  2741. // }
  2742. // };
  2743. var textSymbol = {
  2744. type: "text", // autocasts as new TextSymbol()
  2745. color: "black",
  2746. text: text,
  2747. font: { // autocasts as new Font()
  2748. size: 14,
  2749. weight: "bold"
  2750. }
  2751. };
  2752. var pointGraphic = new Graphic({
  2753. geometry: point,
  2754. symbol: textSymbol
  2755. });
  2756. GraphicsLayer_myLayer.add(polygonGraphic);
  2757. GraphicsLayer_myLayer.add(pointGraphic);
  2758. // m_view.goTo(pointGraphic);
  2759. }
  2760. function promiseRejected(err) {
  2761. console.error("错误信息: ", err.message);
  2762. }
  2763. });
  2764. }
  2765. //高亮边界
  2766. function highLightArea(layerName, where, colorList, orderField) {
  2767. // var layerId = GetFeatureLayerIdbyName(layerName);
  2768. var layer = getLayerByLayerId("density_1");
  2769. var layerId = getSubLayerIdbyName(layer, layerName);
  2770. if (!where) {
  2771. where = "1=1";
  2772. }
  2773. if (layerId == -1)
  2774. return;
  2775. require(["esri/tasks/QueryTask", "esri/tasks/support/Query", "esri/layers/FeatureLayer", "dojo/_base/array", "dojo/dom", "esri/Graphic",
  2776. "esri/geometry/Point"],
  2777. function (QueryTask, Query, FeatureLayer, arrayUtils, dom, Graphic, Point) {
  2778. var polygonGraphicArray = [];
  2779. var pointGraphicArray = [];
  2780. var urlI = layer.url + "/" + layerId;
  2781. var qTask = new QueryTask({
  2782. url: urlI
  2783. });
  2784. var params = new Query({
  2785. returnGeometry: true,
  2786. outFields: ["*"]
  2787. });
  2788. // params.spatialRelationship = "intersects";
  2789. // params.geometry = geo || null;
  2790. params.where = where;
  2791. qTask.execute(params).then(getResults).catch(promiseRejected);
  2792. function getResults(response) {
  2793. var popArray=[];
  2794. if (response.features.length == 0) {
  2795. return;
  2796. }
  2797. var textColor3="rgba(0, 0, 0, 0.5) "
  2798. $.each(response.features, function (index, feature) {
  2799. var color = [255, 0, 0, 0.5];
  2800. var textColor = "black";
  2801. var textColor2="black";
  2802. var text = "";
  2803. var text2="";
  2804. var text3="";
  2805. if (orderField) {
  2806. for (var i = 0; i < colorList.length; i++) {
  2807. if (colorList[i].name == feature.attributes[orderField]) {
  2808. color = colorList[i].color;
  2809. text = colorList[i].text;
  2810. if (colorList[i].textColor) {
  2811. textColor = colorList[i].textColor
  2812. }
  2813. if (colorList[i].textColor2) {
  2814. textColor2 = colorList[i].textColor2
  2815. }
  2816. if (colorList[i].textColor3) {
  2817. textColor3 = colorList[i].textColor3
  2818. }
  2819. if (colorList[i].text2) {
  2820. text2 = colorList[i].text2;
  2821. }
  2822. if (colorList[i].text3) {
  2823. text3 = colorList[i].text3;
  2824. }
  2825. }
  2826. }
  2827. }
  2828. var geometry = feature.geometry;
  2829. var fillSymbol;
  2830. if (geometry.type == "polygon") {
  2831. fillSymbol = {
  2832. type: "simple-fill", // autocasts as new SimpleFillSymbol()
  2833. color: color,
  2834. style: "solid",
  2835. outline: { // autocasts as new SimpleLineSymbol()
  2836. color:color,
  2837. width: 2
  2838. }
  2839. };
  2840. } else {
  2841. if (geometry.type == "polyline") {
  2842. fillSymbol = {
  2843. type: "simple-line",
  2844. color: color,
  2845. width: 3
  2846. };
  2847. } else {
  2848. if (geometry.type == "point") {
  2849. fillSymbol = {
  2850. type: "simple-marker",
  2851. color: color,
  2852. style: "circle",
  2853. size: 10
  2854. };
  2855. }
  2856. }
  2857. }
  2858. var polygonGraphic = new Graphic({
  2859. geometry: geometry,
  2860. symbol: fillSymbol,
  2861. attributes: feature.attributes
  2862. });
  2863. var point = {
  2864. type: "point",
  2865. x: geometry.extent.center.x,
  2866. y: geometry.extent.center.y,
  2867. z:30,
  2868. spatialReference: m_view.spatialReference
  2869. };
  2870. var point2 = {
  2871. type: "point",
  2872. x: geometry.extent.center.x,
  2873. y: geometry.extent.center.y,
  2874. spatialReference: m_view.spatialReference
  2875. };
  2876. var textSymbol = {
  2877. type: "text", // autocasts as new TextSymbol()
  2878. color: textColor,
  2879. text: text,
  2880. font: { // autocasts as new Font()
  2881. size: 14,
  2882. weight: "bold"
  2883. }
  2884. };
  2885. var pointGraphic = new Graphic({
  2886. geometry: point,
  2887. symbol: textSymbol,
  2888. attributes: feature.attributes
  2889. });
  2890. var textSymbol2 = {
  2891. type: "text", // autocasts as new TextSymbol()
  2892. color: textColor2,
  2893. text: text2,
  2894. font: { // autocasts as new Font()
  2895. size: 14
  2896. },
  2897. yoffset: "-25px"
  2898. };
  2899. var pointGraphic2 = new Graphic({
  2900. geometry: point2,
  2901. symbol: textSymbol2
  2902. });
  2903. polygonGraphicArray.push(polygonGraphic);
  2904. pointGraphicArray.push(pointGraphic);
  2905. pointGraphicArray.push(pointGraphic2);
  2906. if(text3!=""){
  2907. popArray.push({
  2908. //地图坐标
  2909. x: geometry.extent.center.x,
  2910. y: geometry.extent.center.y,
  2911. //popup内容的文字,只是个示范,当然格式不限
  2912. content: text3,
  2913. //气泡窗口div的id唯一标识
  2914. id: "areaHigh_"+index
  2915. })
  2916. }
  2917. });
  2918. if(popArray.length>0){
  2919. popupCloseAll();
  2920. popupInfos = [];
  2921. popupInit(popArray,false);
  2922. $(".leaflet-popup-content-wrapper").css("cssText","background-color:" +textColor3+ "!important;");
  2923. $(".leaflet-popup-tip").css("cssText","background-color:" +textColor3+ "!important; ");
  2924. }
  2925. GraphicsLayer_myLayer.removeAll();
  2926. GraphicsLayer_myLayer.addMany(polygonGraphicArray);
  2927. GraphicsLayer_myLayer.addMany(pointGraphicArray);
  2928. // m_view.goTo(polygonGraphicArray);
  2929. }
  2930. function promiseRejected(err) {
  2931. console.error("错误信息: ", err.message);
  2932. }
  2933. });
  2934. }
  2935. function goToZoom(x, y) {
  2936. require(["esri/Camera", "esri/geometry/Point", "esri/Graphic"], function (Camera, Point, Graphic) {
  2937. var pt = new Point({
  2938. x: x - 0,
  2939. y: y - 0,
  2940. spatialReference: m_view.spatialReference
  2941. });
  2942. var pointGraphic = new Graphic({
  2943. geometry: pt
  2944. });
  2945. m_view.goTo({
  2946. target: pointGraphic
  2947. });
  2948. })
  2949. }
  2950. //echarts layer
  2951. var chartLayer;
  2952. var chartLayerSize;
  2953. //迁移图
  2954. function echartsRoute(dataArray, color, imgSrc, imgsize) {
  2955. var series = [];
  2956. if (!color) {
  2957. color = "#FF0000";
  2958. }
  2959. if (!imgsize) {
  2960. imgsize = 40
  2961. }
  2962. chartLayerSize = imgsize;
  2963. imgsize = chartLayerSize - (chartLayerSize * (12 - m_view.zoom) * 0.05);//zoom每级差5%
  2964. if (!imgSrc) {
  2965. imgSrc = "circle";
  2966. }
  2967. else {
  2968. imgSrc = "image://" + imgSrc;
  2969. }
  2970. if (dataArray.length == 0) {
  2971. return;
  2972. }
  2973. dataArray.forEach(function (item, i) {
  2974. series.push({
  2975. name: item[0] + ' Top10',
  2976. type: 'lines',
  2977. coordinateSystem: 'arcgis',
  2978. zlevel: 1,
  2979. effect: {
  2980. show: true,
  2981. period: 6,
  2982. trailLength: 0.7,
  2983. color: '#fff',
  2984. symbolSize: 3
  2985. },
  2986. lineStyle: {
  2987. normal: {
  2988. color: color,
  2989. width: 0,
  2990. curveness: 0.2
  2991. }
  2992. },
  2993. data: convertData(item)
  2994. },
  2995. {
  2996. name: item[0] + ' Top10',
  2997. type: 'lines',
  2998. coordinateSystem: 'arcgis',
  2999. zlevel: 2,
  3000. symbol: ['none', 'arrow'],
  3001. symbolSize: 10,
  3002. effect: {
  3003. show: true,
  3004. period: 6,
  3005. trailLength: 0,
  3006. symbol: imgSrc,
  3007. symbolSize: imgsize
  3008. },
  3009. lineStyle: {
  3010. normal: {
  3011. color: color,
  3012. width: item[1].width? item[1].width:1,
  3013. opacity: 0.6,
  3014. curveness: 0.2
  3015. }
  3016. },
  3017. data: convertData(item)
  3018. }
  3019. );
  3020. });
  3021. require([
  3022. "lib/echartsLayer"
  3023. ], function (echartsLayer) {
  3024. chartLayer = new echartsLayer(m_view);
  3025. var option = {
  3026. series: series
  3027. };
  3028. chartLayer.setChartOption(option);
  3029. });
  3030. //console.log(echarts);
  3031. }
  3032. var chartLayer2;
  3033. function echartsWaterSourceToWorkRoute(dataArray, color, imgSrc, imgsize) {
  3034. var series = [];
  3035. if (!color) {
  3036. color = "#FF0000";
  3037. }
  3038. if (!imgsize) {
  3039. imgsize = 40
  3040. }
  3041. chartLayerSize = imgsize;
  3042. // imgsize = chartLayerSize - (chartLayerSize * (12 - m_view.zoom) * 0.05);//zoom每级差5%
  3043. if (!imgSrc) {
  3044. imgSrc = "circle";
  3045. }
  3046. else {
  3047. imgSrc = "image://" + imgSrc;
  3048. }
  3049. if (dataArray.length == 0) {
  3050. return;
  3051. }
  3052. dataArray.forEach(function (item, i) {
  3053. series.push({
  3054. name: item[0] + ' Top10',
  3055. type: 'lines',
  3056. coordinateSystem: 'arcgis',
  3057. zlevel: 1,
  3058. effect: {
  3059. show: true,
  3060. period: 6,
  3061. trailLength: 0.7,
  3062. color: color,
  3063. symbol:'rect',
  3064. symbolSize: imgsize
  3065. },
  3066. lineStyle: {
  3067. normal: {
  3068. color: color,
  3069. width: 0,
  3070. curveness: 0.2
  3071. }
  3072. },
  3073. data: convertData(item)
  3074. },
  3075. {
  3076. name: item[0] + ' Top10',
  3077. type: 'lines',
  3078. coordinateSystem: 'arcgis',
  3079. zlevel: 2,
  3080. symbol: ['none', 'arrow'],
  3081. symbolSize: 10,
  3082. effect: {
  3083. show: true,
  3084. period: 6,
  3085. trailLength: 0,
  3086. symbol: imgSrc,
  3087. symbolSize: imgsize
  3088. },
  3089. lineStyle: {
  3090. normal: {
  3091. color: color,
  3092. width: 1,
  3093. opacity: 0.6,
  3094. curveness: 0.2
  3095. }
  3096. },
  3097. data: convertData(item)
  3098. }
  3099. );
  3100. });
  3101. require([
  3102. "lib/echartsLayer"
  3103. ], function (echartsLayer) {
  3104. chartLayer2 = new echartsLayer(m_view);
  3105. var option = {
  3106. series: series
  3107. };
  3108. chartLayer2.setChartOption(option);
  3109. });
  3110. }
  3111. var chartLayer3;
  3112. function echartsWaterWorkToAreaRoute(dataArray, color, imgSrc, imgsize) {
  3113. var series = [];
  3114. if (!color) {
  3115. color = "#FF0000";
  3116. }
  3117. if (!imgsize) {
  3118. imgsize = 40
  3119. }
  3120. chartLayerSize = imgsize;
  3121. // imgsize = chartLayerSize - (chartLayerSize * (12 - m_view.zoom) * 0.05);//zoom每级差5%
  3122. if (!imgSrc) {
  3123. imgSrc = "circle";
  3124. }
  3125. else {
  3126. imgSrc = "image://" + imgSrc;
  3127. }
  3128. if (dataArray.length == 0) {
  3129. return;
  3130. }
  3131. dataArray.forEach(function (item, i) {
  3132. series.push({
  3133. name: item[0] + ' Top10',
  3134. type: 'lines',
  3135. coordinateSystem: 'arcgis',
  3136. zlevel: 1,
  3137. effect: {
  3138. show: true,
  3139. period: 6,
  3140. trailLength: 0.7,
  3141. color: color,
  3142. symbol:'rect',
  3143. symbolSize: imgsize
  3144. },
  3145. lineStyle: {
  3146. normal: {
  3147. color: color,
  3148. width: 0,
  3149. curveness: 0.2
  3150. }
  3151. },
  3152. data: convertData(item)
  3153. },
  3154. {
  3155. name: item[0] + ' Top10',
  3156. type: 'lines',
  3157. coordinateSystem: 'arcgis',
  3158. zlevel: 2,
  3159. symbol: ['none', 'arrow'],
  3160. symbolSize: 10,
  3161. effect: {
  3162. show: true,
  3163. period: 6,
  3164. trailLength: 0,
  3165. symbol: imgSrc,
  3166. symbolSize: imgsize
  3167. },
  3168. lineStyle: {
  3169. normal: {
  3170. color: color,
  3171. width: 1,
  3172. opacity: 0.6,
  3173. curveness: 0.2
  3174. }
  3175. },
  3176. data: convertData(item)
  3177. }
  3178. );
  3179. });
  3180. require([
  3181. "lib/echartsLayer"
  3182. ], function (echartsLayer) {
  3183. chartLayer3 = new echartsLayer(m_view);
  3184. var option = {
  3185. series: series
  3186. };
  3187. chartLayer3.setChartOption(option);
  3188. });
  3189. //console.log(echarts);
  3190. }
  3191. var convertData = function (data) {
  3192. var res = [];
  3193. for (var i = 0; i < data.length; i++) {
  3194. var fromCoord = data[0].xy;
  3195. var toCoord = data[1].xy;
  3196. res.push({
  3197. fromName: data[0].name,
  3198. toName: data[1].name,
  3199. coords: [fromCoord, toCoord],
  3200. value: data[1].value
  3201. });
  3202. }
  3203. return res;
  3204. };
  3205. //气泡
  3206. var popupInfos = [];
  3207. //初始化列表
  3208. function popupInit(popupInfoArray, hasX) {
  3209. m_view.when(function () {
  3210. //监听地图变化事件,对应刷新气泡窗口位置
  3211. m_view.watch("extent", function () {
  3212. relocatePopup();
  3213. });
  3214. m_view.watch("rotation", function () {
  3215. relocatePopup();
  3216. });
  3217. //地图加载完,初始化气泡窗口
  3218. });
  3219. //popup初始化
  3220. popupInfos = popupInfoArray;
  3221. for (var i = 0; i < popupInfos.length; i++) {
  3222. var popupInfo = popupInfos[i];
  3223. //坐标转换
  3224. var mapPoint = {
  3225. x: popupInfo.x,
  3226. y: popupInfo.y,
  3227. spatialReference: m_view.spatialReference
  3228. };
  3229. var screenPoint = m_view.toScreen(mapPoint);
  3230. var obj = {};
  3231. obj.x = screenPoint.x;
  3232. obj.y = screenPoint.y;
  3233. obj.content = popupInfo.content;
  3234. obj.id = popupInfo.id;
  3235. loadinfoWindow(obj, hasX);
  3236. }
  3237. }
  3238. function relocatePopup(e) {
  3239. for (var i = 0; i < popupInfos.length; i++) {
  3240. var popupInfo = popupInfos[i];
  3241. //坐标转换
  3242. var mapPoint = {
  3243. x: popupInfo.x,
  3244. y: popupInfo.y,
  3245. spatialReference: m_view.spatialReference
  3246. }
  3247. var screenPoint = m_view.toScreen(mapPoint);
  3248. var obj = {};
  3249. obj.x = screenPoint.x;
  3250. obj.y = screenPoint.y;
  3251. obj.content = popupInfo.content;
  3252. obj.id = popupInfo.id;
  3253. //刷新气泡窗口位置
  3254. positionPopUp(obj);
  3255. }
  3256. }
  3257. //显示所有气泡窗口
  3258. function popupShowAll() {
  3259. for (var i = 0; i < popupInfos.length; i++) {
  3260. var popupInfo = popupInfos[i];
  3261. showinfoWindow(popupInfo.id);
  3262. }
  3263. }
  3264. //隐藏所有气泡窗口
  3265. function popupCloseAll(id) {
  3266. if(!id){
  3267. id="";
  3268. }
  3269. if (popupInfos.length > 0) {
  3270. if(id=="viewClick"){
  3271. if(popupInfos[0].id){
  3272. if(popupInfos[0].id.indexOf("areaHigh_")!=-1){
  3273. return
  3274. }
  3275. }
  3276. }
  3277. postToParentPageMethed("closePopupReturn", []);
  3278. }
  3279. for (var i = 0; i < popupInfos.length; i++) {
  3280. var popupInfo = popupInfos[i];
  3281. hideinfoWindow(popupInfo.id);
  3282. }
  3283. popupInfos = [];
  3284. }
  3285. function closePopupReturn(obj) {
  3286. postToParentPageMethed("closePopupReturn", [obj]);
  3287. }
  3288. function loadinfoWindow(obj, hasX) {
  3289. var xStr = "";
  3290. if (hasX) {
  3291. xStr = '<a class="leaflet-popup-close-button" id="leaflet-popup-close' + obj.id + '" href="#" onclick="closePopupReturn(&apos;' + obj.id +
  3292. '&apos;)">×</a>'
  3293. }
  3294. //动态添加气泡窗口DIV
  3295. var infoDiv = '<div id="trackPopUp' + obj.id + '" class="leaflet-popup">' +
  3296. '' + xStr +
  3297. '<div class="leaflet-popup-content-wrapper">' +
  3298. '<div id="' + obj.id + '" class="leaflet-popup-content" style=" "></div>' +
  3299. '</div>' +
  3300. '<div class="leaflet-popup-tip-container">' +
  3301. '<div class="leaflet-popup-tip"></div>' +
  3302. '</div>' +
  3303. '</div>';
  3304. $("#mapDiv").append(infoDiv);
  3305. //填充内容
  3306. $('#' + obj.id).append(obj.content);
  3307. //刷新气泡窗口位置
  3308. positionPopUp(obj);
  3309. //气泡窗口关闭事件
  3310. $('#leaflet-popup-close' + obj.id).click(function () {
  3311. $('#trackPopUp' + obj.id).remove();
  3312. for (var i = popupInfos.length - 1; i >= 0; i--) {
  3313. if (obj.id == popupInfos[i].id) {
  3314. popupInfos.splice(i, 1);
  3315. }
  3316. }
  3317. });
  3318. }
  3319. //显示指定气泡窗口
  3320. function showinfoWindow(id) {
  3321. $('#trackPopUp' + id).show();
  3322. }
  3323. //隐藏指定气泡窗口
  3324. function hideinfoWindow(id) {
  3325. $('#trackPopUp' + id).remove();
  3326. }
  3327. function positionPopUp(obj) {
  3328. var o = document.getElementById("trackPopUp" + obj.id);
  3329. var w = o.clientWidth || o.offsetWidth;
  3330. var h = o.clientHeight || o.offsetHeight;
  3331. $('#trackPopUp' + obj.id).css('transform', 'translate3d(' + (obj.x - (w / 2)) + 'px, ' + (obj.y - (h)) + 'px, 0)');
  3332. }
  3333. function colorRgba(sHex, alpha) {
  3334. // 十六进制颜色值的正则表达式
  3335. var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
  3336. /* 16进制颜色转为RGB格式 */
  3337. var sColor = sHex.toLowerCase()
  3338. if (sColor && reg.test(sColor)) {
  3339. if (sColor.length === 4) {
  3340. var sColorNew = '#'
  3341. for (var i = 1; i < 4; i += 1) {
  3342. sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1))
  3343. }
  3344. sColor = sColorNew
  3345. }
  3346. // 处理六位的颜色值
  3347. var sColorChange = []
  3348. for (var i = 1; i < 7; i += 2) {
  3349. sColorChange.push(parseInt('0x' + sColor.slice(i, i + 2)))
  3350. }
  3351. // return sColorChange.join(',')
  3352. // 或
  3353. return 'rgba(' + sColorChange.join(',') + ',' + alpha + ')'
  3354. } else {
  3355. return sColor;
  3356. }
  3357. }