How to printout the current map view?

584
23
03-01-2019 12:48 PM
CarlTownsend1
New Contributor III

I'm trying to add a map printout functionality to my javascript 3.27 based map, and I've got a problem with the print functions. In the print script code there is this:

......
        Printapp.map = new esri.Map
  ("map",
  {
          basemap: "topo",
         center: [-102, 54.75],
          zoom: 6,
         slider: false
       }
 );

.........
But I already have other script basically to loop through a map service and show the layers with the map type, coordinates and layers on startup. Then I click print, it defaults to this instead of what's on the screen. I can change the zoom level, basemap map type etc. and it will print out the changes instead of what's showing on the screen.

If I comment this bit out, it doesn't work. Basically I just want the print function to print out what's on the current map screen. How do I do this?

Thanks

0 Kudos
23 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Carl,

   You need to pass the Printapp.map a reference to your apps existing map object and not try and create a new one.

0 Kudos
CarlTownsend1
New Contributor III

So, instead of
Printapp.map = new esri.Map
  ("map",

it should be

Printapp.map = new esri.Map
  ("https://path/to/mapserver",

I'm not a programmer so please bear with me

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Carl,

  No not at all. You said:

But I already have other script basically to loop through a map service and show the layers with the map type, coordinates and layers on startup.

So that tells me that somewhere in that code you Already have a map object that you need to passing to the Printapp.map.

0 Kudos
CarlTownsend1
New Contributor III

Yes, it's in a different script, one that loops through the mapserver and loads all the layers - my question is how exactly do I get my print script to reference this looping script? I don't want it loading a new map underneath so I assumed if I commented it out it would automatically reference the looping script, but that hasn't worked. I have about 8,9 pther scripts and I need them to all play nicely with each other without breaking anything.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Carl,

So you have to open this print script from your main app script right? So when you do you pass in the map object from the main script or you set a window level variable for the map object and reference that window level var from the print script.

0 Kudos
BirajaNayak
Esri Contributor

Hi Carl,

Please remove base map " basemap: "topo"," and try.

Also here is the print layer samples from java script api 3.27 for your reference:

ArcGIS API for JavaScript Sandbox 

Thanks,

Biraja

0 Kudos
CarlTownsend1
New Contributor III

Hi Biraja, that approach doesn't work. Programmatically, I need this print script to reference the current map view that is provided by another script and I don't know how to do this with js. An example would help me out a lot. The example you've provided is just the print script in isolation which I've already gone through.

0 Kudos
CarlTownsend1
New Contributor III

Well this has me stumped. I have no idea how to get this to work. Tried everything I could think of. I guess PrintScreen will have to do.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Carl,

   Sorry you are having such a hard time with this. If you could provide your code then I can guide you on how to do this as it should not be complicated.

0 Kudos