arcgis 自己的infowindow 太难看了,放在系统中与系统中的风格格格不入,在参考了网上的一些资料后,整理编写了适合自己系统的infowindow,与大家分享。

1、自定义展示效果

2、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 + 25 + "px",
"top": y - infoHeight-30 + "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-35;
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;
});

3、InfoWindow.css

.myInfoWindow {
position: absolute;
z-index: 100;
font-family: sans-serif;
font-size: 12px;
box-shadow: 0px 0px 5px 0px #2F302C;
}

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

.myInfoWindow .content {
position: relative;
background-color:#fff;
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: 30px solid #fff;
border-left: 5px solid transparent;
border-right: 20px solid transparent;
left: 45%;
bottom: -30px;
}

.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 0px 0px transparent;
width: 12px; height: 12px;
}

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

.myInfoWindow .title {
font-weight: bold;
background-color: #41A3EE;
color: #404040;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
text-align: center;
}

4.index.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.14/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://js.arcgis.com/3.14/init.js"></script>
<script src="jquery.min.js"></script>
<script>

require([
"dojo/dom",
"dojo/dom-construct",
"esri/map",
"myModules/InfoWindow",
"esri/layers/FeatureLayer",
"esri/InfoTemplate",
"dojo/string",
"dojo/domReady!"
], function(
dom,
domConstruct,
Map,
InfoWindow,
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", {
basemap: "gray",
center: [108.954238, 34.265472],
zoom: 12,
infoWindow: infoWindow
});
var showGraphicLayer = new esri.layers.GraphicsLayer();
map.addLayer(showGraphicLayer);

map.on("load", createToolbarAndContextMenu);
function createToolbarAndContextMenu() {
var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new esri.Color([25, 132, 200, 0.5]), 2),
new esri.Color([25, 132, 200, 0.5]));
var ring = "[108.92796875049564, 34.25199473286298],[108.93398402791837, 34.2547358719417],[108.93413631342275, 34.247045453970856],[108.92796875049564, 34.24696931121866], [108.92796875049564, 34.25199473286298]";
var polygon = new esri.geometry.Polygon({
"rings": eval('([[' + ring + ']])')
});
var attr = { "stationName": "lifuqiang", "locate": "lifuqiang", "complainTime": "lifuqiang", "region": "lifuqiang", "type": "lifuqiang", "technology": "lifuqiang" };
var infoTemplate = new esri.InfoTemplate("${stationName}", "名称1: ${locate}<br/>名称1: ${complainTime} <br/>名称1: ${region} <br/>名称1:${type}<br/>名称1:${technology}<div style='display:block;height:30px;background:#41A3EE;'></div><div><a href='javascript:ShowDetailStationPanel(22)'>查看详情</a> </div>");
var symbol;
var dddd = new esri.Graphic(polygon, polygonSymbol, attr, infoTemplate);
showGraphicLayer.add(dddd);
}

// var template = new esri.dijit.PopupTemplate({
// title: "Boston Marathon 2013",
// description: " of starters from finished",
// fieldInfos: [{ //define field infos so we can specify an alias
// fieldName: "Percent_Fi",
// label: "Entrants"
// },{
// fieldName: "Number_Sta",
// label: "Starters"
// },{
// fieldName: "Number_Fin",
// label: "Finishers"
// }]
// });

//var featureLayer = new FeatureLayer("http://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Boston_Marathon/FeatureServer/0",{
// mode: FeatureLayer.MODE_ONDEMAND,
// outFields: ["*"],
// infoTemplate:template
// });

// map.addLayer(featureLayer);

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

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

5、文件结构数

将2、3、4文件按照5的结构创建,点击浏览index.html,可见图1效果

