各位看到这个标题不要嫌烦,因为本人最近一直在研究相关的问题,所以相关文章也只能是这些,同时希望看过我的文章的朋友,我的文章能够给你帮助。

在前面的两篇相关的文章里面,实现InfoWindow是通过div的东西实现的,本文要讲的是通过集成InfoWindowBase实现infowindow的。实现后InfoWindow主要修改了arcgis原来的样式,并加入了InfoWindow出界的处理。

源代码奉上:

InfoWindow.js

  1. define([
  2. "dojo/Evented",
  3. "dojo/parser",
  4. "dojo/on",
  5. "dojo/_base/declare",
  6. "dojo/dom-construct",
  7. "dojo/_base/array",
  8. "dojo/dom-style",
  9. "dojo/_base/lang",
  10. "dojo/dom-class",
  11. "dojo/fx",
  12. "dojo/Deferred",
  13. "esri/domUtils",
  14. "esri/InfoWindowBase"
  15. ],
  16. function(
  17. Evented,
  18. parser,
  19. on,
  20. declare,
  21. domConstruct,
  22. array,
  23. domStyle,
  24. lang,
  25. domClass,
  26. coreFx,
  27. Deferred,
  28. domUtils,
  29. InfoWindowBase
  30. )
  31. {
  32. var infoWidth,infoHeight;
  33. var initMapCenter,initScreenCenter;
  34. var showMapPoint,showScreenPoint=null;
  35.  
  36. return declare([InfoWindowBase, Evented],
  37. {
  38. constructor: function(parameters)
  39. {
  40. lang.mixin(this, parameters);
  41. domClass.add(this.domNode, "myInfoWindow");
  42. this._closeButton = domConstruct.create("div",{"class": "close", "title": "关闭"}, this.domNode);
  43. this._title = domConstruct.create("div",{"class": "title"}, this.domNode);
  44. this._content = domConstruct.create("div",{"class": "content"}, this.domNode);
  45. this._arrow = domConstruct.create("div",{"class": "arrow"}, this.domNode);
  46. on(this._closeButton, "click", lang.hitch(this, function(){
  47. //hide the content when the info window is toggled close.
  48. this.hide();
  49. }));
  50. //hide initial display
  51. domUtils.hide(this.domNode);
  52. this.isShowing = false;
  53. },
  54. setMap: function(map)
  55. {
  56. this.inherited(arguments);
  57. map.on("pan", lang.hitch(this, function(pan){
  58. var movePoint=pan.delta;
  59. if(this.isShowing)
  60. {
  61. if(showScreenPoint!=null)
  62. {
  63. this._showInfoWindow(showScreenPoint.x+movePoint.x,showScreenPoint.y+movePoint.y);
  64. }
  65. }
  66. }));
  67. map.on("pan-end", lang.hitch(this, function(panend){
  68. var movedelta=panend.delta;
  69. if(this.isShowing){
  70. showScreenPoint.x=showScreenPoint.x+movedelta.x;
  71. showScreenPoint.y=showScreenPoint.y+movedelta.y;
  72. }
  73. }));
  74. map.on("zoom-start", lang.hitch(this, function(){
  75. domUtils.hide(this.domNode);
  76. this.onHide();
  77. }));
  78. map.on("zoom-end", lang.hitch(this, function(){
  79. if(this.isShowing){
  80. showScreenPoint=this.map.toScreen(showMapPoint);
  81. this._showInfoWindow(showScreenPoint.x,showScreenPoint.y);
  82. }
  83. }));
  84. },
  85. setTitle: function(title){
  86. this.place(title, this._title);
  87. },
  88. setContent: function(content){
  89. this.place(content, this._content);
  90. },
  91. _showInfoWindow:function(x,y)
  92. {
  93. //Position 10x10 pixels away from the specified location
  94. domStyle.set(this.domNode,{
  95. "left": x - infoWidth/2 + 15 + "px",
  96. "top": y - infoHeight-75 + "px"
  97. });
  98. //display the info window
  99. domUtils.show(this.domNode);
  100. },
  101. show: function(location)
  102. {
  103. showMapPoint=location;
  104.  
  105. initMapCenter=this.map.extent.getCenter();
  106. initScreenCenter=this.map.toScreen(initMapCenter);
  107.  
  108. infoHeight= $(".myInfoWindow").height();
  109. infoWidth= $(".myInfoWindow").width();
  110.  
  111. if(location.spatialReference){
  112. location = this.map.toScreen(location);
  113. }
  114.  
  115. var left=location.x-infoWidth/2;
  116. var top=location.y-infoHeight-75;
  117. showScreenPoint=location;
  118.  
  119. if(top<5)
  120. {
  121. initScreenCenter.y=initScreenCenter.y+top-5;
  122. }
  123. if(left<5)
  124. {
  125. initScreenCenter.x=initScreenCenter.x+left-5;
  126. }
  127. this._showInfoWindow(showScreenPoint.x,showScreenPoint.y);
  128. initMapCenter=this.map.toMap(initScreenCenter);
  129. this.map.centerAt(initMapCenter);
  130. this.isShowing = true;
  131. this.onShow();
  132. },
  133. hide: function(){
  134. domUtils.hide(this.domNode);
  135. this.isShowing = false;
  136. this.onHide();
  137. },
  138. resize: function(width, height){
  139. domStyle.set(this._content,{
  140. "width": width + "px",
  141. "height": (height-60) + "px"
  142. });
  143. domStyle.set(this._title,{
  144. "width": width + "px"
  145. });
  146. },
  147. destroy: function(){
  148. domConstruct.destroy(this.domNode);
  149. this._closeButton = this._title = this._content = null;
  150. }
  151. });
  152. return InfoWindow;
  153. });

