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

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

源代码奉上:

myInfoWindow/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;
});

myInfoWindow/InfoWindow.css

.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>

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

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

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

  2. lzugis——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. python IOError: windows directory not found at xxxxx win32

    您需要修改 PATH 环境变量,将Python的可执行程序及额外的脚本添加到系统路径中.将以下路径添加到 PATH 中: C:\Python2.7\;C:\Python2.7\Scripts\;请打开 ...

  2. php中的foreach改变数组的值的问题

    翻到PHP文档的foreach那页这样写道: “foreach 语法结构提供了遍历数组的简单方式.foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误 ...

  3. [hdu4333]Revolving Digits

    /*注意注意:本题非hdu4333原题,而是简化版,原版有多组数据.但此代码在修改输入后依旧可以通过多组数据*/ 给出一个数字串,问有多少本质不同同构串比原串小,一样,大.同构串是指,对于原串S[1- ...

  4. 冷扑大师AI简史:你用德扑来游戏,人家用来发Science

    前言 人类又输了...... 创新工场组织的一场“人工智能和顶尖牌手巅峰表演赛中”,机器人AI冷扑大师赢了人类代表队龙之队 792327 记分牌,最后 200 万奖励归机器人所有. 在围棋项目上人类的 ...

  5. bitcode编译错误

    xcode编译引用的静态库可能会出现编译错误: does not contain bitcode. You must rebuild it with bitcode enabled (Xcode se ...

  6. Android指针管理:RefBase,SP,WP

    Android中通过引用计数来实现智能指针,并且实现有强指针与弱指针.由对象本身来提供引用计数器,但是对象不会去维护引用计数器的值,而是由智能指针来管理. 要达到所有对象都可用引用计数器实现智能指针管 ...

  7. XMPP协议相关基础概念(Strophe学习笔记)

    相关资料: XMPP官网http://xmpp.org/xmpp-software/libraries/ nginx的转发配置http://mineral.iteye.com/blog/448260 ...

  8. 基于C++任意点数的FFT/IFFT(时域和频域)实现

    函数说明:更改主函数体中的N和length(=log2(N))既可以实现任意点数(2的幂次)的FFT/ IFFT的实现,fft函数中flag标志位控制是正变换还是逆变换. 1.复数操作类      定 ...

  9. java多线程环境单例模式实现详解

    Abstract 在开发中,如果某个实例的创建需要消耗很多系统资源,那么我们通常会使用惰性加载机制,也就是说只有当使用到这个实例的时候才会创建这个实例,这个好处在单例模式中得到了广泛应用.这个机制在s ...

  10. day17-jdbc 3.jdbc快速入门

    通过java程序操作数据库. 对数据库操作是对记录的操作.记录就是DML和DCL. 只要Java程序跟任何设备进行了连接,用完之后必须释放资源.最简单基础班讲I/O流,Java跟文件进行了连接,用完之 ...