Select to view content in your preferred language

LabelLayer (API version 3.13) is not working with Line FeatureLayer

4465
8
06-24-2015 04:47 AM
sivanadimpalli
Deactivated User

LabelLayer (API version 3.13) is not working with Line FeatureLayer and throwing an exception "Cannot read property 'labelRotation' of undefined".  But it is working properly in previous version(3.12).

0 Kudos
8 Replies
ChrisSergent
Deactivated User

I shared this in the ArcGIS API for JavaScript Space. More people that know about your topic will see it.

JayantaPoddar
MVP Alum

Hi Siva,

This space is for the contents related to Geonet Contest.

You might like to move this thread to ArcGIS API for JavaScript

Steps to move a content is given below.

Moving Content



Think Location
TomSellsted
MVP Alum

Siva,

Can you please post some of your code for this?  The error implies a rotation error, but viewing your code would give me some context to better understand what the problem might be.  Thanks!

Regards,

Tom

0 Kudos
sivanadimpalli
Deactivated User

Tom,

Below is the sample code for labeling line feature layer. This piece of code works properly if we use 3.12 API.

<!DOCTYPE html>

<html>

  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">

    <title></title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.13/esri/css/esri.css">

    <style>

      html, body, #map {

        height: 100%; width: 100%; margin: 0; padding: 0;

      }

    </style>

    <script src="http://js.arcgis.com/3.13/"></script>

    <script>

      var map;

   

      require([

        "esri/map", "esri/geometry/Extent", "esri/layers/FeatureLayer", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",

        "esri/symbols/TextSymbol", "esri/renderers/SimpleRenderer", "esri/layers/LabelLayer", "esri/Color", "dojo/domReady!"

      ], function(

        Map, Extent, FeatureLayer, SimpleLineSymbol, SimpleFillSymbol,

  TextSymbol, SimpleRenderer, LabelLayer,  Color

      ) {

        map = new Map("map", {

    basemap : 'topo',

    center: [-119.34563354630382, 35.21648028750361],

    zoom: 10

        });

        var sampleColor = new Color("#0033CC");

        var sampleLine = new SimpleLineSymbol("solid", sampleColor, 1.5);       

        var sampleRenderer = new SimpleRenderer(sampleLine);

  var sampleUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Military/FeatureServer/8";

        var sampleLayer = new FeatureLayer(sampleUrl, {

          id: "sampleLayer",

          outFields: ["*"]

        });

        sampleLayer.setRenderer(sampleRenderer);

        map.addLayer(sampleLayer);

        var sampleLabel = new TextSymbol().setColor(new Color("#663300"));

        sampleLabel.font.setSize("12pt");

        sampleLabel.font.setFamily("arial");

        var sampleLabelRenderer = new SimpleRenderer(sampleLabel);

        var labels = new LabelLayer({ id: "labels" });

        labels.addFeatureLayer(sampleLayer, sampleLabelRenderer, "{objectid}");

        map.addLayer(labels);

      });

    </script>

  </head>

  <body>

    <div id="map"></div>

  </body>

</html>

Regards,

  Siva

0 Kudos
TomSellsted
MVP Alum

Siva,

You are correct.  It works at 3.12 and does not at 3.13.  I dug into the LabelLayer.js to see what might be going on and the layer.options.labelRotation is set to true at 3.12 and is undefined at 3.13.  I tried to hack an option setting for labelRotation and it is ignored.

labels[options] = {labelRotation: true};

I have also scoured the documentation and haven't found a proper way to set a labelRotation option.  It appears to be a bug or an undocumented property.

Maybe Kelly Hutchins​ would have a answer?

Regards,

Tom

KellyHutchins
Esri Notable Contributor

Siva,

This looks like an issue you should contact Esri Support about. Could be a bug with the current version of the API.

sivanadimpalli
Deactivated User

Tom & Kelly,

Thanks for your time.

I resolved this issue by host the JavaScript API locally and modify LabelLayer.js to handle the layer options error.

Existing code:

"polyline"==f.layer.geometry.type&&f.layer.options.labelRotation?l.setAngle(m*(180/Math.PI)):l.setAngle(0);

Replaced code:

"polyline"==f.layer.geometry.type&&f.layer.options&&f.layer.options.labelRotation?l.setAngle(m*(180/Math.PI)):"polyline"==f.layer.geometry.type&&m?l.setAngle(m*(180/Math.PI)):l.setAngle(0);

I made these changes without distributing the existing logic, and it works for me.

Regards,

  Siva

TomSellsted
MVP Alum

Siva,

Glad you found a workaround that will work for you.

Regards,

tom

0 Kudos