openlayers通过坐标点画出一块区域

本文介绍如何从GeoJSON本地文件中提取特定城市的坐标,并使用Angular和OpenLayers库将其显示为地图上的区域。通过JSON数据读取、坐标系转换及样式设置,实现了城市面状图的绘制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直接上代码:
其中的文件是json格式的本地文件,本地文件里坐标太多了,所以将里面的所需要的坐标匹配出来,然后写成json格式, 这样就通过坐标画出面了。

$.getJSON('../../scripts/shanxi-city.geo.json', function (city) {
                angular.forEach(city.features, function (item) {
                    if ($scope.city.name == item.properties.name) {
                        $scope.geoPoint = { features: [item], type: "FeatureCollection" }
                    }
                })
                var styles = [
                    new ol.style.Style({
                        stroke: new ol.style.Stroke({
                            color: '#5DA7D2',
                            width: 3
                        })
                    })
                ];
                var features = (new ol.format.GeoJSON()).readFeatures($scope.geoPoint, {     // 用readFeatures方法可以自定义坐标系
                    dataProjection: 'EPSG:4326',    // 设定JSON数据使用的坐标系
                    featureProjection: 'EPSG:3857' // 设定当前地图使用的feature的坐标系
                });
                var Source = new ol.source.Vector({
                    features: features
                });

                var vectorLayer = new ol.layer.Vector({
                    name: 'theData',
                    source: Source,
                    style: styles
                });
                console.log(vectorLayer)
                $scope.clear = vectorLayer
                // map.addLayer(vectorLayer);
            })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值