Adding Points
You can add points to an existing GeoJSON layer using the "AddPoint()" function. The parameters are X,Y values for the coordinate. After the points have been added, you can add attributes and then values for the attributes based in indexes to the features in the layer. Below is a code sample from the Humboldt County example.
Note that we also use set the projector for the layer to "TheProjector" we created in the last tutorial. This allows us to use geographic coordinates (lat/lon) to add the points and the layer will convert them to UTM.
var Layer_Cities=new CMLayerDataset(); Layer_Cities.SetData(null,CMDataset.GEOJSON); // has to be before we set the projector Layer_Cities.SetProjector(TheProjector); // project the data to the same spatial reference as the map Layer_Cities.SetSetting("Name","Cities"); Layer_Cities.SetSettingAttribute("Layer","InfoText","name");; // add the coordinates var TheDataset=Layer_Cities.GetDataset(); TheDataset.AddPoint(-121.941542,37.349217); TheDataset.AddPoint(-123.243619,38.514080); // add the attributes, for GeoJSON, this must be done after the points are added TheDataset.AddAttributeHeading("name","default"); TheDataset.SetAttributeCell("name",0,"Mission Santa Clara"); TheDataset.SetAttributeCell("name",1,"Fort Ross"); Layer_Cities.SetFeatureIconImage(0,"Images/ChurchIcon.png",-17,-17); Layer_Cities.SetFeatureIconImage(1,"Images/Historic.png",-17,-17); TheMainContainer.AddLayer(Layer_Cities);
The attributes contain the content that will appear in the title for the info box. Note that you can also use the "SetFeatureIconImage()" function to change the icon for each point.