vue结合openlayers加载geojson,并根据不同级别渲染不同颜色

vue结合openlayers加载geojson,并根据不同级别渲染不同颜色

不同级别不同颜色样式的设置(面)
 let styleFunction = function(feature) {
                let dn = feature.get('dn');
                if (dn == 1) {
                  return new Style({
                    stroke: new Stroke({
                      color: '#5DC9DA',
                      width: 1,
                    }),
                    fill: new Fill({
                      color: '#5DC9DA',
                    }),
                  })
                } else if (dn == 2) {
                  return new Style({
                    stroke: new Stroke({
                      color: '#00758A',
                      width: 1,
                    }),
                    fill: new Fill({
                      color: '#00758A',
                    }),
                  })
                } 
                }
解读geojson并加入图层中
let vectorSource = new VectorSource({
              features: new GeoJSON().readFeatures(res.data.data),
            });
let vectorLayer1 = new VectorLayer({
              source: vectorSource,
              style: styleFunction,
              zIndex: 10,
            });
            _this.map.addLayer(vectorLayer1);
图层矢量点击高亮
const overlay = new Overlay({
              element: container,
              autoPan: true,
              autoPanAnimation: {
                duration: 250,
              },
            });
 const selectFocus = new Select({
              condition: EventType.click,
              layers: [_this.vectorLayer1],
              hitTolerance: 5,
              style: new Style({
                fill: new Fill({
                  color: "rgba(6, 255, 193, 0.8)",
                }),
                stroke: new Stroke({
                  color: "#ffcc33",
                  width: 1,
                }),
                image: new CircleStyle({
                  radius: 5,
                  fill: new Fill({
                    color: '#4CB49C',
                  }),
                  stroke: new Stroke({
                    color: '#4CB49C',
                    width: 3
                  }),
                })
              }),
            });
            _this.map.addInteraction(selectFocus);
selectFocus.on("select", function(e) {
              if (e.selected.length > 0) {
                let properties = e.selected[0].getProperties();
                console.log(properties)
                let siteName = properties.city;
                let coordinate
                if (data.cid == 1) {
                  coordinate = e.selected[0].getGeometry().flatCoordinates;
                } else {
                  coordinate = e.mapBrowserEvent.coordinate;
                  properties.area = properties.area.toFixed(2);
                }
                container.style.display = 'block';
                _this.selectData = properties;
                overlay.setPosition(coordinate);
                _this.map.addOverlay(overlay);
              } else if (e.deselected.length > 0) {
                overlay.setPosition(undefined);
                return false;
              }
            });
  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!对于VueOpenLayers结合使用返回围栏(fence)的问题,您可以按照以下步骤进行操作: 1. 首先,确保您已经安装了VueOpenLayers的依赖包。您可以使用以下命令进行安装: ``` npm install vue ol ``` 2. 在您的Vue组件中,引入OpenLayers的相关模块和样式,例如: ```javascript import 'ol/ol.css'; import { Map, View } from 'ol'; import { Tile as TileLayer, Vector as VectorLayer } from 'ol/layer'; import { OSM, Vector as VectorSource } from 'ol/source'; import { Draw, Modify } from 'ol/interaction'; import Feature from 'ol/Feature'; import GeometryType from 'ol/geom/GeometryType'; ``` 3. 在组件的`mounted`生命周期钩子中,创建地图和相关图层,并添交互操作。下面是一个示例: ```javascript mounted() { // 创建地图容器 const map = new Map({ target: 'map-container', layers: [ new TileLayer({ source: new OSM() }), new VectorLayer({ source: new VectorSource() }) ], view: new View({ center: [0, 0], zoom: 2 }) }); // 添绘制交互操作 const draw = new Draw({ source: map.getLayers().item(1).getSource(), type: GeometryType.POLYGON }); map.addInteraction(draw); // 添修改交互操作 const modify = new Modify({ source: map.getLayers().item(1).getSource() }); map.addInteraction(modify); // 监听绘制结束事件 draw.on('drawend', (event) => { const feature = event.feature; const geometry = feature.getGeometry(); // 这里可以处理绘制结束后的围栏数据,例如发送到后端进行保存或其他操作 console.log(geometry.getCoordinates()); }); } ``` 4. 在组件的模板中,添一个用于显示地图的容器: ```html <template> <div id="map-container"></div> </template> ``` 通过以上步骤,您可以在Vue中使用OpenLayers创建一个地图,并使用绘制交互操作绘制围栏。当绘制结束时,可以获取到围栏的坐标信息进行后续处理。 希望对您有所帮助!如有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值