arcgis for javascript 自定义infowindow的更多相关文章

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

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

  2. Arcgis for javascript不同的状态下自定义鼠标样式

    俗话说:爱美之心,人皆有之.是的,没错,即使我只是一个做地图的,我也希望自己的地图看起来好看一点.在本文,给大家讲讲在Arcgis for javascript下如何自定义鼠标样式. 首先,说几个状态 ...

  3. Arcgis for Javascript API下类似于百度搜索A、B、C、D marker的实现方式

    原文:Arcgis for Javascript API下类似于百度搜索A.B.C.D marker的实现方式 多说无益,首先贴两张图让大家看看具体的效果: 图1.百度地图搜索结果 图2.Arcgis ...

  4. Arcgis for Javascript之featureLayer图和属性互操作性

    说明:主要实现加载FeatureLayer并显示属性表,而要实现联动属性表与地图,首先,看看实施后的效果: 显示效果 如上图所看到的,本文章主要实现了下面几个功能:1.FeatureLayer属性表的 ...

  5. 利用Arcgis for javascript API绘制GeoJSON并同时弹出多个Popup

    1.引言 由于Arcgis for javascript API不可以绘制Geojson,并且提供的Popup一般只可以弹出一个,在很多专题图制作中,会遇到不少的麻烦.因此本文结合了两个现有的Arcg ...

  6. Arcgis for Javascript之统计图的实现

    首先,截个图给大家看看效果: 初始化状态 放大后的状态 点击选中后的状态 如上图所示,一般的涉及到的地图的统计涉及到上述所展示的三个状态:1.初始化状态:2.缩放后的状态:3.点击选中显示详情状态.第 ...

  7. Arcgis for Javascript之featureLayer图和属性的互操作

    说明:主要实现加载FeatureLayer与显示属性表,并实现属性表与地图的联动,首先,看看实现后的效果: 显示效果 如上图所示,本文章主要实现了以下几个功能:1.FeatureLayer属性表的分页 ...

  8. Arcgis for Javascript实现图

    首先,截个图给大家看结果: 初始化状态 放大后的状态 点击选中后的状态 如上图所看到的,一般的涉及到的地图的统计涉及到上述所展示的三个状态:1.初始化状态.2.缩放后的状态:3.点击选中显示详情状态. ...

  9. Javascript事件模型系列(四)我所理解的javascript自定义事件

    被我拖延了将近一个月的javascript事件模型系列终于迎来了第四篇,也是我计划中的最后一篇,说来太惭愧了,本来计划一到两个星期写完的,谁知中间遇到了很多事情,公司的个人的,搞的自己心烦意乱浮躁了一 ...

随机推荐

  1. 使用可视化图表对 Webpack 2 的编译与打包进行统计分析

    此文主要对使用可视化图表对 Webpack 2 的编译与打包进行统计分析进行了详细地讲解,供您更加直观地参考. 在之前更新的共十七章节中,我们陆续讲解了 Webpack 2 从配置到打包.压缩优化到调 ...

  2. MongoDB--架构搭建(主从、副本集)之副本集

    任何时间点只有一个活跃节点,其他为备份节点,当活跃节点泵机,将会通过选举规则,从备选节点选一个当活跃节点,当泵机的节点恢复之后,则变为备用节点. 节点类型 stabdard:常规节点,存储完整数据,参 ...

  3. Ztorg木马分析: 从Android root木马演变到短信吸血鬼

    本月第二次,Google 从官方应用商店 Google Play 中移除了伪装成合法程序的恶意应用.被移除的应用都属于名叫 Ztorg 的 Android 恶意程序家族.目前为止,发现的几十个新的Zt ...

  4. Linux网络编程客户\服务器设计范式

    1.前言 网络编程分为客户端和服务端,服务器通常分为迭代服务器和并发服务器.并发服务器可以根据多进程或多线程进行细分,给每个连接创建一个独立的进程或线程,或者预先分配好多个进程或线程等待连接的请求.今 ...

  5. RabbitMQ系列教程之四:路由(Routing)

    (使用Net客户端)在上一个教程中,我们构建了一个简单的日志系统,我们能够向许多消息接受者广播发送日志消息.在本教程中,我们将为其添加一项功能 ,这个功能是我们将只订阅消息的一个子集成为可能. 例如, ...

  6. zookeeper client API实现(python kazoo 的实现)

    这里主要分析zookeeper client API的实现方式,以python kazoo的实现代码为蓝本进行逻辑分析. 一.代码框架及介绍 API分为同步模式和异步模式.同步模式是在异步模式的基础上 ...

  7. [LeetCode] Friend Circles 朋友圈

    There are N students in a class. Some of them are friends, while some are not. Their friendship is t ...

  8. 【Android Developers Training】 7. 添加Action Buttons

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  9. 消息队列NetMQ 原理分析4-Socket、Session、Option和Pipe

    消息队列NetMQ 原理分析4-Socket.Session.Option和Pipe 前言 介绍 目的 Socket 接口实现 内部结构 Session Option Pipe YPipe Msg Y ...

  10. java中的方法引用(method reference)官方文档总结

    2017/7/5 转载写明出处:http://www.cnblogs.com/daren-lin/p/java-method-reference.html 今天要说的是java中的一项新特性,方法引用 ...