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

你看到这个标题嫌烦。因为我最近一直与研究问题,相关文章使这些也可以只,同时要读我文章的朋友。我的文章能够给你带来帮助。

在相关的内部的前两篇文章,达到InfoWindow经div实现的东西,成InfoWindowBase实现infowindow的。

实现后InfoWindow主要改动了arcgis原来的样式。并增加了InfoWindow出界的处理。

源码奉上:

InfoWindow.js

define([
    "dojo/Evented",
    "dojo/parser",
    "dojo/on",
    "dojo/_base/declare",
    "dojo/dom-construct",
    "dojo/_base/array",
    "dojo/dom-style",
    "dojo/_base/lang",
    "dojo/dom-class",
    "dojo/fx",
    "dojo/Deferred",
    "esri/domUtils",
    "esri/InfoWindowBase"
],
function(
    Evented,
    parser,
    on,
    declare,
    domConstruct,
    array,
    domStyle,
    lang,
    domClass,
    coreFx,
    Deferred,
    domUtils,
    InfoWindowBase
)
{
	var infoWidth,infoHeight;
	var initMapCenter,initScreenCenter;
	var showMapPoint,showScreenPoint=null;

	return declare([InfoWindowBase, Evented],
	{
        constructor: function(parameters)
		{
			lang.mixin(this, parameters);
			domClass.add(this.domNode, "myInfoWindow");
			this._closeButton = domConstruct.create("div",{"class": "close", "title": "关闭"}, this.domNode);
			this._title = domConstruct.create("div",{"class": "title"}, this.domNode);
			this._content = domConstruct.create("div",{"class": "content"}, this.domNode);
			this._arrow = domConstruct.create("div",{"class": "arrow"}, this.domNode);
			on(this._closeButton, "click", lang.hitch(this, function(){
				//hide the content when the info window is toggled close.
				this.hide();
			}));
			//hide initial display
			domUtils.hide(this.domNode);
			this.isShowing = false;
        },
        setMap: function(map)
		{
			this.inherited(arguments);
			map.on("pan", lang.hitch(this, function(pan){
				var movePoint=pan.delta;
				if(this.isShowing)
				{
					if(showScreenPoint!=null)
					{
						this._showInfoWindow(showScreenPoint.x+movePoint.x,showScreenPoint.y+movePoint.y);
					}
				}
			}));
			map.on("pan-end", lang.hitch(this, function(panend){
				var movedelta=panend.delta;
				if(this.isShowing){
					showScreenPoint.x=showScreenPoint.x+movedelta.x;
					showScreenPoint.y=showScreenPoint.y+movedelta.y;
				}
			}));
			map.on("zoom-start", lang.hitch(this, function(){
				domUtils.hide(this.domNode);
				this.onHide();
			}));
			map.on("zoom-end", lang.hitch(this, function(){
				if(this.isShowing){
					showScreenPoint=this.map.toScreen(showMapPoint);
					this._showInfoWindow(showScreenPoint.x,showScreenPoint.y);
				}
			}));
        },
        setTitle: function(title){
			this.place(title, this._title);
        },
        setContent: function(content){
			this.place(content, this._content);
        },
		_showInfoWindow:function(x,y)
		{
			//Position 10x10 pixels away from the specified location
			domStyle.set(this.domNode,{
				"left": x - infoWidth/2 + 15 + "px",
				"top": y - infoHeight-75 + "px"
			});
			//display the info window
			domUtils.show(this.domNode);
		},
        show: function(location)
		{
			showMapPoint=location;

			initMapCenter=this.map.extent.getCenter();
			initScreenCenter=this.map.toScreen(initMapCenter);

			infoHeight= $(".myInfoWindow").height();
			infoWidth= $(".myInfoWindow").width();

			if(location.spatialReference){
				location = this.map.toScreen(location);
			}

			var left=location.x-infoWidth/2;
			var top=location.y-infoHeight-75;
			showScreenPoint=location;

			if(top<5)
			{
				initScreenCenter.y=initScreenCenter.y+top-5;
			}
			if(left<5)
			{
				initScreenCenter.x=initScreenCenter.x+left-5;
			}
			this._showInfoWindow(showScreenPoint.x,showScreenPoint.y);
			initMapCenter=this.map.toMap(initScreenCenter);
			this.map.centerAt(initMapCenter);
			this.isShowing = true;
			this.onShow();
        },
        hide: function(){
			domUtils.hide(this.domNode);
			this.isShowing = false;
			this.onHide();
        },
        resize: function(width, height){
			domStyle.set(this._content,{
				"width": width + "px",
				"height": (height-60) + "px"
			});
			domStyle.set(this._title,{
				"width": width + "px"
			});
        },
        destroy: function(){
			domConstruct.destroy(this.domNode);
			this._closeButton = this._title = this._content = null;
        }
	});
	return InfoWindow;
});

