MapClass4.js 139 KB

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