This project is read-only.

adding points to a new layer

Mar 17, 2013 at 11:08 AM
Is there a correct way to create a new layer and add points to it? I have done what I think is correct, but after adding the points I can no longer change the webmap provider.

This is what I have done:

void setSiteMarkers()
        {
        ProjectionInfo wgs = KnownCoordinateSystems.Geographic.World.WGS1984;
        this.map1.Projection = wgs;
        this.map1.Projection.IsLatLon = true;

        // The FeatureSet starts with no data; be sure to set it to the point featuretype
        this.dbMarkers = new FeatureSet(FeatureType.Point);
        this.dbMarkers.Projection = wgs;
        this.dbMarkers.Projection.IsLatLon = true;

        // The MapPointLayer controls the drawing of the marker features
        this.dbMarkerLayer = new MapPointLayer(this.dbMarkers);
        this.dbMarkerLayer.Projection = wgs;

        // The Symbolizer controls what the points look like
        this.dbMarkerLayer.Symbolizer = new PointSymbolizer(Color.Blue, DotSpatial.Symbology.PointShape.Star, 15);

        // A drawing layer draws on top of data layers, but is still georeferenced.
        this.map1.MapFrame.DrawingLayers.Add(this.dbMarkerLayer);

        //add feature set to map
        this.map1.Layers.Add(this.dbMarkerLayer);
        this.dbMarkerLayer.LegendText = "Points From Sqlite";

        // add points from database

        SQLiteDB cnData = new SQLiteDB("points");

        getDBtree( cnData, "root"); 


        //this.map1.MapFrame.Invalidate();
        }
In the getDBtree function it extracts some lat/long points and adds to the map.

Coordinate coord = GeographicToWebMercator(equipLat, equipLng);
            DotSpatial.Topology.Point point = new DotSpatial.Topology.Point(coord);
            IFeature feature = this.dbMarkers.AddFeature(point);
This appears to work and I can select and deselect the layer. The only problem is that after doing this I can no longer change the webmap provider.
Mar 17, 2013 at 12:38 PM
OK, apparently the issue was setting the map projection after it was loaded from the webprovider. Here is what works:

ProjectionInfo wgs = this.map1.Projection;
        // The FeatureSet starts with no data; be sure to set it to the point featuretype
        this.dbMarkers = new FeatureSet(FeatureType.Point);
        this.dbMarkers.Projection = wgs;

        // The MapPointLayer controls the drawing of the marker features
        this.dbMarkerLayer = new MapPointLayer(this.dbMarkers);
        this.dbMarkerLayer.Projection = wgs;

        // The Symbolizer controls what the points look like
        this.dbMarkerLayer.Symbolizer = new PointSymbolizer(Color.Blue, DotSpatial.Symbology.PointShape.Star, 15);

        // A drawing layer draws on top of data layers, but is still georeferenced.
        this.map1.MapFrame.DrawingLayers.Add(this.dbMarkerLayer);

        //add feature set to map
        this.map1.Layers.Add(this.dbMarkerLayer);
        this.dbMarkerLayer.LegendText = "Points From Sqlite";
Now I can plot as many points as I wish. I can select or deselect the layer and I can change the map provider.