InfoWindow.js

.myInfoWindow {
  position: absolute;
  z-index: 100;
  font-family: sans-serif;
  font-size: 12px;
}

.dj_ie .myInfoWindow {
  border: 1px solid black;
}

.myInfoWindow .content {
  position: relative;
  background-color:#EFECCA;
  color:#002F2F;
  overflow: auto;
  padding-top:5px;
  padding-bottom:5px;
  padding-left:5px;
}

.myInfoWindow .arrow {
	position: absolute;
	width: 0px;
	height: 0px;
	line-height: 0px;/*为了防止ie下出现题型*/
	border-top: 60px solid #EFECCA;
	border-left: 5px solid transparent;
	border-right: 20px solid transparent;
	left: 45%;
	bottom: -60px;
}

.myInfoWindow .close {
  position: absolute; top: 7px; right: 5px;
  cursor: pointer;
  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;
  width: 12px; height: 12px;
}

.myInfoWindow .close:hover  {
  background-color: #F7FCFF;
}

.myInfoWindow .title {
  font-weight: bold;
  background-color:#046380;
  color:#E6E2AF;
  padding-top:5px;
  padding-bottom:5px;
  padding-left:5px;
}

test.html

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!--The viewport meta tag is used to improve the presentation and behavior
    of the samples on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Custom Info Window</title>
    <link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
    <link rel="stylesheet" href="myModules/InfoWindow.css">
    <style>
      html, body, #mapDiv { height: 100%; width: 100%; margin: 0; padding: 0; } 

    </style>

    <script>
	var dojoConfig = {
        parseOnLoad:true,
        packages: [{
          "name": "myModules",
          "location": location.pathname.replace(/\/[^/]+$/, "") + "/myModules"
        }]
      };
    </script>
    <script src="http://localhost/arcgis_js_api/library/3.9/3.9/init.js"></script>
    <script src="jquery.min.js"></script>
    <script>

    require([
      "dojo/dom",
      "dojo/dom-construct",
      "esri/map",
      "myModules/InfoWindow",
      "esri/layers/ArcGISTiledMapServiceLayer",
      "esri/symbols/PictureMarkerSymbol",//图片点符号
      "esri/renderers/SimpleRenderer", //简单渲染
      "esri/layers/FeatureLayer",
      "esri/InfoTemplate",
      "dojo/string",
      "dojo/domReady!"
    ], function(
       dom,
       domConstruct,
       Map,
       InfoWindow,
       ArcGISTiledMapServiceLayer,
       PictureMarkerSymbol,
       SimpleRenderer,
       FeatureLayer,
       InfoTemplate,
       string
    ) {
      //create the custom info window specifying any input options
       var infoWindow = new  InfoWindow({
          domNode: domConstruct.create("div", null, dom.byId("mapDiv"))
       });

      var map = new Map("mapDiv", {
          logo:false,
          basemap: "gray",
          center: [-98.57, 39.82],
          zoom: 4,
          zoom: 4,
          slider: true,
      	  infoWindow: infoWindow
      });			

      //define the info template that is used to display the popup content.
      var template = new InfoTemplate();
      template.setTitle("<b>${name}</b>");
      template.setContent("hello");
      template.setContent("<h1>我是中国人民的儿子</h1><br>你妹啊!

!

。"); 

	  var featurelayercity = new FeatureLayer("http://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Boston_Marathon/FeatureServer/0", {
          mode: FeatureLayer.MODE_SNAPSHOT,
          infoTemplate: template,
		  outFields: ["*"]
      });
	  var pmsRed = new PictureMarkerSymbol('../images/location_icon_blue.png', 20, 20).setOffset(0, 15);
	  //简单渲染
	  var sr=new SimpleRenderer(pmsRed);
	  featurelayercity.setRenderer(sr);
      map.addLayer(featurelayercity);	  

      //resize the info window
      map.infoWindow.resize(400, 200);

    });
    </script>
  </head>
  <body>
    <div id="mapDiv"></div>
  </body>
</html>

下上传资源

版权声明:本文博主原创文章。博客,未经同意不得转载。

时间: 2024-11-10 07:29:15

lzugis——Arcgis Server for JavaScript API在自己的定义InfoWindow的相关文章

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

同样的标题后面加了一个括弧,不是为了增减博文数量,而确实是上个功能的完善,标注为续,意思是继续上次的内容,来说说如何自定义InfoWindow. 在上一讲中,实现了InfoWindow的显示,但是并没有实现地图拖动地图InfoWindow随着联动,以及缩放地图InfoWindow随着联动的问题,在本文章中,就上述两个问题提供一个解决思路. 首先,说说拖动地图InfoWindow的联动.拖动地图时,地图并未做缩放,所以只是做一个位置的偏移,因此,定义一个公共变量,记录InfoWindow出来时候的

lzugis——Arcgis Server for JavaScript API之POI

POI(Point Of Interest),感兴趣点,其实呢,严格意义上说应该不是POI,但是单位就这样叫了,我也就这样叫了,其实现的功能大致是这样的:用过百度地图的朋友们都知道你在百度地图时,当鼠标经过某个点时会显示这个对象的名称,点击该对象,会弹出该对象的详细信息.如下图所示: 实现后的效果呢就是这样子的,下面呢我来说说在Arcgis Server for JavaScript API下,我实现该效果的思路与想法. 首先,得有一个图层用于显示这些点对象,这个图层可以是切片,也可以是WMS,

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

用过Arcgis Server for JavaScript API肯定知道InfoWIndow,你在用InfoWindow的时候会发现各种问题,例如不能完全显示的问题,遮盖对象的问题等等,所以呢我在实现这个功能的时候动了下脑子,想自己用div+css弄一个,倒腾了半天,弄出来了一个如下所示的: 做的比较丑陋,样式方面还得好好下下功夫,东西是差不多实现了,下面说说思路: 首先,DIV定义,这个样式,我定义了5个div,分别是infowin,title,colse,content,arrow,其中

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

用过Arcgis Server for JavaScript API肯定知道InfoWIndow.你在用InfoWindow的时候会发现各种问题,比如不能全然显示的问题,遮盖对象的问题等等.所以呢我在实现这个功能的时候动了下脑子,想自己用div+css弄一个,倒腾了半天,弄出来了一个例如以下所看到的的: 做的比較丑陋,样式方面还得好好下下功夫.东西是差点儿相同实现了,以下说说思路: 首先.DIV定义,这个样式,我定义了5个div,各自是infowin,title,colse,content.ar

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

ArcGIS Server for javascript 本地部署 第一次使用arcgis server for js开发,在经验方面还有很多的不足,所以将自己在开发过程中遇到的问题写出来与大家共享.有什么不足的地方还望多多指正,共同学习. 一.arcgis arcgis for JavaScript API的下载地址为:http://help.arcgis.com/en/webapi/javascript/arcgis/ 二.下载之后的压缩包解压之后 三.将解压的api和sdk要部署到IIS的

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-services-without-using-pr 比如,在你的arcgis server for javascript api网站中跨域访问WebApi的资源(取一些json格式数据?),差不多懂了

ArcGIS Server 缓存服务切图范围

ArcGIS Server 缓存服务分为创建服务时同时自动建立缓存和创建服务后手动建立缓存两种. 相关资料: 缓存: 瓦片: 切片: 10.4帮助文档: 10.2帮助文档: http://resources.arcgis.com/zh-cn/help/main/10.2/index.html#//00540000000p000000 官方文档链接:http://resources.arcgis.com/zh-cn/help/main/10.2/index.html#//00540000000p0

ArcGIS API for JavaScript(2)-ArcGIS Server发布要素图层服务

1.前言 上一篇该系列的文章我们主要讲了一下基础Web地图搭建,这篇我们主要讲一下ArcGIS Server发布服务,并且如何调用服务.将自己的数据加载到Web地图当中来,实现Web端浏览数据. 2.ArcGIS Server介绍与安装 1.ArcGIS Server 是功能强大的基于服务器的 GIS 产品,用于构建集中管理的.支持多用户的.具备高级GIS功能的企业级GIS应用与服务,如:空间数据管理.二维三维地图可视化.数据编辑.空间分析等即拿即用的应用和类型丰富的服务.ArcGIS Serv

ArcGIS Server JavaScript API 各命名空间的含义【转】

1.esri 命名空间      所有的对象都是在 esri 命名空间下的,esri 有自己的属性和方法.      如 esri.version 返回当前 JavaScript API 的版本号.esri.hide(Element) 隐藏 html 元素,像 DIV 或者是 TABLE 元素.2.Graphic 对象      如果你做过 arcserver adf 开发或者是 arcserver api for Silverlight 开发的话,对 Graphic 对象应该是很熟悉的.这是一