当前位置: 首页 > wzjs >正文

动漫网站设计方案黑马程序员培训机构在哪

动漫网站设计方案,黑马程序员培训机构在哪,wordpress 支持中文用户名,阿里云服务器的网站备案流程一、什么是聚合 聚合是一种将一定范围内的多个图形合并为一个图形的一种技术方案。通常用来解决图形过于集中或者图形数量过多的问题。 在Openlayers中主要通过Cluster数据源来实现聚合的效果。与其它的数据源不同,Cluster数据源在实例化时需要接收一个矢量数据源…

一、什么是聚合

聚合是一种将一定范围内的多个图形合并为一个图形的一种技术方案。通常用来解决图形过于集中或者图形数量过多的问题。

在Openlayers中主要通过Cluster数据源来实现聚合的效果。与其它的数据源不同,Cluster数据源在实例化时需要接收一个矢量数据源作为参数,然后在将Cluster数据源作为一个矢量图层的数据源,这样就能实现对矢量数据源中图形的聚合。

二、如何实现聚合

1.点聚合

如果是有一些点要素需要全部进行聚合,像这种情况实现起来就非常简单,只需要通过distance属性(以像素为单位)设置好聚合的范围就可以了。

  // 矢量数据源const weatherStationSource = new VectorSource({format: new GeoJSON(),url: "src/data/气象站点/stations-wgs.geojson",});// 聚合数据源const clusterSource = new Cluster({distance: 40,source: weatherStationSource,});const weatherStationLayer = new VectorLayer({properties: {name: "气象站点",id: "weather-station",},source: clusterSource,});window.map.addLayer(weatherStationLayer);

聚合前:

聚合后:

2.部分图形聚合

有的时候我们并不希望将矢量数据源中的所有图形都参与聚合,这个时候可以通过geometryFunction属性进行设置。

geometryFunction属性是一个函数,该函数以一个要素(Feature)作为参数,并返回一个点(Point),以此作为该要素用于聚合计算的点。当某个要素不应被纳入聚类考虑范围时,该函数应返回null

注意,如果返回null就相当于矢量数据源中没有这个图形。

  // 矢量数据源const weatherStationSource = new VectorSource({format: new GeoJSON(),url: "src/data/气象站点/stations-wgs.geojson",});// 聚合数据源const clusterSource = new Cluster({distance: 40,source: weatherStationSource,geometryFunction: function (feature) {const type = feature.get("type");console.log(type);if (type == "基本站") {return null;}return feature.getGeometry();},});const weatherStationLayer = new VectorLayer({properties: {name: "气象站点",id: "weather-station",},source: clusterSource,});window.map.addLayer(weatherStationLayer);

3.其它图形的聚合

如果需要进行聚合的是点以外的其它图形,例如多边形,那么就必须设置geometryFunction属性,以指定用于聚合计算的点。对于多边形来说我们可以使用Polygon.getInteriorPoint()方法获取多边形的中心点来进行聚合计算。

  // 矢量数据源const polygonSource = new VectorSource({features: randomPolygonFeature(window.map, 1000),//随机生成1000个多边形});const clusterSource = new Cluster({distance: 40,source: polygonSource,geometryFunction: function (feature) {return feature.getGeometry().getInteriorPoint();},});const polygonLayer = new VectorLayer({properties: {name: "多边形图层",id: "polygonLayer",},source: clusterSource,});window.map.addLayer(polygonLayer);

聚合前:

聚合后:

4.自定义聚合图形

从之前的示例可以看到,聚合后的聚合图形都是点,如果希望使用其它的图形作为聚合图形,那就需要使用createCluster属性进行自定义。

createCluster属性也是一个函数,该函数接受聚合的中心点以及包含在该聚合中的要素数组作为参数。它必须返回一个将用于渲染的要素。

