Follow

How can I change the color spectrum for my choropleth map in MapViewer via automation?

This article contains a sample script for creating a choropleth (hatch) map and changing the color spectrum used to display the map.

To run this script:

  1. Copy the script below, or click here to download the BAS file: ColorSpectrum.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\MapViewer 8\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.
     

*********

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ColorSpectrum.BAS
' Copyright (C) Golden Software Inc. 1992-2015
'
' This sample demonstrates how to change color spectrums
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub main
   Dim MapViewerApp, doc, LayersObj, HatchMap, cm As Object
   Dim path As String

   'Creates an instance of the MapViewer Application object
   ' and assigns it to the variable named "MapViewerApp"
   Set MapViewerApp = CreateObject("MapViewer.Application")

   'Makes the application main window visible
   MapViewerApp.Visible = True

   'Assigns the location of the samples folder to the variable "path"
   path = MapViewerApp.ApplicationFolder + "samples\"

   'Creates a map document object, and assigns it to the variable named "doc"
   Set doc = MapViewerApp.Documents.Add(DocType:=mvDocPlot)

   'Assigns the layer object to the variable named "LayersObj"
   Set LayersObj = doc.Layers

   'Creates a hatch map object and assigns it to the variable named "HatchMap"
   Set HatchMap = doc.CreateHatchMap(path + "co2010.gsb", path + "co2010.dat", "", "", 1, 7, 5)

   'Assigns the foreground color spectrum object to the variable named "cm"
   Set cm = HatchMap.FgColorSpectrum

   'Changes the color spectrum to one of the items stored in the list.
   'This automatically updates the map.
   cm.LoadFromList("Flame")

   'Creats a list of color node positions and color values.
   NodePosVariant = Array(0#, 0.25, 0.5, 0.75, 1#)
   NodeColorVariant = Array(mvColorRed, mvColorGreen, mvColorBlue, mvColorRed, mvColorBlack)
   Dim np(0 To 4) As Double, nc(0 To 4) As Long
   For i = 0 To 4
      np(i) = NodePosVariant(i)
      nc(i) = NodeColorVariant(i)
   Next

   'Updates the color spectrum by assigning the new color node positions and color values.
   'This automatically updates the map.
   cm.SetNodes np, nc

End Sub

 

Updated October 31, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.