当前位置:   article > 正文

openlayers 入门(15)热力图_openlayers geoserver 栅格热力图

openlayers geoserver 栅格热力图
  1. <template>
  2. <div class="vm">
  3. <h2 class="h-title">热力图 Heatmap</h2>
  4. <label>半径大小</label>
  5. <input
  6. id="radius"
  7. type="range"
  8. min="1"
  9. max="50"
  10. step="1"
  11. v-model="radius"
  12. @change="changeRadius"
  13. />
  14. <label>模糊半径</label>
  15. <input
  16. id="blur"
  17. type="range"
  18. min="1"
  19. max="50"
  20. step="1"
  21. v-model="blur"
  22. @change="changeBlur"
  23. />
  24. <button @click="getHeatName">输出涂层名</button>
  25. <div id="map" class="map-x" ref="map"></div>
  26. </div>
  27. </template>
  28. <script>
  29. import "ol/ol.css";
  30. import { Map, View } from "ol";
  31. import { Heatmap, Tile } from "ol/layer";
  32. import { Vector as SourceVector, XYZ } from "ol/source"; // Stamen是底图
  33. import HeatData from "@/assets/data/heatData.json"; // 热力图数据
  34. import GeoJSON from "ol/format/GeoJSON"; // 解析geojson格式
  35. import { fromLonLat } from "ol/proj";
  36. export default {
  37. data() {
  38. return {
  39. map: null,
  40. radius: 5,
  41. blur: 15,
  42. vector: new Heatmap({
  43. // 热力图
  44. name: "热力热力",
  45. source: new SourceVector({
  46. features: new GeoJSON({
  47. featureProjection: "EPSG:3857",
  48. }).readFeatures(HeatData),
  49. format: new GeoJSON(),
  50. wrapX: true,
  51. }),
  52. radius: 10, // 半径大小
  53. blur: 10, // 模糊
  54. gradient: ["#00f", "#0ff", "#0f0", "#ff0", "#f00"], // 热力图颜色(可以不设置)
  55. }),
  56. };
  57. },
  58. methods: {
  59. // 初始化地图
  60. initMap() {
  61. let raster = new Tile({
  62. name: "defaultLayer",
  63. source: new XYZ({
  64. url: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}",
  65. }),
  66. });
  67. this.map = new Map({
  68. target: this.$refs.map,
  69. layers: [raster, this.vector],
  70. view: new View({
  71. center: fromLonLat([20.042007, -35.349998]),
  72. zoom: 5,
  73. }),
  74. });
  75. },
  76. // 修改半径大小
  77. changeRadius() {
  78. this.vector.setRadius(parseInt(this.radius, 10));
  79. },
  80. // 修改模糊半径
  81. changeBlur() {
  82. this.vector.setBlur(parseInt(this.blur, 10));
  83. },
  84. getHeatName() {
  85. let layers = this.map.getLayers();
  86. for (var i = 0; i < layers.getLength(); i++) {
  87. // console.log(layers.item(i))
  88. console.log("图层名:", layers.item(i).get("name"));
  89. }
  90. },
  91. },
  92. mounted() {
  93. this.initMap();
  94. },
  95. };
  96. </script>
  97. <style lang="scss" scoped></style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/935931
推荐阅读
相关标签
  

闽ICP备14008679号