通过下面的代码就可以将一个小正方形作为聚合的图形:

  // 矢量数据源const polygonSource = new VectorSource({features: randomPolygonFeature(window.map, 1000),});const clusterSource = new Cluster({distance: 40,source: polygonSource,geometryFunction: function (feature) {return feature.getGeometry().getInteriorPoint();},createCluster: function (point, features) {// 定义中心点const centerPoint = point.getCoordinates();// 定义正方形的半边长const halfSideLength = 0.5;// 计算正方形的四个顶点const topLeft = [centerPoint[0] - halfSideLength,centerPoint[1] + halfSideLength,];const topRight = [centerPoint[0] + halfSideLength,centerPoint[1] + halfSideLength,];const bottomRight = [centerPoint[0] + halfSideLength,centerPoint[1] - halfSideLength,];const bottomLeft = [centerPoint[0] - halfSideLength,centerPoint[1] - halfSideLength,];// 创建正方形的多边形坐标const squareCoordinates = [topLeft,topRight,bottomRight,bottomLeft,topLeft, // 闭合多边形];// 创建多边形要素const squareFeature = new Feature({geometry: new Polygon([squareCoordinates]),features: features,});return squareFeature;},});const polygonLayer = new VectorLayer({properties: {name: "多边形图层",id: "polygonLayer",},source: clusterSource,});window.map.addLayer(polygonLayer);

三、优化聚合效果

1.显示聚合的数量

有一种常见的聚合优化的效果就是在聚合点上显示聚合的图形的数量。

这种效果需要通过给矢量图层设置样式来实现。

可以使用普通样式来实现:

  // 缓存样式const styleCache = new Map([[1,new Style({image: new CircleStyle({radius: 10,stroke: new Stroke({color: "#fff",}),fill: new Fill({color: "#3399CC",}),}),}),],]);weatherStationLayer.setStyle(function (feature) {const size = feature.get("features").length;let style = styleCache.get(size);if (!style) {style = new Style({image: new CircleStyle({radius: 10,stroke: new Stroke({color: "#fff",}),fill: new Fill({color: "#3399CC",}),}),text: new Text({text: size.toString(),fill: new Fill({color: "#fff",}),}),});styleCache.set(size, style);}return style;});

