我是靠谱客的博主 聪明帆布鞋,这篇文章主要介绍Openlayer以图片填充面,pattern填充,现在分享给大家,希望可以做个参考。

pattern填充无效:需要将方法写在img.onload事件中

var color =  "rgba(255,0,0,1)";

                var stroke = new ol.style.Stroke({

                    color: color,

                    width: 3

                    //lineDash: [10, 10]

                });

 

var cnv = document.createElement('canvas');

                var ctx = cnv.getContext('2d');

                var img = new Image();

                img.src = '../../../static/images/tb.png';

                img.onload = function () {

                    var pattern = ctx.createPattern(img, 'repeat');

                    var fill = new ol.style.Fill({

                        color:  pattern  //'rgba(0,0,0,0.2)'

                    });

                    var drawStyle = new ol.style.Style({

                        fill: fill,

                        stroke: stroke

                    });

                      //polygons为arcgis的features数组。

                    for(var i=0;i<polygons.length;i++){

                        var polygon=polygons[i];

                        //添加新要素feature

                        var polygonFeature = polygon;

                        if(polygon.geometry!=undefined&&polygon.geometry.rings!=undefined) {

                            polygonFeature = new ol.feature.Feature({

                                geometry: new ol.geometry.Polygon(polygon.geometry.rings),

                                attribute: polygon.attributes

                            });

                            polygonFeature.setStyle(drawStyle);

                            me.vectorLayer.layer.getSource().addFeature(polygonFeature);

                        }              

                    }

                };

最后

以上就是聪明帆布鞋最近收集整理的关于Openlayer以图片填充面,pattern填充的全部内容,更多相关Openlayer以图片填充面内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部