Select to view content in your preferred language

add a custom image and a label for features

1772
6
Jump to solution
12-10-2018 08:16 AM
MRReddy
Regular Contributor

i was trying to add a custom picture.png file for features and a label  to it

for example:

buildingImage.png+(Building Id)

went to through some examples, but didn't helped me.

Any suggestions

Thanks

<!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>FeatureTable - Custom Menu Items</title>
  <link rel="stylesheet" href="https://js.arcgis.com/3.26/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="https://js.arcgis.com/3.26/esri/css/esri.css">
  <script src="https://js.arcgis.com/3.26/"></script>

  <style>
    html, body, #map {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
    }
  </style>

  <script>
    require([
      "esri/layers/FeatureLayer",
      "esri/geometry/Extent",
      "esri/graphicsUtils",
      "esri/tasks/query",
      "esri/map",
      "dojo/dom",
      "dojo/parser",
      "dojo/ready",
      "dojo/on",
      "dijit/layout/ContentPane",
      "dijit/layout/BorderContainer"
    ], function (
      FeatureLayer, Extent, graphicsUtils, Query, Map,
      dom, parser, ready, on, ContentPane, BorderContainer
    ) {

      parser.parse();

      ready(function(){
        var map = new Map("map",{
          basemap: "dark-gray", 
          extent: new Extent({xmax: -13035353.854156237, xmin: -13053431.211345658,
            ymax: 4038351.1313028745, ymin: 4034089.766975982,
            "spatialReference":{"wkid":102100,"latestWkid":3857}
          })
        });

        //Load a FeatureTable to the application once map loads
        map.on("load", loadTable);

        function loadTable(){
    
          // editable FeatureLayer
          var myFeatureLayer = new FeatureLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/RedlandsEmergencyVehicles/FeatureServer/...", {
            mode: FeatureLayer.MODE_ONDEMAND,
            outFields: ["*"],
            visible: true,
            id: "fLayer2"
          });

       
         
         
      
          map.addLayer(myFeatureLayer);

      
        
        }
      });
    });
  </script>
</head>
<body class="claro esri">
  <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline'" style="width:100%; height:100%;">
    <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center', splitter:true" style="height:50%">
      <div id="map"></div>
    </div>
    <div id="bot" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'bottom', splitter:true">
    
    </div>
  </div>
</body>
</html>
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Malla,

   You would need to define a UniqueValueRenderer for the FeatureLayer. ANd add unique values for each of the urls that will be used in your app. 

var defaultSymbol = new PictureMarkerSymbol(...);

//create renderer
var renderer = new UniqueValueRenderer(defaultSymbol, "SOME FIELD");

//add symbol for each possible value
renderer.addValue("BUILDING1", new PictureMarkerSymbol('http://www.esri.com/graphics/aexicon.jpg', 51, 51));‍‍‍‍‍‍‍

or forget using a FeatureLayer at all and just do a QueryTask to get the features you want to add to the map and add each feature to a GraphicsLayer in the map, that way you can define the Graphics symbol based on a fields value (if you have the url to the image stored in a field).

View solution in original post

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus

Malla,

   I am not clear at all on what you are wanting to do...

0 Kudos
MRReddy
Regular Contributor

Robert,

i want to change the image of points from layer  

0 Kudos
MRReddy
Regular Contributor

Robert,

i want to change the image of points from layer 

Thanks

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Malla,

  I see that this question has been marked "Assumed Answered" so you have figured this out yourself?

0 Kudos
MRReddy
Regular Contributor

Robert Scheitlin, GISP

i added label/text   to point by following below code, but i didn't figured to add an image.png  instead of point

for example instead of point i want to add   

https://i.pinimg.com/236x/a7/e5/a8/a7e5a8580157a9bc7a0e61da6395b3ba--high-rise-apartments-building-d... 

didn't find examples regarding to image change in javascript

 var layerdata = new FeatureLayer(State_Service, {
        mode: FeatureLayer.MODE_SNAPSHOT,
        infoTemplate: popupTemplate,
        outFields: ["*"],
    });
    
    var statesColor = new Color("crimson");
    var statesLabel = new TextSymbol().setColor(statesColor);
    statesLabel.setAlign(TextSymbol.ALIGN_MIDDLE);
    statesLabel.font.setSize("9pt");
    statesLabel.font.setFamily("arial");
    statesLabel.font.setWeight(esri.symbol.Font.WEIGHT_BOLD);
    var json = {
        "labelExpressionInfo": { "value": "{Name}" }
    };
    var labelClass = new LabelClass(json);
    labelClass.symbol = statesLabel;
    layerdata.setLabelingInfo([labelClass]);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Malla,

   You would need to define a UniqueValueRenderer for the FeatureLayer. ANd add unique values for each of the urls that will be used in your app. 

var defaultSymbol = new PictureMarkerSymbol(...);

//create renderer
var renderer = new UniqueValueRenderer(defaultSymbol, "SOME FIELD");

//add symbol for each possible value
renderer.addValue("BUILDING1", new PictureMarkerSymbol('http://www.esri.com/graphics/aexicon.jpg', 51, 51));‍‍‍‍‍‍‍

or forget using a FeatureLayer at all and just do a QueryTask to get the features you want to add to the map and add each feature to a GraphicsLayer in the map, that way you can define the Graphics symbol based on a fields value (if you have the url to the image stored in a field).

0 Kudos