javascript - OpenLayers3 add Text over Circle -


after searching lot, managed find block of code allows me draw circle on map.

html:

<div id="mapholder"></div> 

css:

#mapholder{   width: 100%;   height: 200px;   background-color: #ccc; } 

javascript:

$(document).ready(function(){   var map = new ol.map({           target: 'mapholder',           interactions: ol.interaction.defaults({mousewheelzoom:false}),           layers: [             new ol.layer.tile({               source: new ol.source.osm()             })           ],           view: new ol.view({             center: ol.proj.transform([parsefloat(8.680239), parsefloat(50.114034)], 'epsg:4326','epsg:3857'),         zoom: 13           })         });      var vectorsource = new ol.source.vector();   var circlelayer = new ol.layer.vector({     source: vectorsource   });   map.addlayer(circlelayer);    var coordinate = ol.proj.transform([parsefloat(8.680239), parsefloat(50.114034)], 'epsg:4326','epsg:3857');   vectorsource.addfeature(new ol.feature(new ol.geom.circle(coordinate, 2000)));  }); 

this fiddle: https://jsfiddle.net/79hjbxw9/

1) how can put text on circle title "approximate area"; , able define color , font.

2) want change color , thickness of circle border.

you can using style on vector layer.

declare style

     var mystlye = new ol.style.style ({       fill: new ol.style.fill({          color: 'rgba(255,100,50,0.5)'        }),        stroke: new ol.style.stroke({          color: 'blue',          width: 3        }),        text: new ol.style.text({          textalign: "start",          textbaseline: "middle",          font: 'normal 12px arial',          text: 'approximate area',          fill: new ol.style.fill({            color: '#ffa500'          }),          stroke: new ol.style.stroke({            color: '#000000',            width: 3          }),          offsetx: -45,          offsety: 0,          rotation: 0        })     }); 

and attach layer

 var circlelayer = new ol.layer.vector({         style:mystlye,         source: vectorsource       }); 

here fiddle see in action


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -