Openlayers 5 icons are not showing on the map The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceOpenLayers vs Google Maps?OpenLayers: parsed GeoJSON points always display at coords(0 , 0)Measure segment length fix for OpenLayers 2.11How to show different popups on click and on mouseover?Changing OpenLayers marker iconHow to show a Google Map via OpenLayers on tiki-wiki 12+How to fix projection in my OpenLayers 4 projectHeatmap in Openlayers using an XML (KML formatted) string, styling is incorrectManipulate GeoJSON Data - reload vector Layer in OpenLayersOpenlayers: Add a list of Points to a Layer

How are presidential pardons supposed to be used?

How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?

Can smartphones with the same camera sensor have different image quality?

How should I replace vector<uint8_t>::const_iterator in an API?

How can I protect witches in combat who wear limited clothing?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?

How do you keep chess fun when your opponent constantly beats you?

How many people can fit inside Mordenkainen's Magnificent Mansion?

Simulating Exploding Dice

Relations between two reciprocal partial derivatives?

High Q peak in frequency response means what in time domain?

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

He got a vote 80% that of Emmanuel Macron’s

Does Parliament need to approve the new Brexit delay to 31 October 2019?

Cooking pasta in a water boiler

Arduino Pro Micro - switch off LEDs

How to test the equality of two Pearson correlation coefficients computed from the same sample?

Sort a list of pairs representing an acyclic, partial automorphism

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

Segmentation fault output is suppressed when piping stdin into a function. Why?

Can undead you have reanimated wait inside a portable hole?

Take groceries in checked luggage

Do warforged have souls?

Who or what is the being for whom Being is a question for Heidegger?



Openlayers 5 icons are not showing on the map



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceOpenLayers vs Google Maps?OpenLayers: parsed GeoJSON points always display at coords(0 , 0)Measure segment length fix for OpenLayers 2.11How to show different popups on click and on mouseover?Changing OpenLayers marker iconHow to show a Google Map via OpenLayers on tiki-wiki 12+How to fix projection in my OpenLayers 4 projectHeatmap in Openlayers using an XML (KML formatted) string, styling is incorrectManipulate GeoJSON Data - reload vector Layer in OpenLayersOpenlayers: Add a list of Points to a Layer



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm using OpenLayers 5 to create a simple map with icons on it. I have followed the Icon Colors example and it works. Now, I changed the source data from an array. I have, for example, four points to show on the map.



window.locs = [
"y": "52,51241",
"x": "13,38961"
,
"y": "52,52107",
"x": "13,38773"
,
"y": "52,52488",
"x": "13,40369"
,
"y": "52,54902",
"x": "13,41655"
];


I only change the part where we create the vector source, from manually setting one by one to using a loop.



for (var i in window.locs) 
var data = window.locs[i];
iconFeature = new ol.Feature(
geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(data.x.replace(",", ".")), parseFloat(data.y.replace(",", "."))]))
);

iconFeature.setStyle(new ol.style.Style(
image: new ol.style.Icon(/** @type module:ol/style/Icon~Options */(
color: [113, 140, 0],
crossOrigin: 'anonymous',
src: 'https://openlayers.org/en/v3.20.1/examples/data/dot.png'
))
));
window.iconFeatures.push(iconFeature);

var vectorSource = new ol.source.Vector(
features: window.iconFeatures
);


Unfortunately, the icons are not showing on the map. If I don't use the loop, the icons are shown. I have a lot of data and cannot assign the value one by one.



This is my JSFiddle: Fiddle



How can I resolve this?










share|improve this question



















  • 3





    Your fiddle needs map.addLayer(vectorLayer); Apart from that it seems to be working correctly.

    – Mike
    Mar 8 at 14:12











  • @Mike Wow. Thank you! Why don't they use 'addLayer' in the example though? There is no explanation about it there. And can you post this as an answer so I can accept it?

    – User2018
    Mar 8 at 14:23







  • 2





    The map is created after the layers so both layers can be included in the setup.

    – Mike
    Mar 8 at 14:28











  • Hi @Mike, can you post your comment as an answer so I can accept it?

    – User2018
    Mar 14 at 13:46

















