difference between URL and Loader on Vector Source - openlayers 3












0















I have to load a WFS layer from my Geoserver to my website with Openlayers 3.9.0.



According to the manual there are two options to load features, loader(ol.FeatureLoader) and url (ol.FeatureUrlFunction).



I dont get the difference between the two. They both used to load features, loader, does not set any URL and looks more complicated.



I try



var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
loader: function(extent){
$.ajax({
url: url,
type:'GET',
dataType: 'jsonp'
}).done(loadFeatures);
},
strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
});

var loadFeatures = function(response) {
var features = vectorSource.readFeatures(response);
vectorSource.addFeatures(features);
};


and no errors at all, but also no features.



Then I simply setted



var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20})),
url: function(extent, resolution, projection){return url}
});


and worked.



I dont get the difference, url is simler, quicker and does not require a loadFeatures function. I red the manual, but in practice, in terms of code, I cannot understand it. What is loader for, why it does not set a URL and when to use it? What am I missing here?



Thanks










share|improve this question





























    0















    I have to load a WFS layer from my Geoserver to my website with Openlayers 3.9.0.



    According to the manual there are two options to load features, loader(ol.FeatureLoader) and url (ol.FeatureUrlFunction).



    I dont get the difference between the two. They both used to load features, loader, does not set any URL and looks more complicated.



    I try



    var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
    var vectorSource = new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    loader: function(extent){
    $.ajax({
    url: url,
    type:'GET',
    dataType: 'jsonp'
    }).done(loadFeatures);
    },
    strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
    });

    var loadFeatures = function(response) {
    var features = vectorSource.readFeatures(response);
    vectorSource.addFeatures(features);
    };


    and no errors at all, but also no features.



    Then I simply setted



    var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
    var vectorSource = new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20})),
    url: function(extent, resolution, projection){return url}
    });


    and worked.



    I dont get the difference, url is simler, quicker and does not require a loadFeatures function. I red the manual, but in practice, in terms of code, I cannot understand it. What is loader for, why it does not set a URL and when to use it? What am I missing here?



    Thanks










    share|improve this question



























      0












      0








      0








      I have to load a WFS layer from my Geoserver to my website with Openlayers 3.9.0.



      According to the manual there are two options to load features, loader(ol.FeatureLoader) and url (ol.FeatureUrlFunction).



      I dont get the difference between the two. They both used to load features, loader, does not set any URL and looks more complicated.



      I try



      var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
      var vectorSource = new ol.source.Vector({
      format: new ol.format.GeoJSON(),
      loader: function(extent){
      $.ajax({
      url: url,
      type:'GET',
      dataType: 'jsonp'
      }).done(loadFeatures);
      },
      strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
      });

      var loadFeatures = function(response) {
      var features = vectorSource.readFeatures(response);
      vectorSource.addFeatures(features);
      };


      and no errors at all, but also no features.



      Then I simply setted



      var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
      var vectorSource = new ol.source.Vector({
      format: new ol.format.GeoJSON(),
      strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20})),
      url: function(extent, resolution, projection){return url}
      });


      and worked.



      I dont get the difference, url is simler, quicker and does not require a loadFeatures function. I red the manual, but in practice, in terms of code, I cannot understand it. What is loader for, why it does not set a URL and when to use it? What am I missing here?



      Thanks










      share|improve this question
















      I have to load a WFS layer from my Geoserver to my website with Openlayers 3.9.0.



      According to the manual there are two options to load features, loader(ol.FeatureLoader) and url (ol.FeatureUrlFunction).



      I dont get the difference between the two. They both used to load features, loader, does not set any URL and looks more complicated.



      I try



      var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
      var vectorSource = new ol.source.Vector({
      format: new ol.format.GeoJSON(),
      loader: function(extent){
      $.ajax({
      url: url,
      type:'GET',
      dataType: 'jsonp'
      }).done(loadFeatures);
      },
      strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
      });

      var loadFeatures = function(response) {
      var features = vectorSource.readFeatures(response);
      vectorSource.addFeatures(features);
      };


      and no errors at all, but also no features.



      Then I simply setted



      var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
      var vectorSource = new ol.source.Vector({
      format: new ol.format.GeoJSON(),
      strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20})),
      url: function(extent, resolution, projection){return url}
      });


      and worked.



      I dont get the difference, url is simler, quicker and does not require a loadFeatures function. I red the manual, but in practice, in terms of code, I cannot understand it. What is loader for, why it does not set a URL and when to use it? What am I missing here?



      Thanks







      vector openlayers-3






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 22 '16 at 14:35









      Jose Gómez

      1,9071741




      1,9071741










      asked Oct 14 '15 at 18:36









      user2860857user2860857

      1691616




      1691616
























          2 Answers
          2






          active

          oldest

          votes


















          1














          The first reason that comes to mind: to catch errors. If your server is able to catch errors and return them inside the response, you might want to read them inside your loader and act accordingly.



          A second reason would be to compute/execute some operations before those features are added to the source. Here's an example in an other thread from StackOverflow. It features both these reasons to use a loader.



          If you do not need to do anything special with your data before it's being added or if you do not need to manage errors, then url is enough for your requirements, indeed.






          share|improve this answer


























          • OK, makes sense now. By the way, any ideas on why the loader version does not work? Thanks again

            – user2860857
            Oct 15 '15 at 14:32






          • 1





            Hi. If you could create a JSFiddle, I'd be happy to help into looking what's wrong.

            – Alexandre Dubé
            Oct 15 '15 at 18:30











          • Check this out. I dont know why it does not work. I use jQuery 1.11.3 not 1.11.0. If I replace http://demo.opengeo.org/geoserver/wfs with http://localhost:3000/geoserver/mymap/wfs it does not work even though I see no errors. wfs GET has status 200 OK. I dont get it, it looks fine to me, I can spot the bug. Any tip would be great. Thank you

            – user2860857
            Oct 15 '15 at 20:50













          • My code is based on this. I also uses Openlayers 3.9.0

            – user2860857
            Oct 15 '15 at 20:55






          • 1





            The query works fine, however there seems to be something wrong with the reading of the geometry. See you updated example: jsfiddle.net/cn8jsdmz/3 This would be something not related to this thread, so I suggest you start a new one if you can't figure the issue out.

            – Alexandre Dubé
            Oct 16 '15 at 12:29



















          0














          Mybe this will work better



          var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
          var vectorSource = new ol.source.Vector({
          format: new ol.format.GeoJSON(),
          loader: function(extent, resolution, projection){
          $.ajax({
          url: url,
          type:'GET',
          dataType: 'jsonp'
          }).done(function(response) {

          var features = vectorSource.readFeatures(response, {
          featureProjection: projection
          });

          vectorSource.addFeatures(features);
          });
          },
          strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
          });





          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%2f33133069%2fdifference-between-url-and-loader-on-vector-source-openlayers-3%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The first reason that comes to mind: to catch errors. If your server is able to catch errors and return them inside the response, you might want to read them inside your loader and act accordingly.



            A second reason would be to compute/execute some operations before those features are added to the source. Here's an example in an other thread from StackOverflow. It features both these reasons to use a loader.



            If you do not need to do anything special with your data before it's being added or if you do not need to manage errors, then url is enough for your requirements, indeed.






            share|improve this answer


























            • OK, makes sense now. By the way, any ideas on why the loader version does not work? Thanks again

              – user2860857
              Oct 15 '15 at 14:32






            • 1





              Hi. If you could create a JSFiddle, I'd be happy to help into looking what's wrong.

              – Alexandre Dubé
              Oct 15 '15 at 18:30











            • Check this out. I dont know why it does not work. I use jQuery 1.11.3 not 1.11.0. If I replace http://demo.opengeo.org/geoserver/wfs with http://localhost:3000/geoserver/mymap/wfs it does not work even though I see no errors. wfs GET has status 200 OK. I dont get it, it looks fine to me, I can spot the bug. Any tip would be great. Thank you

              – user2860857
              Oct 15 '15 at 20:50













            • My code is based on this. I also uses Openlayers 3.9.0

              – user2860857
              Oct 15 '15 at 20:55






            • 1





              The query works fine, however there seems to be something wrong with the reading of the geometry. See you updated example: jsfiddle.net/cn8jsdmz/3 This would be something not related to this thread, so I suggest you start a new one if you can't figure the issue out.

              – Alexandre Dubé
              Oct 16 '15 at 12:29
















            1














            The first reason that comes to mind: to catch errors. If your server is able to catch errors and return them inside the response, you might want to read them inside your loader and act accordingly.



            A second reason would be to compute/execute some operations before those features are added to the source. Here's an example in an other thread from StackOverflow. It features both these reasons to use a loader.



            If you do not need to do anything special with your data before it's being added or if you do not need to manage errors, then url is enough for your requirements, indeed.






            share|improve this answer


























            • OK, makes sense now. By the way, any ideas on why the loader version does not work? Thanks again

              – user2860857
              Oct 15 '15 at 14:32






            • 1





              Hi. If you could create a JSFiddle, I'd be happy to help into looking what's wrong.

              – Alexandre Dubé
              Oct 15 '15 at 18:30











            • Check this out. I dont know why it does not work. I use jQuery 1.11.3 not 1.11.0. If I replace http://demo.opengeo.org/geoserver/wfs with http://localhost:3000/geoserver/mymap/wfs it does not work even though I see no errors. wfs GET has status 200 OK. I dont get it, it looks fine to me, I can spot the bug. Any tip would be great. Thank you

              – user2860857
              Oct 15 '15 at 20:50













            • My code is based on this. I also uses Openlayers 3.9.0

              – user2860857
              Oct 15 '15 at 20:55






            • 1





              The query works fine, however there seems to be something wrong with the reading of the geometry. See you updated example: jsfiddle.net/cn8jsdmz/3 This would be something not related to this thread, so I suggest you start a new one if you can't figure the issue out.

              – Alexandre Dubé
              Oct 16 '15 at 12:29














            1












            1








            1







            The first reason that comes to mind: to catch errors. If your server is able to catch errors and return them inside the response, you might want to read them inside your loader and act accordingly.



            A second reason would be to compute/execute some operations before those features are added to the source. Here's an example in an other thread from StackOverflow. It features both these reasons to use a loader.



            If you do not need to do anything special with your data before it's being added or if you do not need to manage errors, then url is enough for your requirements, indeed.






            share|improve this answer















            The first reason that comes to mind: to catch errors. If your server is able to catch errors and return them inside the response, you might want to read them inside your loader and act accordingly.



            A second reason would be to compute/execute some operations before those features are added to the source. Here's an example in an other thread from StackOverflow. It features both these reasons to use a loader.



            If you do not need to do anything special with your data before it's being added or if you do not need to manage errors, then url is enough for your requirements, indeed.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 23 '17 at 10:28









            Community

            11




            11










            answered Oct 14 '15 at 19:34









            Alexandre DubéAlexandre Dubé

            2,23711025




            2,23711025













            • OK, makes sense now. By the way, any ideas on why the loader version does not work? Thanks again

              – user2860857
              Oct 15 '15 at 14:32






            • 1





              Hi. If you could create a JSFiddle, I'd be happy to help into looking what's wrong.

              – Alexandre Dubé
              Oct 15 '15 at 18:30











            • Check this out. I dont know why it does not work. I use jQuery 1.11.3 not 1.11.0. If I replace http://demo.opengeo.org/geoserver/wfs with http://localhost:3000/geoserver/mymap/wfs it does not work even though I see no errors. wfs GET has status 200 OK. I dont get it, it looks fine to me, I can spot the bug. Any tip would be great. Thank you

              – user2860857
              Oct 15 '15 at 20:50













            • My code is based on this. I also uses Openlayers 3.9.0

              – user2860857
              Oct 15 '15 at 20:55






            • 1





              The query works fine, however there seems to be something wrong with the reading of the geometry. See you updated example: jsfiddle.net/cn8jsdmz/3 This would be something not related to this thread, so I suggest you start a new one if you can't figure the issue out.

              – Alexandre Dubé
              Oct 16 '15 at 12:29



















            • OK, makes sense now. By the way, any ideas on why the loader version does not work? Thanks again

              – user2860857
              Oct 15 '15 at 14:32






            • 1





              Hi. If you could create a JSFiddle, I'd be happy to help into looking what's wrong.

              – Alexandre Dubé
              Oct 15 '15 at 18:30











            • Check this out. I dont know why it does not work. I use jQuery 1.11.3 not 1.11.0. If I replace http://demo.opengeo.org/geoserver/wfs with http://localhost:3000/geoserver/mymap/wfs it does not work even though I see no errors. wfs GET has status 200 OK. I dont get it, it looks fine to me, I can spot the bug. Any tip would be great. Thank you

              – user2860857
              Oct 15 '15 at 20:50













            • My code is based on this. I also uses Openlayers 3.9.0

              – user2860857
              Oct 15 '15 at 20:55






            • 1





              The query works fine, however there seems to be something wrong with the reading of the geometry. See you updated example: jsfiddle.net/cn8jsdmz/3 This would be something not related to this thread, so I suggest you start a new one if you can't figure the issue out.

              – Alexandre Dubé
              Oct 16 '15 at 12:29

















            OK, makes sense now. By the way, any ideas on why the loader version does not work? Thanks again

            – user2860857
            Oct 15 '15 at 14:32





            OK, makes sense now. By the way, any ideas on why the loader version does not work? Thanks again

            – user2860857
            Oct 15 '15 at 14:32




            1




            1





            Hi. If you could create a JSFiddle, I'd be happy to help into looking what's wrong.

            – Alexandre Dubé
            Oct 15 '15 at 18:30





            Hi. If you could create a JSFiddle, I'd be happy to help into looking what's wrong.

            – Alexandre Dubé
            Oct 15 '15 at 18:30













            Check this out. I dont know why it does not work. I use jQuery 1.11.3 not 1.11.0. If I replace http://demo.opengeo.org/geoserver/wfs with http://localhost:3000/geoserver/mymap/wfs it does not work even though I see no errors. wfs GET has status 200 OK. I dont get it, it looks fine to me, I can spot the bug. Any tip would be great. Thank you

            – user2860857
            Oct 15 '15 at 20:50







            Check this out. I dont know why it does not work. I use jQuery 1.11.3 not 1.11.0. If I replace http://demo.opengeo.org/geoserver/wfs with http://localhost:3000/geoserver/mymap/wfs it does not work even though I see no errors. wfs GET has status 200 OK. I dont get it, it looks fine to me, I can spot the bug. Any tip would be great. Thank you

            – user2860857
            Oct 15 '15 at 20:50















            My code is based on this. I also uses Openlayers 3.9.0

            – user2860857
            Oct 15 '15 at 20:55





            My code is based on this. I also uses Openlayers 3.9.0

            – user2860857
            Oct 15 '15 at 20:55




            1




            1





            The query works fine, however there seems to be something wrong with the reading of the geometry. See you updated example: jsfiddle.net/cn8jsdmz/3 This would be something not related to this thread, so I suggest you start a new one if you can't figure the issue out.

            – Alexandre Dubé
            Oct 16 '15 at 12:29





            The query works fine, however there seems to be something wrong with the reading of the geometry. See you updated example: jsfiddle.net/cn8jsdmz/3 This would be something not related to this thread, so I suggest you start a new one if you can't figure the issue out.

            – Alexandre Dubé
            Oct 16 '15 at 12:29













            0














            Mybe this will work better



            var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
            var vectorSource = new ol.source.Vector({
            format: new ol.format.GeoJSON(),
            loader: function(extent, resolution, projection){
            $.ajax({
            url: url,
            type:'GET',
            dataType: 'jsonp'
            }).done(function(response) {

            var features = vectorSource.readFeatures(response, {
            featureProjection: projection
            });

            vectorSource.addFeatures(features);
            });
            },
            strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
            });





            share|improve this answer




























              0














              Mybe this will work better



              var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
              var vectorSource = new ol.source.Vector({
              format: new ol.format.GeoJSON(),
              loader: function(extent, resolution, projection){
              $.ajax({
              url: url,
              type:'GET',
              dataType: 'jsonp'
              }).done(function(response) {

              var features = vectorSource.readFeatures(response, {
              featureProjection: projection
              });

              vectorSource.addFeatures(features);
              });
              },
              strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
              });





              share|improve this answer


























                0












                0








                0







                Mybe this will work better



                var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
                var vectorSource = new ol.source.Vector({
                format: new ol.format.GeoJSON(),
                loader: function(extent, resolution, projection){
                $.ajax({
                url: url,
                type:'GET',
                dataType: 'jsonp'
                }).done(function(response) {

                var features = vectorSource.readFeatures(response, {
                featureProjection: projection
                });

                vectorSource.addFeatures(features);
                });
                },
                strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
                });





                share|improve this answer













                Mybe this will work better



                var url =  'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'    
                var vectorSource = new ol.source.Vector({
                format: new ol.format.GeoJSON(),
                loader: function(extent, resolution, projection){
                $.ajax({
                url: url,
                type:'GET',
                dataType: 'jsonp'
                }).done(function(response) {

                var features = vectorSource.readFeatures(response, {
                featureProjection: projection
                });

                vectorSource.addFeatures(features);
                });
                },
                strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
                });






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 3:37







                user5496249





































                    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%2f33133069%2fdifference-between-url-and-loader-on-vector-source-openlayers-3%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

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python