概述:

本文解说怎样通过Arcgis Server REST 的导出地图(Export)接口。实如今OL2中直接以WMS的方式调用Arcgis Server REST服务。

实现思路:

1、rest的export接口介绍

服务支持导出地图

导出參数

Parameter

Details

f

Description: The response format. The default response format is html. If the format is image, the image bytes are directly streamed to the client.

Values: html | json | image | kmz

bbox

Description: (Required) The extent (bounding box) of the exported image. Unless the bboxSR parameter has been specified, the bbox is assumed to be in the spatial reference of the map.

Syntax: <xmin>, <ymin>, <xmax>, <ymax>

Example: bbox=-104,35.6,-94.32,41

The bbox coordinates should always use a period as the decimal separator even in countries where traditionally a comma is used.

size

Description: The size width *height) of the exported image in pixels. If the size is not specified, an image with a default size of 400 * 400 will be exported.

Syntax: <width>, <height>

Example: size=600,550

dpi

Description: The device resolution of the exported image (dots per inch). If the dpi is not specified, an image with a default DPI of 96 will be exported.

Example: dpi=200

imageSR

Description: The spatial reference of the exported image.

The spatial reference can be specified as either a well-known ID or as a spatial reference json object.

If the imageSR is not specified, the image will be exported in the spatial reference of the map.

bboxSR

Description: The spatial reference of the bbox.

The spatial reference can be specified as either a well-known ID or as a spatial reference json object.

If the bboxSR is not specified, the bbox is assumed to be in the spatial reference of the map.

format

Description: The format of the exported image. The default format is .png.

Values: png | png8 | png24 | jpg | pdf | bmp | gif | svg | svgz | emf | ps | png32

Note:

Support for the png32 format was added at 9.3.1. This format is only available formap services whose supportedImageFormatTypes property includes PNG32.

layerDefs

Description: Allows you to filter the features of individual layers in the exported map by specifying definition expressions for those layers. Definition expression for a layer that is published with the service will be always honored.

Simple Syntax:

Syntax: layerId1:layerDef1;layerId2:layerDef2

Where layerId1, layerId2 are the layer ids returned by the map service resource.

Example: 0:POP2000 > 1000000;5:AREA > 100000

JSON Syntax (new in 10.0): You can also use a JSON representation for Layer Definitions.

Syntax: { "<layerId1>" : "<layerDef1>" , "<layerId2>" : "<layerDef2>" }

Where layerId1, layerId2 are the layer ids returned by the map service resource.

Example: {"0":"POP2000 > 1000000","5":"AREA > 100000"}

layers

Description: Determines which layers appear on the exported map. There are four ways to specify which layers are shown:

  • show: Only the layers specified in this list will be exported.
  • hide: All layers except those specified in this list will be exported.
  • include: In addition to the layers exported by default, the layers specified in this list will be exported.
  • exclude: The layers exported by default excluding those specified in this list will be exported.

Syntax: [show | hide | include | exclude]:layerId1,layerId2

Where layerId1, layerId2 are the layer ids returned by the map service resource.

Example: layers=show:2,4,7

transparent

Description: If true, the image will be exported with the background color of the map set as its transparent color. The default is false. Only the .png and .gif formats support transparency. Internet Explorer 6 does not display transparency correctly for png24 image formats.

Values: true | false

time

Description: The time instant or time extent of the exported map image.

Time instant:

Syntax: time=<timeInstant>

Example: time=1199145600000 (1 Jan 2008 00:00:00 GMT)

Time extent:

Syntax: time=<startTime>, <endTime>

Example: time=1199145600000, 1230768000000 (1 Jan 2008 00:00:00 GMT to 1 Jan 2009 00:00:00 GMT)

A null value specified for start time or end time will represent infinity for start or end time respectively.

layerTimeOptions

Description: The time options per layer. Users can indicate whether or not the layer should use the time extent specified by the time parameter or not, whether to draw the layer features cumulatively or not and the time offsets for the layer.

Syntax:

{
"<layerId1>" : {
//If true, use the time extent specified by the time parameter
"useTime" : < true | false >,
//If true, draw all the features from the beginning of time for that data
"timeDataCumulative" : < true | false >,
//Time offset for this layer so that it can be overlaid on the top of a previous or future time period
"timeOffset" : <timeOffset1>,
"timeOffsetUnits" : "<esriTimeUnitsCenturies | esriTimeUnitsDays | esriTimeUnitsDecades |
esriTimeUnitsHours | esriTimeUnitsMilliseconds | esriTimeUnitsMinutes |
esriTimeUnitsMonths | esriTimeUnitsSeconds | esriTimeUnitsWeeks | esriTimeUnitsYears |
esriTimeUnitsUnknown>"
},
"<layerId2>" : {
"useTime" : < true | false >,
"timeDataCumulative" : < true | false >,
"timeOffsetOffset" : <timeOffset2>,
"timeOffsetUnits" : "<timeOffsetUnits2>"
}
}

Example:

{
"0" : {
"useTime" : true,
"timeDataCumulative" : false,
"timeOffset" : 1,
"timeOffsetUnits" : "esriTimeUnitsYears"
},
"3" : {
"useTime" : false
}
}
dynamicLayers

//This option was added at 10.1.

Description: Use dynamicLayers parameter to modify the layer drawing order, change layer drawing info, and change layer data source version for this request. New layers (dataLayer) can also be added to the dynamicLayers based on the map service registered workspaces.

The order of dynamicLayers array defines the layer drawing order. The first element of the dynamicLayers array draws on top of all other layers.

Note:
  • When defining a dynamic layer, if the layer source is of type mapLayer, then use the id in layer resource as the mapLayerId for the dynamic layer.
  • If the layer source is a dataLayer based on a data table ( table or queryTabledataSource), then set drawingInfo.
  • transparency is on a scale of 1-100, where 0 is opaque and 100 is 100% transparent.
  • Use scaleSymbols to turn off scaling symbols on a layer that reportscanScaleSymbols to be true on the layer resource.
  • Use showLabels to turn on/off labeling on a layer that has labels (hasLabels set to true on layer resource).
  • To turn on labels on a layer that does not have labels defined on it, setshowLabels to true and use labelingInfo to specify labels.
  • Dynamic layers support both the Standard and Maplex labeling engines. The labeling engine that would be used is dependent on the one that was set in the map document used to create the map service.

Syntax:

[
{
"id": <layerOrTableId>,
"source": <layer source>,
"definitionExpression": "<definitionExpression>",
"drawingInfo":
{
"renderer": <renderer>,
"transparency": <transparency>,
"scaleSymbols": <true | false >,
"showLabels": <true | false >,
"labelingInfo": <labeling info>
},
"layerTimeOptions":
{
"useTime" : <true | false>,
"timeDataCumulative" : <true | false>,
"timeOffset" : <timeOffset>,
"timeOffsetUnits" : "<esriTimeUnitsCenturies | esriTimeUnitsDays | esriTimeUnitsDecades |
esriTimeUnitsHours | esriTimeUnitsMilliseconds | esriTimeUnitsMinutes |
esriTimeUnitsMonths | esriTimeUnitsSeconds | esriTimeUnitsWeeks | esriTimeUnitsYears |
esriTimeUnitsUnknown>"
}
},
{
"id": <layerOrTableId>,
"source": <layer source>,
"definitionExpression": "<definitionExpression>",
"drawingInfo":
{
"renderer": <renderer>,
"transparency": <transparency>,
"scaleSymbols": <true | false >,
"showLabels": <true | false >,
"labelingInfo": <labeling info>
},
"layerTimeOptions":
{
"useTime" : <true | false>,
"timeDataCumulative" : <true | false>,
"timeOffset" : <timeOffset>,
"timeOffsetUnits" : "<esriTimeUnitsCenturies | esriTimeUnitsDays | esriTimeUnitsDecades |
esriTimeUnitsHours | esriTimeUnitsMilliseconds | esriTimeUnitsMinutes |
esriTimeUnitsMonths | esriTimeUnitsSeconds | esriTimeUnitsWeeks | esriTimeUnitsYears |
esriTimeUnitsUnknown>"
}
}
]

Example:

