gpt4 book ai didi

javascript - 如何在传单中设置 geoJSON FeatureCollection 的样式?

转载 作者:行者123 更新时间:2023-11-27 23:58:06 25 4
gpt4 key购买 nike

我正在尝试使用 L.geoJSON 设置 geoJSON FeatureCollection 的样式,但我未能成功偏离默认样式。

我已经尝试了 L.geoJSON 的文档(见下文),并将样式属性直接放入 geoJSON 功能中。这两个选项对图层的显示没有影响

//coordinates on map
var map = L.map('map').setView([29.76, -95.37], 10);
L.esri.basemapLayer('Gray').addTo(map);
var fromProjection = "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
var toProjection = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ";
var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
var myLayer = L.geoJSON(watersheds,{
coordsToLatLng: function (p) {
p = proj4(fromProjection,toProjection,p); // reproject each point
p = [p[1],p[0]] // swap the values
return p; // return the lat/lng pair
}},{
style: myStyle
}).addTo(map);

预期结果:我的层将是橙色的并且略微透明

实际效果:我的图层是默认的蓝色

(类似于:http://bl.ocks.org/andrew-reid/e472886c83819e8459178a4a56548449)

最佳答案

试试这个:

//coordinates on map
var map = L.map('map').setView([29.76, -95.37], 10);
L.esri.basemapLayer('Gray').addTo(map);
var fromProjection = "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
var toProjection = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ";
var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
myLayer = L.geoJson(watersheds, {
onEachFeature: function (feature, layer) {
layer.setStyle(feature.myStyle);

}
}).addTo(map);

关于javascript - 如何在传单中设置 geoJSON FeatureCollection 的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56277660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com