spacer1
spacer2 1_1 1_2
2_1
 Subscribe
 The MP2K Update!
 
 
 
 Magazine
Front Cover
What's New
Articles
News
Sample Data
Gallery
Advertise
About
 Features
MapPoint 2013
Press Releases
MapPoint Forums
Companies
Link to MP2Kmag
Wish List
MapPoint Trial
Authors
 Earlier Content
Past News Items
Past What's New Announcements
 Sponsors
 Order

MapPoint 2013

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
SVG Tutorials
MapPoint

Map Visitors

  MAPPOINT Q & A  

Top | Post New Question | Read All | MP2K Asks Microsoft

635 Will Vereen - March 27, 2002

I have territories based on Counties. I have also imported sales by county. How can I get the sales to display by territory and to react dynamically to changes in county territory assignments?

Answer:

The only way to manipulate territories is to import them; there is no link or other programmatic manipulation.

So you have to do something like the following (this is untested as written and doesn't include variable declarations and error handling):


    arrFields(1, 1) = "StateCode": arrFields(1, 2) = geoFieldRegion1
    arrFields(2, 1) = "CountyName": arrFields(2, 2) = geoFieldRegion2
    arrFields(3, 1) = "TerritoryAssignment": arrFields(3, 2) = geoFieldData
    arrFields(4, 1) = "TerritorySales": arrFields(4, 2) = geoFieldData
    
    Set cn = New ADODB.Connection
    cn.ConnectionTimeout = 120
    cn.CommandTimeout = 120
    cn.Open "...insert database connection string..."
    
    Set objMap = objMapPoint.ActiveMap
    'Clear the map.
    For Each objDataSet In objMap.DataSets
        If Not objDataSet.Name = "My Pushpins" Then
            objDataSet.Delete
        End If
    Next
    
    With objMap.DataSets
        gstrUDLLocation = "...location of UDL pointer to database..."
        ' vwMapSalesTerritories is a SQL Server view that contains fields
        ' that defines the territories.
        sConnection = gstrUDLLocation & "!vwMapSalesTerritories"
        Set objDS = .ImportTerritories(sConnection, , _
                    geoCountryUnitedStates, geoDelimiterTab, _
                    geoImportFirstRowNotHeadings)
    End With
    Set objDS = Nothing
    
    With objMap.DataSets
        ' vwMapSalesByTerritory is a SQL Server view that contains sales
        ' data by territory returning the arrFields array.
        sConnection = gstrUDLLocation & "!vwMapSalesByTerritory"
        Set objDS = .ImportData(sConnection, _
                    arrFields, _
                    geoCountryUnitedStates, _
                    geoDelimiterDefault)
    End With
    
    objDS.DisplayDataMap DataMapType:=geoDataMapTypeShadedArea, _
                        DataField:=objDS.Fields("TerritoryAssignment"), _
                        ShowDataBy:=geoShowByRegion2, _
                        CombineDataBy:=geoCombineByNone, _
                        DataRangeType:=geoRangeTypeUniqueValues, _
                        DataRangeOrder:=geoRangeOrderDefault, ColorScheme:=3
    
    objDS.ZoomTo
    objDS.DataMap.LegendTitle = txtMapTitle.Text
    objMap.MapStyle = geoMapStyleData

After this is executed, the territories are drawn and the sales data is shown on a tooltip that is displayed when you hover over a county.

- Walt Cygan

Post New Answer / Follow-up


Google
 
MP2Kmag Internet


 Recent Discussion
 Resources


Want Your Site To Appear Here?

   © 1999-2012 MP2K. Questions and comments to: website@mp2kmag.com
  Microsoft and MapPoint 2002/2004/2006/2009/2010/2011/2013 are either trademarks or registered trademarks of Microsoft.