InfoWindow.js

  1. .myInfoWindow {
  2. position: absolute;
  3. z-index: 100;
  4. font-family: sans-serif;
  5. font-size: 12px;
  6. }
  7.  
  8. .dj_ie .myInfoWindow {
  9. border: 1px solid black;
  10. }
  11.  
  12. .myInfoWindow .content {
  13. position: relative;
  14. background-color:#EFECCA;
  15. color:#002F2F;
  16. overflow: auto;
  17. padding-top:5px;
  18. padding-bottom:5px;
  19. padding-left:5px;
  20. }
  21.  
  22. .myInfoWindow .arrow {
  23. position: absolute;
  24. width: 0px;
  25. height: 0px;
  26. line-height: 0px;/*为了防止ie下出现题型*/
  27. border-top: 60px solid #EFECCA;
  28. border-left: 5px solid transparent;
  29. border-right: 20px solid transparent;
  30. left: 45%;
  31. bottom: -60px;
  32. }
  33.  
  34. .myInfoWindow .close {
  35. position: absolute; top: 7px; right: 5px;
  36. cursor: pointer;
  37. background: url(http://serverapi.arcgisonline.com/jsapi/arcgis/2.6/js/dojo/dijit/themes/claro/layout/images/tabClose.png) no-repeat scroll 0 0 transparent;
  38. width: 12px; height: 12px;
  39. }
  40.  
  41. .myInfoWindow .close:hover {
  42. background-color: #F7FCFF;
  43. }
  44.  
  45. .myInfoWindow .title {
  46. font-weight: bold;
  47. background-color:#046380;
  48. color:#E6E2AF;
  49. padding-top:5px;
  50. padding-bottom:5px;
  51. padding-left:5px;
  52. }

test.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <!--The viewport meta tag is used to improve the presentation and behavior
  6. of the samples on iOS devices-->
  7. <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  8. <title>Custom Info Window</title>
  9. <link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
  10. <link rel="stylesheet" href="myModules/InfoWindow.css">
  11. <style>
  12. html, body, #mapDiv { height: 100%; width: 100%; margin: 0; padding: 0; }
  13.  
  14. </style>
  15.  
  16. <script>
  17. var dojoConfig = {
  18. parseOnLoad:true,
  19. packages: [{
  20. "name": "myModules",
  21. "location": location.pathname.replace(/\/[^/]+$/, "") + "/myModules"
  22. }]
  23. };
  24. </script>
  25. <script src="http://localhost/arcgis_js_api/library/3.9/3.9/init.js"></script>
  26. <script src="jquery.min.js"></script>
  27. <script>
  28.  
  29. require([
  30. "dojo/dom",
  31. "dojo/dom-construct",
  32. "esri/map",
  33. "myModules/InfoWindow",
  34. "esri/layers/ArcGISTiledMapServiceLayer",
  35. "esri/symbols/PictureMarkerSymbol",//图片点符号
  36. "esri/renderers/SimpleRenderer", //简单渲染
  37. "esri/layers/FeatureLayer",
  38. "esri/InfoTemplate",
  39. "dojo/string",
  40. "dojo/domReady!"
  41. ], function(
  42. dom,
  43. domConstruct,
  44. Map,
  45. InfoWindow,
  46. ArcGISTiledMapServiceLayer,
  47. PictureMarkerSymbol,
  48. SimpleRenderer,
  49. FeatureLayer,
  50. InfoTemplate,
  51. string
  52. ) {
  53. //create the custom info window specifying any input options
  54. var infoWindow = new InfoWindow({
  55. domNode: domConstruct.create("div", null, dom.byId("mapDiv"))
  56. });
  57.  
  58. var map = new Map("mapDiv", {
  59. logo:false,
  60. basemap: "gray",
  61.           center: [-98.57, 39.82],
  62.           zoom: 4,
  63. zoom: 4,
  64. slider: true,
  65. infoWindow: infoWindow
  66. });
  67.  
  68. //define the info template that is used to display the popup content.
  69. var template = new InfoTemplate();
  70. template.setTitle("<b>${name}</b>");
  71. template.setContent("hello");
  72. template.setContent("<h1>我是中国人民的儿子</h1><br>你妹啊!!!");
  73.  
  74. var featurelayercity = new FeatureLayer("http://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Boston_Marathon/FeatureServer/0", {
  75. mode: FeatureLayer.MODE_SNAPSHOT,
  76. infoTemplate: template,
  77. outFields: ["*"]
  78. });
  79. var pmsRed = new PictureMarkerSymbol('../images/location_icon_blue.png', 20, 20).setOffset(0, 15);
  80. //简单渲染
  81. var sr=new SimpleRenderer(pmsRed);
  82. featurelayercity.setRenderer(sr);
  83. map.addLayer(featurelayercity);
  84.  
  85. //resize the info window
  86. map.infoWindow.resize(400, 200);
  87.  
  88. });
  89. </script>
  90. </head>
  91. <body>
  92. <div id="mapDiv"></div>
  93. </body>
  94. </html>

下载源代码

lzugis——Arcgis Server for JavaScript API之自定义InfoWindow的更多相关文章

  1. lzugis——Arcgis Server for JavaScript API之自定义InfoWindow(续)

    同样的标题后面加了一个括弧,不是为了增减博文数量,而确实是上个功能的完善,标注为续,意思是继续上次的内容,来说说如何自定义InfoWindow. 在上一讲中,实现了InfoWindow的显示,但是并没 ...

  2. Arcgis Server for JavaScript API之自定义InfoWindow

    各位看到这个标题不要嫌烦,因为本人最近一直在研究相关的问题,所以相关文章也只能是这些,同时希望看过我的文章的朋友,我的文章能够给你帮助. 在前面的两篇相关的文章里面,实现InfoWindow是通过di ...

  3. lzugis——Arcgis Server for JavaScript API之自己定义InfoWindow

    用过Arcgis Server for JavaScript API肯定知道InfoWIndow.你在用InfoWindow的时候会发现各种问题,比如不能全然显示的问题,遮盖对象的问题等等.所以呢我在 ...

  4. lzugis——Arcgis Server for JavaScript API之POI

    POI(Point Of Interest),感兴趣点,其实呢,严格意义上说应该不是POI,但是单位就这样叫了,我也就这样叫了,其实现的功能大致是这样的:用过百度地图的朋友们都知道你在百度地图时,当鼠 ...

  5. lzugis——Arcgis Server for JavaScript API在自己的定义InfoWindow

    你看到这个标题嫌烦.因为我最近一直与研究问题,相关文章使这些也可以只,同时要读我文章的朋友.我的文章能够给你带来帮助. 在相关的内部的前两篇文章,达到InfoWindow经div实现的东西,成Info ...

  6. ArcGIS server开发之API for js 本地部署

    ArcGIS Server for javascript 本地部署 第一次使用arcgis server for js开发,在经验方面还有很多的不足,所以将自己在开发过程中遇到的问题写出来与大家共享. ...

  7. ArcGIS 10.2 JavaScript API本地部署离线开发环境

    1 获取ArcGIS JavaScript API API的下载地址http://support.esrichina.com.cn/2011/0223/960.html,在下载页面会看到api和sdk ...

  8. ArcGIS Server for JavaScript 3.3 的安装部署

    一.安装包下载 首先从官网下载ArcGIS API for JavaScript 3.3 的API和SDK,地址:http://support.esrichina.com.cn/2011/0223/9 ...

  9. How to CORS enable ArcGIS Server 10.2.1 to Access REST Services without Using proxy.ashx

    http://gis.stackexchange.com/questions/86206/how-to-cors-enable-arcgis-server-10-2-1-to-access-rest- ...

随机推荐

  1. 同步锁,死锁现象与递归锁,信息量Semaphore.....(Day36)

    一.同步锁 三个需要注意的点: #1.线程抢的是GIL锁,GIL锁相当于执行权限,拿到执行权限后才能拿到互斥锁Lock,其他线程也可以抢到GIL,但如果发现Lock仍然没有被释放则阻塞,即便是拿到执行 ...

  2. MyBatis For .NET学习- 初识MyBatis

    MyBatis的框架. Introduction MyBatis本是apache的一个开源项目iBatis,2010年这个项目由 apache software foundation迁移到了googl ...

  3. python2.7中的字符编码问题

    0. 写在前面 起因:之前写个数据预处理程序的时候遇到了点问题,用re模块的正则查找方法search时总是找不出来(找错了或者出乱码),于是捣鼓捣鼓. 经过:查资料,做实验,发现用utf8编码的str ...

  4. Tomcat 源码分析(转)

    本文转自:http://blog.csdn.net/haitao111313/article/category/1179996 Tomcat源码分析(一)--服务启动 1. Tomcat主要有两个组件 ...

  5. 用VS2013编译FFMPEG232

    http://blog.csdn.net/finewind/article/details/38854517 如果只是拿来使用,网上有现成的SDK.但我是想深入研究FFMPEG代码,又不熟悉Linux ...

  6. 双camera景深计算

    https://sanwen8.cn/p/2e41VC5.html 本文系微信公众号<大话成像>,知乎专栏< all in camera>原创文章,转载请注明出处. 接着上一篇 ...

  7. 【笔记】IntelliJ IDEA配置Hibernate

    参考:imooc:http://www.imooc.com/video/7706 1.创建Hibernate的配置文件. 将依赖包导入项目.http://blog.csdn.net/a15337525 ...

  8. 【Java】仿真qq尝试:用户注册(一)

    需求: 1.流程分析:客户端程序拿到用户名和密码,将用户名和密码发送到服务端(在客户端验证合法性),服务端接收并存储用户名和密码,返回给客户端一个信息(可能是成功也可能是失败.) 2.数据怎么存?服务 ...

  9. JavaWeb XML

    1. XML详解 1.1. XML介绍 1.1.1. 什么是XML XML的全称为eXtensible Markup Language,译为可扩展标记语言.XML语法上和HTML比较相似,但HTML中 ...

  10. java中TreeMap集合的常用方法

    实现Map集合的方法这里就不在讲了 https://www.cnblogs.com/xiaostudy/p/9510763.html public Map.Entry<K,V> ceili ...