添加全部数据

// 构建map容器
var view = new MapView({
container: 'mapId',
map: map
});
/********************
* 添加底图
********************/
var imageLayer = new MapImageLayer({
url: 'https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer',
id: 'basicLayer'
});
map.add(imageLayer)

通过geojson添加边界数据(这里以北京为例)

var geojsonLayer = new GeoJSONLayer({
id: 'beijing',
url: './data/beijing.json'
});
map.add(geojsonLayer)

因为我的geojson数据是墨卡托,底图数据是经纬度,所以还要进行墨卡托转经纬度的转换,并根据边界数据进行地图定位

// 查询北京范围内的geometry并进行坐标转换
map.findLayerById('beijing').queryFeatures().then((res) => {
let tempArr = []
res.features[0].geometry.rings[0].forEach((item, index) => {
tempArr.push(_getLngLat(item))
})
res.features[0].geometry.rings[0] = tempArr
geometryBeiJing = res.features[0].geometry
view.goTo(geometryBeiJing)
})
/**
* 墨卡托转经纬度
* @param poi 墨卡托
* @returns {{}}
* @private
*/
function _getLngLat(poi){
var lnglat = [];
lnglat[0] = poi[0]/20037508.34*180;
var mmy = poi[1]/20037508.34*180;
lnglat[1] = 180/Math.PI*(2*Math.atan(Math.exp(mmy*Math.PI/180))-Math.PI/2);
return lnglat;
}

通过接口获得数据list,渲染点图层,并进行过滤

// 渲染点图层
function getFeatures (list) {
//原始数据点集合
var gras = [];
for (var i = 0; i < list.length; i++) {
gras.push(new Graphic({
geometry: new Point({
longitude: list[i].lon,
latitude: list[i].lat
}),
attributes: {
id: list[i].id,
dz_rank: list[i].dz_rank,
lon: list[i].lon,
lat: list[i].lat,
}
}))
}
// 过滤北京内数据
var mapArr = [];
gras.forEach((item, index) => {
if (geometryEngine.contains(geometryBeiJing, item.geometry))
{
mapArr.push(new Graphic({
geometry: item.geometry,
attributes: item.attributes
}))
}
})
//字段定义
var fields = []
for (var col in gras[0]['attributes']) {
let type = 'string'
if (col === 'lon' || col === 'lat') {
type = 'double'
} else {
type = 'integer'
}
fields.push({
name: col,
alias: col,
type: type
})
}
// 分级渲染
const less25 = {
type: 'picture-marker', // autocasts as new SimpleFillSymbol()
url: png1,
height: 12,
width: 10
}; const less50 = {
type: 'picture-marker', // autocasts as new SimpleFillSymbol()
url: png2,
height: 12,
width: 10
}; const less75 = {
type: 'picture-marker', // autocasts as new SimpleFillSymbol()
url: png3,
height: 12,
width: 10
}; const less100 = {
type: 'picture-marker', // autocasts as new SimpleFillSymbol()
url: png4,
height: 12,
width: 10
};
const renderer = {
type: 'class-breaks', // autocasts as new ClassBreaksRenderer()
field: 'dz_rank',
classBreakInfos: [
{
minValue: 0,
maxValue: 0.25,
symbol: less25,
label: '无震感'
},
{
minValue: 0.25,
maxValue: 0.5,
symbol: less100,
label: '轻微震感'
},
{
minValue: 0.5,
maxValue: 0.75,
symbol: less75,
label: '明显震感'
},
{
minValue: 0.75,
maxValue: 1.0,
symbol: less50,
label: '强烈震感'
}
],
legendOptions: {
title: '震感级别'
}
};
// 弹窗
let template = {
title: '{id}',
content: [
{
// Autocasts as new TextContent()
type: 'text',
text: '经度:{lon}'
},
{
// Autocasts as new TextContent()
type: 'text',
text: '纬度:{lat}'
},
{
// Autocasts as new TextContent()
type: 'text',
text: '震感级别:{dz_rank}'
},
{
// Autocasts as new TextContent()
type: 'text',
text: '描述:文字描述'
}
],
}
//定义图层
var layer = new FeatureLayer({
id: 'newLayer',
source: mapArr,
renderer: renderer,
geometryType: 'point',
fields: fields,
objectIdField: 'id',
popupTemplate: template
})
map.add(layer)
// 添加图例
const legend = new Legend({
view: view,
layerInfos: [{
layer: layer
}]
});
view.ui.add(legend, 'bottom-right');
}

这样就在全国的数据中过滤了北京的数据了,并在地图上进行了渲染

知识点是geometryEngine.contains(containerDiv, insideDiv)

最新文章

  1. git使用札记
  2. HTTP错误500.19-定义了重复的节点
  3. arcgis制作兴趣点分布图
  4. (ios) nsnotification总结
  5. JS 关闭 页面 浏览器 事件
  6. 大数据下多流形聚类分析之谱聚类SC
  7. android 网络编程之HttpURLConnection与HttpClient使用与封装
  8. 前端构建工具gulpjs
  9. 浏览器检测navigator 对象
  10. 自定义web浏览器(五)
  11. ubuntu install opengrok
  12. .Net 4.5 Task
  13. Scrapy的架构初探
  14. Codeforce D. Make a Permutation!
  15. 使用 pprof 和 Flame-Graph 调试 Golang 应用
  16. day07
  17. eclipse工具的使用心得
  18. java多线程(4)---volatile关键字
  19. JQ判断在不同分辨率电脑下使用不同的banner尺寸
  20. 转 基于Excel参数化你的Selenium2测试

热门文章

  1. Using mlock ulimits for SHM_HUGETLB is deprecated
  2. 使用 Docker 开发 - 使用多阶段构建镜像
  3. Promise内部实现原理
  4. Tallest Cow,题解
  5. Uni-app登录态管理(vuex)
  6. 深入Mybatis源码——配置解析
  7. 数据分析07 /matplotlib绘图
  8. Python面向对象06 /元类type、反射、函数与类的区别、特殊的双下方法
  9. bzoj2296【POJ Challenge】随机种子*
  10. Sequential Minimal Optimization: A Fast Algorithm for Training Support Vector Machines 论文研读