0

I have a question regarding creating a style object in openlayers 3. If Source of the Icon is given relative path its working fine.

var image = new ol.style.Icon({
   src : 'app/images/test.png'
});
var style =  new ol.style.Style({
   image : image
});

But if i give it absolute path its not taking it even if the image exists in that path.

var image = new ol.style.Icon({
   src : 'C:/test.png'
});
var style =  new ol.style.Style({
   image : image
});

Please tell me am i missing something? Thanks in advance

Faizaan Nawaz
  • 86
  • 2
  • 12
Sumanth Shastry
  • 1,139
  • 1
  • 19
  • 28

1 Answers1

0

I can't post comments because I don't have enough privilages, but when you say you are serving from the local file system, I assume your page url begins with file:/// (i.e., you are using file protocol) and not http://localhost (http protocol)? Because, due to browser security limitations accessing system files when you are using http protocol will not work. If you are using file protocol, have you tried using the prefix file:///? Also, these SO questions might help: Why can't I do <img src="C:/localfile.jpg">? and How do I view file:// images from http://localhost served pages in Firefox 11?.

Community
  • 1
  • 1
seto
  • 156
  • 1
  • 6
  • No Errors. Its just not rendering features. – Sumanth Shastry Apr 06 '16 at 13:19
  • Can you tell me the url of the page that you are accessing? Does it look something like this: file:///C:/Users/test/Downloads/Icon%20Symbolizer.html ? Also, are you using chrome? – seto Apr 06 '16 at 13:41
  • Yes URL looks similar to that and i am using IE 11 – Sumanth Shastry Apr 06 '16 at 17:06
  • It might be an error in path, IE console will not tell you if there is an error. If you try it in chrome, the debugger will tell you if there is an error. I have tried the following in chrome and IE and it worked: `var iconStyle = new ol.style.Style({ image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({ anchor: [0.5, 46], anchorXUnits: 'fraction', anchorYUnits: 'pixels', src: 'C:/Users/test/Downloads/images.png' })) });` But when I gave an incorrect path, there was no error message in IE, but chrome gave me an error. – seto Apr 07 '16 at 07:16
  • If you try in chrome you might get mor information. – seto Apr 07 '16 at 07:20
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/108485/discussion-between-seto-and-sumanth-shastry). – seto Apr 07 '16 at 08:05