Change marker layer's data source

2 posts, 0 answers
  1. Marc Arbesman
    Marc Arbesman avatar
    7 posts
    Member since:
    Feb 2006

    Posted 18 Jun 2014 Link to this post

    Hello,

    I am trying to set marks on a marker layer via JSON returned from my MVC controller.  I am capturing an onCriteriaChange event from a ListView.  In the event handler function I am try the following

    var mapData = $('#map').data('kendoMap');
            mapData.layers[1].dataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: ('@Url.Action("getMapData")'),
                        dataType: "json",
                        data: { customerId: customer.Id }
                    }
                }
            });
            mapData.layers[1].dataSource.read();

    My declaration code is 

    $("#map").kendoMap({
                              center: [30.268107, -97.744821],
                              zoom: 15,
                              layers: [{
                                  type: "tile",
                                  urlTemplate: "http://#= subdomain #.tile2.opencyclemap.org/transport/#= zoom #/#= x #/#= y #.png",
                                  subdomains: ["a", "b", "c"],
                                  attribution: "© <a href='http://osm.org/copyright'>OpenStreetMap contributors</a>." +
                                               "Tiles courtesy of <a href='http://www.opencyclemap.org/'>Andy Allan</a>"
                              },
                              {
                                  type: "marker",
                                  locationField: "latlng",
                                  titleField: "name",
                                  
                              }]
                          });

    so you can see the layer already exists.  I just want to set a marker for the lat, long returned by my controller.  

    I can verify that my controller is producing JSON (see attached screenshot).   But the markers do not show. Am I doing this correctly? Any help would be appreciated.

  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2770 posts

    Posted 20 Jun 2014 Link to this post

    Hello,

    The DataSource instance can't be replaced directly as there's no suitable setDataSource method.
    We'll add such method for the next release, but in the meantime you can use the following workaround:
    mapData.layers[1].options.dataSource = new kendo.data.DataSource({});
    mapData.layers[1]._initDataSource();

    Apologies for the caused inconvenience.
    As a token of gratitude for your involvement your Telerik points have been updated.

    Regards,
    T. Tsonev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top