当然也可以使用flat样式实现:

  weatherStationLayer.setStyle([{filter: [">", ["get", "features", "length"], 1],style: [{"circle-radius": 10, //圆半径"circle-fill-color": "#3399CC", //圆填充颜色"circle-stroke-width": 1.25, //圆边框宽度"circle-stroke-color": "#fff", //圆边框颜色},{"text-value": ["to-string", ["get", "features", "length"]], //文本内容"text-fill-color": "#fff", //文本颜色},],},{else: true,style: [{"circle-radius": 10, //圆半径"circle-fill-color": "#3399CC", //圆填充颜色"circle-stroke-width": 1.25, //圆边框宽度"circle-stroke-color": "#fff", //圆边框颜色},],},]);

2.点击聚合点放大视图展示构成聚合点的要素

这是一个常用的聚合的交互效果,它基本的实现思路如下:

  map.on("click", e => {weatherStationLayer.getFeatures(e.pixel).then(clickedFeatures => {if (clickedFeatures.length) {// Get clustered Coordinatesconst features = clickedFeatures[0].get("features");if (features.length > 1) {const extent = boundingExtent(features.map(r => r.getGeometry().getCoordinates()));map.getView().fit(extent, { duration: 1000, padding: [50, 50, 50, 50] });}}});});

3.鼠标悬停到聚合点时展示构成该聚合点的各个要素

想要实现这种效果就不能继续使用地图事件了(其实也可以,但是会很麻烦),推荐通过 Select 交互来实现,它的style属性可以为选中的图形设置样式。

整体的思路如下:

  // 矢量数据源const weatherStationSource = new VectorSource({format: new GeoJSON(),url: "src/data/气象站点/stations-wgs.geojson",});// 聚合数据源const clusterSource = new Cluster({distance: 40,source: weatherStationSource,geometryFunction: function (feature) {const type = feature.get("type");if (type == "基本站") {return null;}return feature.getGeometry();},});// 矢量图层const weatherStationLayer = new VectorLayer({properties: {name: "气象站点",id: "weather-station",},source: clusterSource,});// 聚合样式weatherStationLayer.setStyle([{filter: [">", ["get", "features", "length"], 1],style: [{"circle-radius": 10, //圆半径"circle-fill-color": "#3399CC", //圆填充颜色"circle-stroke-width": 1.25, //圆边框宽度"circle-stroke-color": "#fff", //圆边框颜色},{"text-value": ["to-string", ["get", "features", "length"]], //文本内容"text-fill-color": "#fff", //文本颜色},],},{else: true,style: [{"circle-radius": 10, //圆半径"circle-fill-color": "#3399CC", //圆填充颜色"circle-stroke-width": 1.25, //圆边框宽度"circle-stroke-color": "#fff", //圆边框颜色},],},]);window.map.addLayer(weatherStationLayer);// 定义选中聚合点时的样式function selectStyleFunction(feature) {const styles = [new Style({image: new CircleStyle({radius: 10,fill: new Fill({color: "rgba(255, 255, 255, 0.01)",}),}),}),];const originalFeatures = feature.get("features");let originalFeature;for (let i = originalFeatures.length - 1; i >= 0; --i) {originalFeature = originalFeatures[i];styles.push(new Style({geometry: originalFeature.getGeometry(),image: new RegularShape({radius: 3,radius2: 7,points: 5,angle: Math.PI,fill: new Fill({color: "rgba(255, 153, 0, 0.8)",}),stroke: new Stroke({color: "rgba(255, 204, 0, 0.2)",width: 1,}),}),}));}return styles;}// 定义选中聚合点的交互const select = new Select({condition: function (evt) {return evt.type == "pointermove" || evt.type == "singleclick";},style: selectStyleFunction,});window.map.addInteraction(select);

参考资料

  1. OpenLayers v10.5.0 API - Class: Cluster
  2. Clustered Features
  3. Earthquake Clusters
  4. OpenLayers v10.5.0 API - Class: Select
http://www.dtcms.com/wzjs/154731.html

相关文章:

  • 华强北电子网站建设百度搜索排名推广
  • 视频直播系统源码百度seo视频教程
  • 网页设计与制作课程设计报告shu河北电子商务seo
  • 网站选服务器文件无锡百姓网推广
  • 视频网址链接哪里找昆明排名优化
  • ext做的网站成人职业培训机构
  • 做母婴产品的网站企业网站制作价格
  • wordpress 个人博客模板网站关键词快速优化
  • 如何网站公司小程序营销推广策划方案范文
  • 快手等视频网站做推广拼多多代运营收费标准
  • 0基础做下载网站网站如何优化排名软件
  • 模板做图 网站有哪些内容小程序开发平台有哪些
  • 河北网站建设报价十大计算机培训机构排名
  • 网站建设的论文谷歌商店下载官方正版
  • 高端网站制作 上海搜索引擎排名机制
  • 网站怎么靠前百度搜索网址大全
  • 厦门网站排名网络推广怎么做
  • 网站编辑是个长期做的工作吗前端seo主要优化哪些
  • 太平阳电脑网网站模板百度网盘下载慢
  • 重庆网站建设公司是什么百度指数是干嘛的
  • 成都营销型网站建设及推广那家好微帮推广平台怎么加入
  • 怎样用h5做网站优化器
  • 建设网站排名靠前百度做个人简介多少钱
  • 门户网站建设收费关键词排名靠前
  • 江苏建设网站公司简介百度小说排行榜第一名
  • wordpress网站源代码网络推广合作协议范本
  • 织梦网站模板怎么安装市场推广方案和思路
  • 上海网站开发怎么做做网站哪个平台好
  • 贵阳网站开发哪家专业网站排名查询平台
  • 友情链接交换百度seo排名报价