[
//disable time on existing map service layer and turn off labels
{
"id": 501,
"source":
{
"type": "mapLayer",
"mapLayerId": 0
},
"drawingInfo":
{
"showLabels": false
},
"layerTimeOptions":
{
"useTime": false
}
},
//add a new layer from registered workspace and label features with a feature attribute value {TaxLotId]
{
"id": 502,
"source":
{
"type": "dataLayer",
"dataSource":
{
"type": "table",
"workspaceId": "MAP",
"dataSourceName": "MAP.user1.Taxlots"
}
},
"drawingInfo":
{
"renderer":
{
"type": "simple",
"symbol":
{
"type" : "esriSFS",
"style" : "esriSFSSolid",
"color" : [166,36,0,255],
"outline" :
{
"type" : "esriSLS",
"style" : "esriSLSSolid",
"color" : [110,110,110,255],
"width" : 1.0
}
},
"label": "TaxLots",
"description": ""
},
"transparency": 60
},
"showLabels": true,
"labelingInfo":
[
{
"labelPlacement": "esriServerPolygonPlacementAlwaysHorizontal",
"labelExpression": "[TaxLotId]",
"useCodedValues": false,
"symbol":
{
"type": "esriTS",
"color": [255,255,0,255],
"verticalAlignment": "bottom",
"horizontalAlignment": "left",
"font":
{
"family": "Arial",
"size": 12,
"style": "normal",
"weight": "bold",
"decoration": "none"
}
},
"minScale": 15000,
"maxScale": 30000,
"where": ""
}
]
},
//change the Version of existing map service layer
{
"id": 503,
"source":
{
"type": "mapLayer",
"mapLayerId": 1,
"gdbVersion": "USER1"
},
"definitionExpression": "neighborhood = 'French Quarter'"
},
//add a raster from registered workspace
{
"id": 504,
"source":
{
"type": "dataLayer",
"dataSource":
{
"type": "raster",
"workspaceId": "rasterWS",
"dataSourceName": "NewOrleans.tif"
}
},
"drawingInfo":
{
"transparency": 0
}
}
]
gdbVersion

//This option was added at 10.1.

Description: Use this parameter to specify the geodatabase version.

Syntax: gdbVersion=<geodatabase version>

Example: gdbVersion=sde.USER1

mapScale

//This option was added at 10.1.

Description: Use this parameter to export a map image at a specific scale, with the map centered around the center of the specified bounding box (bbox).

Syntax: mapScale=<scale>

Examples: mapScale=5000000, mapScale=5E6

參数具体说明

请求实例:

http://localhost:6080/arcgis/rest/services/china/MapServer/export?bbox=66.02425609744357%2C34.94598754534843%2C141.47696459232174%2C57.860197031494025&bboxSR=&layers=show%3A1&layerDefs=&size=&imageSR=&format=png&transparent=true&dpi=&time=&layerTimeOptions=&dynamicLayers=&gdbVersion=&mapScale=&f=image

返回结果:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

必须參数:

a、layers——展示的图层

b、bbox——四至范围

c、width——宽度

d、height——高度

2、返回图片

本文通过简单的servlet实现获取网络图片并返回前台的方式。

代码:

1、servlet代码

package com.lzugis.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL; @WebServlet(description = "rest to wms", urlPatterns = {"/wms"})
public class WmsServices extends HttpServlet {
private static final long serialVersionUID = 1L;
private static String baseUrl = "http://localhost:6080/arcgis/rest/services/china/MapServer/export?";
private static String basePara = "&format=png&transparent=true&f=image"; public WmsServices() {
super();
// TODO Auto-generated constructor stub
} protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
} protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String encoding = getInitParameter("encoding");
if ((encoding != null) && (!"".equals(encoding))) {
request.setCharacterEncoding(encoding);
}
String time = request.getParameter("t");
baseUrl = baseUrl+"t="+time;
String layers = request.getParameter("LAYERS");
String bbox= request.getParameter("BBOX");
String width= request.getParameter("WIDTH");
String height= request.getParameter("HEIGHT"); String wmsUrl = baseUrl+"&bbox="+bbox+"&layers=show:"+layers+"&size="+width+","+height+basePara;
try {
showImage(response,wmsUrl);
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public void showImage(HttpServletResponse response,String src) throws Exception {
response.setContentType("text/html; charset=UTF-8");
response.setContentType("image/png");
//new一个URL对象
URL url = new URL(src);
//打开链接
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//设置请求方式为"GET"
conn.setRequestMethod("GET");
//超时响应时间为5秒
conn.setConnectTimeout(5 * 1000);
//通过输入流获取图片数据
InputStream inStream = conn.getInputStream();
OutputStream os = response.getOutputStream();
try {
int count = 0;
byte[] buffer = new byte[1024 * 1024];
while ((count = inStream.read(buffer)) != -1){
os.write(buffer, 0, count);
}
os.flush();
}
catch (IOException e) {
e.printStackTrace();
}
finally {
os.close();
inStream.close();
}
}
}

