Hi all,
I am trying to clone a Web App but have it centered over a new area (new city for example) and i was wondering if I could use the item_extent parameter from clone_items to achieve this. Anyone have any ideas?
Thanks!
@JLBlair Thank you so much. I have spent half a day trying to figure this out and your solution works perfectly and should be the accepted answer to this question
Hello, I just wrestled with this too. I am copying from a template webmap that has a Field Maps customization, so I wish to have those edit layers- but I then need to change the extent of the webmap to fit different areas of interest.
This works for me:
# Get the template webmap item ID Template_WebMap_Item = gis.content.get('cf6eec40dbd644d99b4645547e2614d5') # Create a WebMap object from an existing web map item Template_map_obj = WebMap(Template_WebMap_Item) # Update the properties for new map wm_properties = {'title' : 'New Web Map {0}'.format(EventAliasName), 'snippet': "Web map for earthquake response data acquisition", 'tags' : 'Observations', 'type': 'Web Map' } # Add a layer unique to this event Template_map_obj.add_layer(ShakeMap_MI_layer) # Save the webmap to the new Event Folder TheEventMap = Template_map_obj.save(item_properties = wm_properties, folder=event_folder) # Get the text data associated with the new webmap item theEventMap_data = TheEventMap.get_data() # Examine the 'initialState' key print(theEventMap_data['initialState']) # {'viewpoint': {'targetGeometry': {'spatialReference': {'latestWkid': 3857, 'wkid': 102100}, 'xmin': -14142684.7214327, 'ymin': 4011415.2444049953, 'xmax': -12384021.574647833, 'ymax': 5128007.353594553}}} # Generate a new initialState key using a specific feature layer extent. Or do this manually New_Istate = {'viewpoint': {'targetGeometry': {'spatialReference': {'latestWkid': ShakeMap_MI_layer.properties.extent.spatialReference.latestWkid, 'wkid': ShakeMap_MI_layer.properties.extent.spatialReference.wkid}, 'xmin': ShakeMap_MI_layer.properties.extent['xmin'], 'ymin': ShakeMap_MI_layer.properties.extent['ymin'], 'xmax': ShakeMap_MI_layer.properties.extent['xmax'], 'ymax': ShakeMap_MI_layer.properties.extent['ymax']}}} # Update the webmap item theEventMap_data['initialState'] = New_Istate TheEventMap.update(item_properties={"text": json.dumps(theEventMap_data)})
The new saved webmap now has the desired extent upon loading it.
Note the last line here. Formatting correctly the 'item_properties' in the update method seems to be critical element here. I learned this from this thread.
Luke
I would also like to get some more information on this. I can't find anything online. I've tried the following, but when I open the cloned WebMap, the extent remains unchanged:
ext ={'spatialReference': {'latestWkid': 3857, 'wkid': 102100}, 'xmin': -1252724.3668020056, 'ymin': 4250996.361644156, 'xmax': -84766.57460482302, 'ymax': 4740193.342669154} cloned_item = mygis.content.clone_items(items=[temp_item], folder=event_name, item_extent=ext, search_existing_items=False)
I have tried to this before with copy_item() as well, since I'm not moving content between portals and organizations. I just need to duplicate a webmap and then reset the extent. But not a single approach has worked for me:
#Copy the item, move and share the copy new_item = temp_item.copy_item(title="WMasdf_{}".format(event_name), folder = event_name) new_item.move(event_name) #because the folder parameter in the previous method doesn't seem to work either new_item.share(True) #Different formats of extents ex1 = {'xmin': -427248.44528862747, 'ymin': 4919558.2636672305, 'xmax': -399769.33362014365, 'ymax': 4936393.519147017, 'spatialReference': {'latestWkid':3857, 'wkid': 102100}} ex2 = '-427248.44528862747, 4919558.2636672305, -399769.33362014365, 4936393.519147017' ex3 = '110, 47, 111, 46' ex4 = [[110,47],[111,46]] #Differente ways I've been trying to set the extent, some on their own, then also some combined. Nothing worked new_item.extent = ex4 new_item.get_data()['initialState']['viewpoint']['targetGeometry'] = ex new_item.update(item_properties={'extent':ex1}) new_item.update(item_properties={'extent':ex2}) new_map = WebMap(copy_item) new_map.definition['initialState'] = ex
If someone could offer some insight on this, that would be amazing!
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.