Since the introduction of RadMap many customers have expressed a need to load shapefiles onto it. We are adding native support for shapefiles in the Q3 Release, along with vastly improving the performance of information, and dynamic layers. However, the beta is still a few weeks away, and I had a need for loading shapefiles this week, so I put this quick example together.
Shapefile parsing in this demo is handled by the reader available in the ESRI Contrib project. When we make the Q3 release you will be able to switch over to our reader by changing about two lines of code :)
The most basic code required to load a shapefile is shown below:
The first thing that needs to be done is parse the shapefile. After that I call an extension method, which converts the native ShapeFile shapes into MapShapes. The converter also stores the shape record’s attributes in the tag of the new map shape for easy retrieval later. The final step is to add all the shapes to an information layer. At this point the shapefile has been successfully loaded!
Unfortunately, nothing will be visible since we have not set any colors for strokes/background. We actually need to do a little more when adding the elements to the information layer:
Now our shapes will be visible, and have a yellow background with a black stroke.
I created a simple demo that displays a shapefile, each shape is yellow with a black stroke as discussed above. When you click a shape it will turn pink. Also, I am logging several mouse events to the event window on the right side. Along with the events, I output some information about the shape you are interacting with. For example, in the preloaded shapefile I output the name of the Texas county pulled out of the shapefile.
Give it a try:
Subscribe to be the first to get our expert-written articles and tutorials for developers!