Trying to get a graphics layer that was created from JSON (using the whole webmap to JSON workflow) from one map in APRX to another map using arcpy.
I've tried this:
myLayer = map1.listLayers("myLayer")[0]
map2.addLayer(myLayer)
map2.listLayers()
The layer now shows up in the layer list. But I can't see it in the map. So I tried this:
layerDef = json.loads(Web_Map_as_JSON)['operationalLayers'][<index of layer>]
map2.addLayer(map1.listLayer("myLayer")[0]
map2.listLayers("myLayer")[0].updateLayerFromJSON(layerDef)
Everything runs without errors. I just don't get the added layer to display. Any suggestions?
Wanted to add a little more context in the hopes of garnering some feedback.
Using ConvertWebMapToArcGISProject to create a map. Now as part of the JSON, I'm ending up with a graphics layer. It looks something like this:
{
"mapOptions": {
...
},
...
},
"operationalLayers": [
{
"id": "defaultBasemap",
...
},
{
"id": "<map servce name>",
....
},
{
"id": "<mygraphicslayer>",
"opacity": 1,
"minScale": 0,
"maxScale": 0,
"featureCollection": {
"layers": [
{
"layerDefinition": {
"name": "pointLayer",
"geometryType": "esriGeometryPoint"
},
"featureSet": {
"geometryType": "esriGeometryPoint",
"features": [
{
"geometry": {
"x": someX,
"y": someY,
"spatialReference": {
"wkid": 102100
}
},
...
}
]
}
}
]
}
}
]
}
I can remove <mygraphicsLayer> from map by doing
mymap.removeLayer(mymap.listLayers("pointLayer")[0]
But I can't add this "pointLayer" to another map (see my first post).
Is there any way to grab a portion of the JSON above...
json.loads(Web_Map_as_JSON)['operationalLayers'][2]
to define a layer and add it to another map? Such as ...
json.loads(Web_Map_as_JSON)['operationalLayers'][2]["featureCollection"]["layers"][0] # doesnt seem to work
... or get some viable layer definition that can be fed into ...
arcpy.JSONToFeatures_conversion()
... and then add those to the other map?
Last ditch effort to find someone who knows...
These are steps I have taken to get me to where I am.
Nothing has worked so far. I even tried this:
myLayer = map1.listLayers('myLayer')[0]
myLayer.saveACopy(r"...\myLayer.lyrx")
map2.addLayer(arcpy.mp.LayerFile(r"...\mylayer.lyrx"))
Both map frames have same spatial reference and share other common service layers that display without any issues. Must be something about graphics.