2、前台调用代码

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>openlayers map</title>
<link rel="stylesheet" href="../../../plugin/OpenLayers-2.13.1/theme/default/style.css" type="text/css">
<style>
html, body, #map{
padding:0;
margin:0;
height:100%;
width:100%;
overflow: hidden;
}
</style>
<script src="../../../plugin/OpenLayers-2.13.1/OpenLayers.js"></script>
<script src="../../../plugin/jquery/jquery-1.8.3.js"></script>
<script>
var map;
var tiled;
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5;
OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;
$(window).load(function() {
var format = 'image/png';
var bounds = new OpenLayers.Bounds(
73.45100463562233, 18.16324718764174,
134.97679764650596, 53.531943152223576
);
var options = {
controls: [],
maxExtent: bounds,
maxResolution: 0.2403351289487642,
projection: "EPSG:4326",
units: 'degrees'
};
map = new OpenLayers.Map('map', options);
var time = new Date();
time = time.getTime();
var url = "http://localhost:8081/lzugis/wms?t="+time;
tiled = new OpenLayers.Layer.WMS(
"Geoserver layers - Tiled",
url,
{
"LAYERS": '1,6',
"STYLES": '',
format: format
},
{
buffer: 0,
displayOutsideMaxExtent: true,
isBaseLayer: true,
yx : {'EPSG:4326' : true}
}
);
map.addLayers([tiled]);
OpenLayers.INCHES_PER_UNIT["千米"] = OpenLayers.INCHES_PER_UNIT["km"];
OpenLayers.INCHES_PER_UNIT["米"] = OpenLayers.INCHES_PER_UNIT["m"];
OpenLayers.INCHES_PER_UNIT["英里"] = OpenLayers.INCHES_PER_UNIT["mi"];
OpenLayers.INCHES_PER_UNIT["英寸"] = OpenLayers.INCHES_PER_UNIT["ft"];
//比例尺
map.addControl(new OpenLayers.Control.ScaleLine({topOutUnits:"千米",topInUnits:"米",bottomOutUnits:"英里",
bottomInUnits:"英寸"
}));
map.addControl(new OpenLayers.Control.Zoom());
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.OverviewMap());
map.zoomToExtent(bounds);
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>

实现后效果:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

转换Arcgis Server REST接口实现OL2直接调用的更多相关文章

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

    1.前言 上一篇该系列的文章我们主要讲了一下基础Web地图搭建,这篇我们主要讲一下ArcGIS Server发布服务,并且如何调用服务.将自己的数据加载到Web地图当中来,实现Web端浏览数据. 2. ...

  2. arcgis server 中Web墨卡托投影与WGS-84坐标的转换

    arcgis server 中Web墨卡托投影坐标与WGS-84坐标的转换 //经纬度转墨卡托 function lonlat2mercator(lonlat){ var mercator={x:0, ...

  3. Arcgis api for javascript学习笔记 - 不改变默认端口(6080)情况下,外网访问Arcgis Server 发布的接口

    Arcgis Server发布的地图服务地址默认端口号是6080,假设本机上只对80端口做了外网映射,在IIS中部署了一个网站绑定了80端口,那么网站中某个页面通过arcgis api for js ...

  4. Arcgis, ArcEngine, Arcgis Server使用开发汇总 索引

    ArcGIS系列软件license及安装: Arcgis SDE10.1 和 Arcgis server10.1的授权文件license tnt_esri.dat Arcgis8.1安装license ...

  5. Arcgis Server发布服务

    提到Arcgis Server 服务的发布,做起来貌似很简单,就算电脑再卡,只要鼠标还能点,一个小时肯定能搞定,但是当你遇到问题的时候,就头大了,也许搞上个一两天都摸不着头脑,最后你采取的措施可能是一 ...

  6. ArcGIS Server 10 Java 版的Rest服务手动配置方法

    Java版的Manager中发布的服务默认只发布了该服务的SOAP接口,而REST接口需要用户在信息服务器,如Tomcat. Apache.WebLogic等中手工配置.由于在Java版的Server ...

  7. ArcGIS Server 10.2 实战(二)动态修改要素数据的地理处理服务

    上一篇<ArcGIS Server 10.2 实战(一)Asp.net MVC与JSON数据妙用实现动态生成要素图层>介绍了如何用JSON转要素的地理处理服务,实现了动态创建点要素并加载到 ...

  8. Android系统进程间通信(IPC)机制Binder中的Client获得Server远程接口过程源代码分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6633311 在上一篇文章中,我 们分析了And ...

  9. Windows下创建ArcGIS Server站点

    原创文章,转载须标明出处自: https://www.cnblogs.com/gisspace/p/8126261.html ------------------------------------- ...

随机推荐

  1. 对JVM还有什么不懂的?一文章带你深入浅出JVM!

    本文跟大家聊聊JVM的内部结构,从组件中的多线程处理,JVM系统线程,局部变量数组等方面进行解析 JVM JVM = 类加载器(classloader) + 执行引擎(execution engine ...

  2. 通过Hibernate实现添加功能

    package com.demo.dao; import org.hibernate.Session; import org.hibernate.SessionFactory; import org. ...

  3. 代理模式(Proxy)C++实现

    代理模式 尽管Decorator的实现部分与代理相似,但Decorator的目的不一样.Decorator为对象添加一个或多个功能,而代理则控制对对象的访问. 意图: 为其他对象提供一种代理以控制对这 ...

  4. 第6章 服务模式 在 .NET 中实现 Service Interface

    上下文 您 的应用程序部署在 Microsoft Windows? 操作系统上.您决定将应用程序的某一块功能作为 ASP.NET Web Service 公开.互操作性是一个关键问题,因此您无法使用仅 ...

  5. 更换WordPress编辑器为TinyMCE Advanced

    WordPress自带的编辑器功能很少,连更换字体样式大小都不行,没关系WordPress的插件中心插件非常多 在插件中心搜索TinyMCE Advanced 安装启用 还没完 点击设置 里面有丰富的 ...

  6. wpf 错误 执行了 QueryInterface 调用,请求提供 COM 可见的托管类“BoilerMonitoringV1._0.MapControl”的默认 IDispatch 接口。

    在做wpf嵌入地图时,在自定义的WebBrowser 里面使用JavaScript调用外部方法的时报的错误 在原来的WinForm里 我们只要在窗体类设置的头部设置个 [System.Runtime. ...

  7. Oracle PL/SQL开发基础(第三十四弹:RAISE_APPLICATION_ERROR)

    RAISE_APPLICATION_ERROR在子程序内部使用时,能从存储子程序中抛出自定义的错误消息.这样就能将错误报告给应用程序而避免范围未捕获异常. 语法如下: RAISE_APPLICATIO ...

  8. Angular 定时器$timeout和$interval关于定时刷新页面和发送请求的用法

    项目中有用到定时器定时刷新页面的数据,在网上查看了一些资料,整理了一下,备忘. $timeout 用法如下:$timeout(fn,[delay],[invokeApply]); fn:一个将被延迟执 ...

  9. js 目录树

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  10. Javaee 方法的格式和注意事项

    1.构造方法的格式是什么?有哪些注意事项?   修饰符+方法名称+(参数列表),构造的方法没有返回值,方法名称要和类名一样,有属性参数的需要在成员变量前加this,参数列表的值要和指定的方法格式相同. ...