Select to view content in your preferred language

Why does fromArcGISServerUrl not support popups?

676
5
03-08-2018 09:26 AM
Travis_L_Riffle
New Contributor II

I can load a feature layer, but the popup data associated with the FeatureLayer does not work. 

I can load the same item by calling fromPortalItem and it has popups.  Is there a way to load a FeatureLayer by URL instead of ID that will allow popups??

Here's a code example of a FeatureLayer I created for a coffee shop in Phoenix.  If I query by id, the popup shows, but if I query by the service URL, the coffee shop shows but not the popup.

SANDBOX EXAMPLE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>FeatureLayer - 4.6</title>

<link rel="stylesheet" href="https://js.arcgis.com/4.6/esri/css/main.css">
<script src="https://js.arcgis.com/4.6/"></script>

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

<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/Layer",
"esri/layers/FeatureLayer",
"esri/widgets/Popup",
"dojo/domReady!"
],
function(
Map, MapView, Layer,
FeatureLayer, Popup
) {

var map = new Map({
basemap: "hybrid"
});

var view = new MapView({
container: "viewDiv",
map: map,

extent: { // autocasts as new Extent()
xmin: -9177811,
ymin: 4247000,
xmax: -9176791,
ymax: 4247784,
spatialReference: 102100
}
});

/********************
* Add feature layer
********************/

// Carbon storage of trees in Warren Wilson College.
var featureLayer = new FeatureLayer({
url: "https://services5.arcgis.com/QGM0VeSNqhUanPGN/arcgis/rest/services/Coffee_Shops__Custom_Data_Sample/..."
});

map.add(featureLayer);
});
</script>
</head>

<body>
<div id="viewDiv"></div>
</body>

</html>

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Travis,

   Using a webmap or portalitem is what carries over the popup configuration. Using the url to create a new FeatureLayer has no knowledge of the popup you configured in the web map.

0 Kudos
Travis_L_Riffle
New Contributor II

There doesn't seem to be a way to query a portal item by service URL.  You can set the URL property of the portal item, but that doesn't return anything. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Travis,

   You have completely lost me here. If you want access to the layer popup you configured in Portal/AGOL then you need to use the WebMap ID in your code.

You get a PortalItem from a Portal class query method:

https://developers.arcgis.com/javascript/3/jsapi/portal-amd.html#queryitems 

0 Kudos
Travis_L_Riffle
New Contributor II

We are using the 4.6 version of the API.  We are wanting to use the service URL to retrieve the portal Item.  You can retrieve the feature layer without the popup with the fromArcGisServerUrl method or fromPortalItem method which returns the popup.  I'm trying to use the service URL to return the portalItem/feature layer with the popup.  

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Travis,

   As I have mentioned already the layer.fromArcGisServerUrl just creates a new layer that has no concept of a popup that was configured using AGOL/Portal. Let me try and break this down for you. The portalItem/WebMap is a json text that stores information like the popup and symbology and other items along with the url to the specific service that is used. A url to a map service does not have access to any of this information as it is just accessing the MapService directly on ArcGIS Server.

Hopefully this clears things up for you.

0 Kudos