how to get geometry type of layer using IMapServer3 and IMapLayerInfo? (C#)
I need to create a REST extension that will return JSON looking like that:
"layers" : [ { "MaxScale" : 0,
"MinScale" : 0,
"defaultVisibility" : true,
"geometryType" : null,
"id" : 0,
"name" : "Name",
"parentLayerId" : -1,
"subLayerIds" : [ 1, 2 ]
},
{ "MaxScale" : 0,
"MinScale" : 0,
"defaultVisibility" : false,
"geometryType" : "esriGeometryPoint",
"id" : 1,
"name" : "NAME Offices",
"parentLayerId" : 0,
"subLayerIds" : null
}
...
As I'm able to get almost all informations that I want, I have only issue getting geometryType anddefaultVisibility.
I was trying to find a way by looking into DOCS, I'm sure If I will be able to get IGeometry interface I should be able to get geometry type, but how to get IGeometry interface starting from IMapServer3? Or there is other way to do it?
Here is a code that is creating list of layers in JSON format:
private XxxLayerInfo[] GetLayerInfos()
{
IMapServer3 mapServer = _serverObjectHelper.ServerObject as IMapServer3;
if (mapServer == null)
throw new Exception("Unable to access XXX map server.");
IMapServerInfo msInfo = mapServer.GetServerInfo(mapServer.DefaultMapName);
IMapLayerInfos layerInfos = msInfo.MapLayerInfos;
int length = layerInfos.Count;
XxxLayerInfo[] xxxLayerInfos = new XxxLayerInfo[c][/c];
for(int i = 0; i < length; i++)
{
IMapLayerInfo layerInfo = layerInfos.get_Element(i);
xxxLayerInfos[i] = XxxLayerInfo.CreateXxxLayerInfo(layerInfo);
}
return xxxLayerInfos;
}
public static XxxLayerInfo CreateXxxLayerInfo(IMapLayerInfo mapLayerInfo)
{
var layer = new XxxLayerInfo();
layer.Id = mapLayerInfo.ID;
layer.Name = mapLayerInfo.Name;
layer.GeometryType = null; //mapLayerInfo.GeometryType - HOW TO GET this?;
layer.DefaultVisibility = false; //mapLayerInfo.DefaultVisibility - HOW TO GET this?;
layer.MinScale = mapLayerInfo.MinScale;
layer.MaxScale = mapLayerInfo.MaxScale;
layer.ParentLayerId = mapLayerInfo.ParentLayerID;
layer.SubLayers = mapLayerInfo.SubLayers;
return layer;
}
Ok, there is a way to do it with multiply casts and few extra loops (esri why?)
As what surprising is that after 2 (?) months question staid without answer - the only place for Q reg ESRI.
The full desc how to do it can be found here - text in PL.
If you are interested only in code, here it is:
// get map info
public static MapInfo ConstructFrom(IMapServer3 mapServer3)
{
// IMapServerInfo3 contains CopyrightText prop, 1 & 2 does not
var mapServerInfo = (IMapServerInfo3)mapServer3.GetServerInfo(mapServer3.DefaultMapName);
var mapInfo = new MapInfo
{
Description = mapServerInfo.Description,
MapName = mapServerInfo.Name,
CopyrightText = mapServerInfo.CopyrightText
};
IMapLayerInfos layerInfos = mapServerInfo.MapLayerInfos;
for (int i = 0; i < layerInfos.Count; i++)
{
var layerInfo = layerInfos.Element[i];
mapInfo.Layers.Add(
LayerInfo.ConstructFrom(
layerInfo,
LayerInfo.IsLayerVisible(mapServerInfo, layerInfo.ID)
));
}
return mapInfo;
}
// get layer info
private static readonly int[] AvaliableReports = new[] {17,18,19,20};
public static LayerInfo ConstructFrom(IMapLayerInfo mapLayerInfo, bool visible)
{
var layerInfo = new LayerInfo
{
Id = mapLayerInfo.ID,
DisplayField = mapLayerInfo.DisplayField,
ScaleUpper = (int)mapLayerInfo.MaxScale,
ScaleLower = (int)mapLayerInfo.MinScale,
Name = mapLayerInfo.Name,
Description = mapLayerInfo.Description,
DefaultVisibility = visible,
ParentLayerId = mapLayerInfo.ParentLayerID,
};
IFields fields = mapLayerInfo.Fields;
bool addFields = false;
if (fields != null)
{
for (int j = 0; j < fields.FieldCount; j++)
{
IField field = fields.Field[j];
if (field.Type == esriFieldType.esriFieldTypeString)
{
layerInfo.DictFields[field.Name] = field.AliasName;
continue;
}
if(field.Type != esriFieldType.esriFieldTypeGeometry)
{
continue;
}
IGeometryDef geometryDef = field.GeometryDef;
layerInfo.GeometryType = Enum.GetName(typeof(esriGeometryType), geometryDef.GeometryType);
switch (geometryDef.GeometryType)
{
case esriGeometryType.esriGeometryNull:
layerInfo.GeometryType = null;
break;
case esriGeometryType.esriGeometryPoint:
addFields = true;
break;
}
}
}
// hack: this should be done in a proper way... but for now is enough
layerInfo.ContainsReport = AvaliableReports.Contains(layerInfo.Id);
if(!addFields)
{
layerInfo.DictFields = new Dictionary<string, string>();
}
if (mapLayerInfo.SubLayers == null)
{
return layerInfo;
}
for (int i = 0; i < mapLayerInfo.SubLayers.Count; i++)
{
layerInfo.SubLayerIds.Add(mapLayerInfo.SubLayers.Element[i]);
}
return layerInfo;
}
// get default visibility
public static bool IsLayerVisible(IMapServerInfo3 mapServerInfo, int layerId)
{
ILayerDescriptions layerDescs = mapServerInfo.DefaultMapDescription.LayerDescriptions;
long c = layerDescs.Count;
for (long i = 0; i < c; i++)
{
var layerDesc = (ILayerDescription3)layerDescs.Element[i];
if (layerDesc.ID == layerId)
{
return layerDesc.Visible;
}
}
return false;
}
how to get geometry type of layer using IMapServer3 and IMapLayerInfo? (C#)的更多相关文章
- 弹出层layer的使用
弹出层layer的使用 Intro layer是一款web弹层组件,致力于服务各个水平段的开发人员.layer官网:http://layer.layui.com/ layer侧重于用户灵活的自定义,为 ...
- layer弹出信息框API
首先向大家推荐layer,在这里也非常感谢贤心的贡献,非常不错的信息框及弹出层解决方案,为一些项目的前端开发提高了很大的效率,希望layer 越办越好! 下面是API,呵呵,官方抄袭过来的,为了自己看 ...
- Caffe源码解析3:Layer
转载请注明出处,楼燚(yì)航的blog,http://home.cnblogs.com/louyihang-loves-baiyan/ layer这个类可以说是里面最终的一个基本类了,深度网络呢就是 ...
- jQuery layer[页面弹出框]
常见接口如下: 方法名 描述 $.layer({}) 核心接口,参数是一个对象,对象属性参见上述列表.诸如layer.alert()之类的为$.layer()的包装方法. layer.v 获取版本号. ...
- boost库之geometry<二>
#include <boost/assign.hpp> #include <boost/geometry/core/point_type.hpp> #include <b ...
- Layer弹层组件 二次扩展,项目中直接使用。
/************************ Layer扩展 ****************************/ /* * Layer弹出Alert提示框 * @param messag ...
- layer.open
1.type-基本层类型 类型:Number,默认:0 layer提供了5种层类型.可传入的值有:0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层). 若你采用layer. ...
- Caffe中Layer注册机制
Caffe内部维护一个注册表用于查找特定Layer对应的工厂函数(Layer Factory的设计用到了设计模式里的工厂模式).Caffe的Layer注册表是一组键值对(key, value)( La ...
- jquery 弹窗插件 layer 常见接口
源自:https://www.cnblogs.com/teamobaby/p/3556584.html 常见接口如下: 方法名 描述 $.layer({}) 核心接口,参数是一个对象,对象属性参见上述 ...
随机推荐
- Farseer.net轻量级ORM开源框架 V1.x 入门篇:表实体类映射
导航 目 录:Farseer.net轻量级ORM开源框架 目录 上一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:数据库上下文 下一篇:Farseer.net轻量级ORM开源框 ...
- System.Web.Optimization找不到引用怎么办
新建Bootstap for MVC5出现的问题, 通过打开VS 工具->NUGET程序包管理器->控制台 输入以下命令进行完成,一切完成 Install-Package Microsof ...
- Python游戏开发入门
Pygame简介与安装 1.Pygame安装 pip install pygame2.检测pygame是否安装成功 python -m pygame.examples.aliens Pygame最小开 ...
- vue动态设置页面title方法
第一种方法 npm install vue-wechat-title --save 在mian.js中引入 //设置title import VueWechatTitle from 'vue-wech ...
- jquery 获取日期 date 对象、 判断闰年
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- (function(){})() 立即执行函数
(function(){})() 立即执行函数 (function(a){})(5) 带参的
- xxtea 文件加密与解密
加密 cocos luacompile -s src -d dst_dir -e -b xxxxx -k xxxxx --disable-compile 解密 cocos luacompile -s ...
- GPS坐标转化距离(短距离模型公式)
下面是C#计算方法: class Program { const double EARTH_RADIUS = 6378.137; static void Main(string[] args) { d ...
- JS授权
(function(){ var origin_url = location.href; var oauth_url = 'https://vx.mcilife.com/weixin/api/oaut ...
- 3D超炫酷旋转
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...