0















I'm using OpenLayers 5 to create a simple map with icons on it. I have followed the Icon Colors example and it works. Now, I changed the source data from an array. I have, for example, four points to show on the map.



window.locs = [
"y": "52,51241",
"x": "13,38961"
,
"y": "52,52107",
"x": "13,38773"
,
"y": "52,52488",
"x": "13,40369"
,
"y": "52,54902",
"x": "13,41655"
];


I only change the part where we create the vector source, from manually setting one by one to using a loop.



for (var i in window.locs) 
var data = window.locs[i];
iconFeature = new ol.Feature(
geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(data.x.replace(",", ".")), parseFloat(data.y.replace(",", "."))]))
);

iconFeature.setStyle(new ol.style.Style(
image: new ol.style.Icon(/** @type module:ol/style/Icon~Options */(
color: [113, 140, 0],
crossOrigin: 'anonymous',
src: 'https://openlayers.org/en/v3.20.1/examples/data/dot.png'
))
));
window.iconFeatures.push(iconFeature);

var vectorSource = new ol.source.Vector(
features: window.iconFeatures
);


Unfortunately, the icons are not showing on the map. If I don't use the loop, the icons are shown. I have a lot of data and cannot assign the value one by one.



This is my JSFiddle: Fiddle



How can I resolve this?










share|improve this question



















  • 3





    Your fiddle needs map.addLayer(vectorLayer); Apart from that it seems to be working correctly.

    – Mike
    Mar 8 at 14:12











  • @Mike Wow. Thank you! Why don't they use 'addLayer' in the example though? There is no explanation about it there. And can you post this as an answer so I can accept it?

    – User2018
    Mar 8 at 14:23







  • 2





    The map is created after the layers so both layers can be included in the setup.

    – Mike
    Mar 8 at 14:28











  • Hi @Mike, can you post your comment as an answer so I can accept it?

    – User2018
    Mar 14 at 13:46













0












0








0








I'm using OpenLayers 5 to create a simple map with icons on it. I have followed the Icon Colors example and it works. Now, I changed the source data from an array. I have, for example, four points to show on the map.



window.locs = [
"y": "52,51241",
"x": "13,38961"
,
"y": "52,52107",
"x": "13,38773"
,
"y": "52,52488",
"x": "13,40369"
,
"y": "52,54902",
"x": "13,41655"
];


I only change the part where we create the vector source, from manually setting one by one to using a loop.



for (var i in window.locs) 
var data = window.locs[i];
iconFeature = new ol.Feature(
geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(data.x.replace(",", ".")), parseFloat(data.y.replace(",", "."))]))
);

iconFeature.setStyle(new ol.style.Style(
image: new ol.style.Icon(/** @type module:ol/style/Icon~Options */(
color: [113, 140, 0],
crossOrigin: 'anonymous',
src: 'https://openlayers.org/en/v3.20.1/examples/data/dot.png'
))
));
window.iconFeatures.push(iconFeature);

var vectorSource = new ol.source.Vector(
features: window.iconFeatures
);


Unfortunately, the icons are not showing on the map. If I don't use the loop, the icons are shown. I have a lot of data and cannot assign the value one by one.



This is my JSFiddle: Fiddle



How can I resolve this?










share|improve this question
















I'm using OpenLayers 5 to create a simple map with icons on it. I have followed the Icon Colors example and it works. Now, I changed the source data from an array. I have, for example, four points to show on the map.



window.locs = [
"y": "52,51241",
"x": "13,38961"
,
"y": "52,52107",
"x": "13,38773"
,
"y": "52,52488",
"x": "13,40369"
,
"y": "52,54902",
"x": "13,41655"
];


I only change the part where we create the vector source, from manually setting one by one to using a loop.



