Question

Looking to use MapPoint from VB

Asked by: klamerus

Okay, here's the story.

We want to create some PDF files of maps.  We're modeling what one of our customers does on their UNIX system.  They use GMT (a public domain package) to create PS files and then run through threw ghostscript to create PDF.

We've got Acrobat distiller installed on this system, so we have no problem turning PS into PDF.  What's left is creating maps.  Essentially we have 4 longitude/latitude points that we need a map of, and then we want to overlay data points on that.  We then want to generate a PS of the map.

MapPoint looks very strong, but it seems like we might have a couple of problems.  First, MapPoint looks interactive and not especially easy to automate.  It seems similar to Word or Excel, but it definitely looks like we have to go GUI.  If that's not true, we'd love to know.  Second, I don't see how to save the output to any sort of print file.  If we could automate printing to a PDF printer (or distiller printer) we'd have that handled too.

Does anyone have any sample code that uses MapPoint objects to create a map and generate a PS or PDF of it?  That's probably the starter.  We are going to do this on a server, so we'd prefer no GUI at all.

Thanks

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-09-07 at 16:30:28ID20731607
Tags

mappoint

Topic

Visual Basic Programming

Participating Experts
1
Points
500
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Distill PS into PDF using VB
    I have Acrobat 5. I want to distill PDF's programatically. I'm using the 'Watched Folder' option at present, but it's rather limited. I would rather control the process in VB. Can this be done...? Thanks, Sh
  2. Generate PDF with VBA code Acrobat Distiller
    Hello, I know this topic has been discussed, but I am a novice to this whole thing so I could not keep up with the treads. My issue is that I want to print Reports from Microsoft Access to a .PDF with a specific path and specific filename. I need code showing how to print t...
  3. Change PdfWriter VB proigramming to Acrobat 6 (Adobe …
    First of all, sorry my "english". Adobe Acrobat 6 does'nt support PDFWriter (not in the product, and also renamed Distiller to "PDF Printer"). The Adobe forum speak clear about PDFWriter is removed due it was "obsolete". I've an old VB6 program...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: EnladePosted on 2003-09-07 at 16:50:41ID: 9306540


I think mappoint comes with an API that you can use to automate what you are trying to do from your VB application.  I do have Mappoint, but I never really played with it much.  Maybe I'll install it and get you some code for manipulating it through the use of the API.  Or, if you want you could just do a web search for MapPoint API and you should be a few hits....let me see...yea there are a lot of sites that talk about control MapPoint through the API.  Like here is some VB code related to the MapPoint API:

http://www.anotherurl.com/mapping/API.htm

If you want I'll install Mappoint and see what Methods the API has that might be useful.  However, it might be just as easy for you to just add a Mappoint application object to a simple VB project and then just take a look at what methods and properties it makes available to you.

 

by: EnladePosted on 2003-09-07 at 16:59:25ID: 9306568


k...I had mappoint installed on one of my laptops and they list out all the VB methods in the help option of the Mappoint application.  I don't have any development software installed on that laptop so I can't toy with it unless I install it on my development machine.  Maybe I'll do that.  Still, check out all the avialable methods and properties that you have from VB.  It seems like you can pretty much automate the creation of maps without much trouble at all.  Mind you, GIS isn't my specialty, but it looks like there is enough methods exposed for you to solve your problem.

 

by: EnladePosted on 2003-09-07 at 17:13:13ID: 9306601


An easy way to do this is to automate both Distiller and Mappoint from VB.  Then I think you can just copy a selection (map) from Mappoint and paste it into Distiller before you use Distiller to generate the PDF file.  The alternitive is to figure out how to grab an image directly from the Mappoint API and insert it directly into Distiller (not using the clipboard).  Or a further alternitive is to use a temporary file to store the image between Mappoint and Distiller.  It all depends on what methods are visible through the Mappoint and Distiller API's.

By the way, Word and Excel are actually pretty easy to automate.  The only problem with all these Microsoft products is that they give you too much flexability and thus it is tough to learn all the avaliable methods and properties.  You gotta learn a mess of stuff just to do something simple.  Still, thats better then not having enough versitility.  I haven't looked into the Distiller API yet, but I bet if you do have any trouble it will be because Distiller has some limitations on its API.  For instance, Adobe Photoshop has some clear limitations on its API that make it a pain to try to do some fancy stuff with.  So, if you have trouble I bet it will be with Distiller and not Mappoint.  But again, I haven't toyed around with either yet (at least progammaticlly).

 

by: klamerusPosted on 2003-09-07 at 17:14:19ID: 9306604

Doh!!!  Who would have thought to look in help.  Anyway, it does look like it doesn't support output to an image or PS/PDF.  Perhaps via the Acrobat print devices it'll work out.  This will take some playing around.  What I'd like is to select a map that fits within some boundaries and then print to PS/PDF.

 

by: klamerusPosted on 2003-09-07 at 17:17:11ID: 9306612

Distiller simply turns PS into PDF, so I need to find out how to print to the PDF or PS (and if PS, then it's into the Distiller input directory".

 

by: klamerusPosted on 2003-09-07 at 17:18:21ID: 9306615

I wish I could figure out how to get an image out of MapPoint - that would simplify things, but the save and saveas output seem to only be other mappoint files (for the save) and html for saveas.  No images (go figure).

 

by: klamerusPosted on 2003-09-07 at 17:18:35ID: 9306616

I wonder if this would be do-able via Visio.

 

by: EnladePosted on 2003-09-07 at 17:26:55ID: 9306638


Doesn't Distiller allow you to create PDF files (from scratch)?  Or is that another Adobe product?  Oh, maybe that was Illistrator that does that.  Maybe you need to be using Illistrator and Mappoint.  I have Illistrator installed on something in my office...let me hunt it down and see what it can do as well....are you already commited to Distiller?

 

by: EnladePosted on 2003-09-07 at 17:29:09ID: 9306648


Actually, what you need is a PDF control so you can dump Illistrator and/or Distiller completely, but I think they are probably pretty expensive.  Adobe is pretty protective over its PDF format.  Still I could probably find you a PDF writter control somewhere (probably cost over $500 for a one user site license would be my guess).

 

by: klamerusPosted on 2003-09-07 at 17:42:09ID: 9306691

The costs are peanuts.  This is for an application at work.  Still, I can't print to PDF unless MapPoint supports that, and it doesn't.  It appears I need to print to the Adobe printer devices and specify the output file.  That's do-able.  Just a pain.  I was reading that MapPoint 2004 can generate images at output.  I think would probably go over okay (I can always stick them in a PDF if necessary).  It's supposed to be out in a week, so that would be good.  I wonder if I can get a beta somewhere?

 

by: EnladePosted on 2003-09-07 at 19:47:05ID: 9307004


No you don't have to print to PDF with MapPoint.  All you need is some way to get the image out of mappoint and over to another application that can print PDF files.  I would think that you would probably want to do this anyway since you can insert the map into a document and then add formated text, company logo, and anything else you want to add to the PDF document.  Though if all you want in your PDF file is a MAP image then I guess all the extras for using Illistrator or Distiller would be an overkill.

So, the way I see it you have two options.

1)  Buy an application that will allow you to create a PDF file.  That application will need some mechanism to insert an image (BMP, JPG,...) into it and to allow you to position text and other graphics (company logos) on the page (if you need that kind of stuff).  Again, I think Illistrator might do this (I'll have to find out) or maybe Distiller can do this also (another unknown for me, will have to investigate).

2)  Buy an ActiveX control or third party API that will allow you to generate PDF files directly from your VB application without having to load a seperate application object (for Illistrator or Distiller).  In this case you would still need to use MapPoint to get the map image (in a sense it is your GIS database though that is a stretch), but you would not need to load another application and automate the layout of a PDF image through that other application.

As I said in my previous message I think the majority of your work will be related to using Illistrator or Distiller (or a PDF API/ActiveX) and not so much a problem using MapPoint.  I'll look into this more, but I am working on something else right now.  I'll take a peak at it tomorrow.

 

by: klamerusPosted on 2003-09-08 at 03:44:55ID: 9308494

Thanks for the ideas.

We do need PDF in the end, althogh I think an image might be acceptable.  I need to have one of my guys solidify user requirements tomorrow.

Assuming that, I think we have to print via a print driver.  It's hard to see where in MapPoint we could hook in a component.  MapPoint itself doesn't appear to support the saving of images at this point (just maps).  The only non-map it seems to support creating is HTML files with embedded image (which I know we can "borrow").  It sounds like MapPoint 2004 supports output of images (B&W or Color) directly and that's out in < 2 weeks, so I'm hopeful it will give us this extra step.  I've put in my pre-order on it.

Anyway, any help on the selecting of a map region via a longitude/latitude bounding box would be helpful.

 

by: EnladePosted on 2003-09-08 at 11:00:54ID: 9310895


No, what I mean is that you simply use MapPoint to generate images (JPG, BMP, etc).  You instruct MapPoint to give you the image through the MapPoint VB Component and the MapPoint API.  You write your VB application to load the MapPoint application (in the backgroud so it will look semeless to the user of your VB App) and once loaded your VB application will set up MapPoint to get the Map image that you want.  Then your VB App gets that image from MapPoint.  Now, by "gets that image" there is some thought required on how you want to do that.  If the Mappoint API allows you to directly access the current Maps image (they call it ActiveMap) then you just grab it that way (very easy).  Otherwise, you will need to use the Copy method within the MapPoint ActiveMap to copy the image over to the clipboard and then from the clipboard into your VB application (or directly to whatever application you choose to generate the PDF--but lets ignore the PDF side of things for a secound).  The only other way I can think of getting the image over to your VB application is to have your VB application tell MapPoint to save the image into a file (JPG, BMP, whatever it can do).  Then you can have your VB application load it from that file.  The file will be a temporary file that is simply used to transfer images between Mappoint and your VB application (its just a long about way of doing the same thing that the Clipboard does--and you would only want to do this if you couldn't transfer the image in one of the other ways).

Now, that is the easy part.  You now have a bitmap image of whatever map you wanted (based on your coordinates) in your VB application.  So, now you add a function to your application that generates the PDF file.  That function can generate the file directly if you buy a PDF control for VB.  Or that function will generate the PDF by creating a new document within some third party application (Illistrator for instance--though we will need to check to see if Illistrator is controallable by your VB application).  In either case, you create a new PDF document and then fill that document with whatever you want in that document.  For instance, you might start your function by putting a company logo at the top of the page.  Then maybe the company address.  Then a little ways down you put in a paragraph explaining the map that is to follow on the page.  Then finally you drop the map on the page.  The page will be layed out just like a form is layed out.  So if you want the map (or text or whatever) placed on the page you simply tell it the X,Y location where you want it (making sure you stay within the dimensions of the page.

After you write all that to the page you then save the page to the PDF file.  This is to say that the page is created in memory and after you get everything on it you just use the Save method to save the page to your hard disk as a PDF file.

This is the overal approuch to your application.  I think it shouldn't be too difficult.  I might toy with it as well since it sounds like an interesting problem.  So, maybe I'll have a better grasp on the actual syntax in a day or so.  So, if you have any specific coding questions I'd be happy to consider them.  Take care.


Note: Remember that you really don't want MapPoint to create any files for you at all.  You just want to use it as a map database (super low grade GIS--single layer if you will).  You just want to tell it that your VB application wants some map image that you will then use to create the PDF file (using some other PDF writting application or by useing a VB PDF control).  The only time that you would care about the format that MapPoint would save a map image to some file would be if you couldn't get the Map image out of Mappoint directly (or by using the Clipboard).

 

by: EnladePosted on 2003-09-08 at 11:19:06ID: 9310972


Like for instance, here is some code that will grab a map image from MapPoint and put it into a picturebox within your VB application.  I didn't have time to read through the MapPoint methods and properties, so this is just an easy way that doesn't involve thinking much.  A better way would be to try to eliminate the clipboard alltogether and grab the image directly from MapPoint (if that is possible--won't know until I read through the MapPoint methods and properties).  Anyway, see how easy it is to get a map given a lat/long:

Option Explicit

Private Sub cmdMapIt_Click()
  Dim objApp As New MapPoint.Application
  Dim objLoc As MapPoint.Location
 
  objApp.Visible = False
  objApp.UserControl = False
 
  Set objLoc = objApp.ActiveMap.GetLocation(52, -0#)
   
  objApp.ActiveMap.CopyMap
   
  Set Pic1 = Clipboard.GetData
End Sub

To make this work just drop a command button (called cmdMapIt) and a picturebox (called Pic1) on a form.  Also, make sure you add the reference to the MapPoint application object in your VB references.

 

by: EnladePosted on 2003-09-08 at 11:37:57ID: 9311110


Actually, you also need to put in a objLoc.GoTo or it won't get the correct map.  Like here is the code that will get a map of Boston.


Private Sub cmdMapIt_Click()
  Dim objApp As New MapPoint.Application
  Dim objLoc As MapPoint.Location
 
  objApp.Visible = False
  objApp.UserControl = False
 
  'Or better yet here is Boston
  Set objLoc = objApp.ActiveMap.GetLocation(42.37, -71.06, 10)
  objLoc.GoTo
   
  objApp.ActiveMap.CopyMap
   
  Set Image1 = Clipboard.GetData

End Sub

 

by: EnladePosted on 2003-09-08 at 11:39:13ID: 9311119


Opps, I also switch the picturebox to an image control.  I wanted to use the stretch property of the image control.  Let me post the code online for you....hold up....

 

by: EnladePosted on 2003-09-08 at 11:41:29ID: 9311140


Ok, just download the project from here and give it a try:

http://www.enlade.com/MapPointTest.zip

 

by: EnladePosted on 2003-09-08 at 11:48:17ID: 9311189


So, without much thinking this code gets the map image from MapPoint (though I would recommend that you check to see if you can get the image directly without going through the clipboard).  So, now you just need to create a function that will dump the image over to Illistrator or Distiller so that you can generate the PDF file (or use a VB PDF control to do it directly).  In either case, if you just want the image in the PDF file you will probably be able to do it in just a few lines of code.  However, if you want to add text and logos and all sorts of other stuff you will need to put more effort into the creation of the PDF (still, I suspect it won't be too hard).

Then the only thing left is to get a little more control over Mappoint so that the exported map images don't have all those Locations on them (the little squares and junk).  You need to turn them all off and maybe add your own so that they show up on the graph with text or given a color that you index in the text that you write to the PDF document.

 

by: EnladePosted on 2003-09-08 at 19:59:57ID: 9314309


I made a few other little changes to the program and reposted it at:

http://www.enlade.com/MapPointTest.zip

You should notice that I'm using the stretch feature of the Image control.  This will give you a little blurry or scrunched up look to the graph (on the display) if the proportion between the display and the Mappoint image are different.  So, when you actually do this program you will probably want to grab the image using the SelectArea method (within SelectedArea under the ActiveMap).  This way you can grab an image that is the exact size that you want to draw in your PDF file.  I think if you do that then you can fix the Map size in the PDF file and just grab the size you need from Mappoint and that way you won't have any trouble with the proportions.  In any case, this little code is an example of how to get the map image out of MapPoint.  Now you just need to figure out how you want to get the images into the PDF file.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...