Hi,
I hope this is the appropriate place to ask this question -- not sure if it is a geotools issue or if that even matters.
I got the map viewer (IViewPart implementation) working well, and I was able to get styles to update dynamically, so I think I more or less have the basic patterns worked out. But I'm having trouble figuring out the recipe for my key use case:
"Change feature attributes dynamically and have those changes reflected on the map."
I have the first part, in that I figured out how that the ShapeFileDataStore was read only. So I created a MemoryDataStore for that. I gather that that is slow, but I couldn't see a better way of making the shape file modifiable. Now, I can get the attributes to change to new values. As I mentioned, I can also get a map to update regularly. But I can't get the values to hook up with the map.
First, I load in the shape file like so:
URL resourceId = new URL(
ICatalog localCatalog = CatalogPlugin.getDefault().getLocalCatalog(); List<IService> services = CatalogPlugin.getDefault().getServiceFactory().createService(resourceId); for (IService service : services) { localCatalog.add(service); for (IGeoResource resource : service.resources(null)) {
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = resource .resolve(FeatureSource.class, null);
Then, I copy the feature into the memory store (I think..)
FeatureCollection<SimpleFeatureType, SimpleFeature> shapeFeatures = featureSource.getFeatures(); features = DataUtilities.collection(shapeFeatures);
MemoryDataStore mds = new MemoryDataStore(features); mdsStore = mds.getFeatureSource(featureSource.getName());
Now, I can add the original resource into the map..and as I say form that it displays properly, I can modify styles, etc..
Layer createLayer = getMap().getLayerFactory().createLayer(resource); getMap().getLayersInternal().add(createLayer); createLayer.getStyleBlackboard().put(SLDContent.ID, style);
Here's where I'm stuck, but perhaps there is a better approach altogether.. I can't actually figure out how to get an IGeoResource for the MapDataStore to add it into the set of layers. I mean, this has to be straightforward but..?
thanks for any hints,
Miles
|