for (var i in window.locs) 
var data = window.locs[i];
iconFeature = new ol.Feature(
geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(data.x.replace(",", ".")), parseFloat(data.y.replace(",", "."))]))
);

iconFeature.setStyle(new ol.style.Style(
image: new ol.style.Icon(/** @type module:ol/style/Icon~Options */(
color: [113, 140, 0],
crossOrigin: 'anonymous',
src: 'https://openlayers.org/en/v3.20.1/examples/data/dot.png'
))
));
window.iconFeatures.push(iconFeature);

var vectorSource = new ol.source.Vector(
features: window.iconFeatures
);


Unfortunately, the icons are not showing on the map. If I don't use the loop, the icons are shown. I have a lot of data and cannot assign the value one by one.



This is my JSFiddle: Fiddle



How can I resolve this?







javascript html openlayers openlayers-5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 13:58







User2018

















asked Mar 8 at 13:42









User2018User2018

68111




68111







  • 3





    Your fiddle needs map.addLayer(vectorLayer); Apart from that it seems to be working correctly.

    – Mike
    Mar 8 at 14:12











  • @Mike Wow. Thank you! Why don't they use 'addLayer' in the example though? There is no explanation about it there. And can you post this as an answer so I can accept it?

    – User2018
    Mar 8 at 14:23







  • 2





    The map is created after the layers so both layers can be included in the setup.

    – Mike
    Mar 8 at 14:28











  • Hi @Mike, can you post your comment as an answer so I can accept it?

    – User2018
    Mar 14 at 13:46












  • 3





    Your fiddle needs map.addLayer(vectorLayer); Apart from that it seems to be working correctly.

    – Mike
    Mar 8 at 14:12











  • @Mike Wow. Thank you! Why don't they use 'addLayer' in the example though? There is no explanation about it there. And can you post this as an answer so I can accept it?

    – User2018
    Mar 8 at 14:23







  • 2





    The map is created after the layers so both layers can be included in the setup.

    – Mike
    Mar 8 at 14:28











  • Hi @Mike, can you post your comment as an answer so I can accept it?

    – User2018
    Mar 14 at 13:46







3




3





Your fiddle needs map.addLayer(vectorLayer); Apart from that it seems to be working correctly.

– Mike
Mar 8 at 14:12





Your fiddle needs map.addLayer(vectorLayer); Apart from that it seems to be working correctly.

– Mike
Mar 8 at 14:12













@Mike Wow. Thank you! Why don't they use 'addLayer' in the example though? There is no explanation about it there. And can you post this as an answer so I can accept it?

– User2018
Mar 8 at 14:23






@Mike Wow. Thank you! Why don't they use 'addLayer' in the example though? There is no explanation about it there. And can you post this as an answer so I can accept it?

– User2018
Mar 8 at 14:23





2




2





The map is created after the layers so both layers can be included in the setup.

– Mike
Mar 8 at 14:28





The map is created after the layers so both layers can be included in the setup.

– Mike
Mar 8 at 14:28













Hi @Mike, can you post your comment as an answer so I can accept it?

– User2018
Mar 14 at 13:46





Hi @Mike, can you post your comment as an answer so I can accept it?

– User2018
Mar 14 at 13:46












1 Answer
1






active

oldest

votes


















1














The layer needs to be added to the map



map.addLayer(vectorLayer);





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55064467%2fopenlayers-5-icons-are-not-showing-on-the-map%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The layer needs to be added to the map



    map.addLayer(vectorLayer);





    share|improve this answer



























      1














      The layer needs to be added to the map



      map.addLayer(vectorLayer);





      share|improve this answer

























        1












        1








        1







        The layer needs to be added to the map



        map.addLayer(vectorLayer);





        share|improve this answer













        The layer needs to be added to the map



        map.addLayer(vectorLayer);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 14 at 13:49









        MikeMike

        2,9302211




        2,9302211





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55064467%2fopenlayers-5-icons-are-not-showing-on-the-map%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved