38 |
|
|
39 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
40 |
import org.geotools.data.DefaultQuery; |
import org.geotools.data.DefaultQuery; |
41 |
|
import org.geotools.data.FeatureSource; |
42 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
43 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
44 |
import org.geotools.styling.Style; |
import org.geotools.styling.Style; |
45 |
import org.geotools.styling.TextSymbolizer; |
import org.geotools.styling.TextSymbolizer; |
46 |
|
import org.opengis.feature.Feature; |
47 |
import org.opengis.feature.simple.SimpleFeature; |
import org.opengis.feature.simple.SimpleFeature; |
48 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
49 |
import org.opengis.feature.type.AttributeDescriptor; |
import org.opengis.feature.type.AttributeDescriptor; |
50 |
|
import org.opengis.feature.type.FeatureType; |
51 |
import org.opengis.filter.Filter; |
import org.opengis.filter.Filter; |
52 |
import org.opengis.filter.expression.Expression; |
import org.opengis.filter.expression.Expression; |
53 |
import org.opengis.filter.expression.PropertyName; |
import org.opengis.filter.expression.PropertyName; |
84 |
this.mapPane = mapPane; |
this.mapPane = mapPane; |
85 |
} |
} |
86 |
|
|
87 |
|
/** |
88 |
|
* The Attribute that provides the labels for this text symbolizer. |
89 |
|
*/ |
90 |
private AttributeDescriptor getLabelAttribute(final TextSymbolizer ts, |
private AttributeDescriptor getLabelAttribute(final TextSymbolizer ts, |
91 |
final SimpleFeatureType schema) { |
final SimpleFeatureType schema) { |
92 |
if (ts == null) { |
if (ts == null) { |
93 |
// This layer has no labels |
// This layer has no labels |
94 |
return null; |
return null; |
95 |
} |
} |
96 |
|
|
97 |
final Expression labelExp = ts.getLabel(); |
final Expression labelExp = ts.getLabel(); |
98 |
if (labelExp instanceof PropertyName) { |
if (labelExp instanceof PropertyName) { |
99 |
final PropertyName pn = (PropertyName) labelExp; |
final PropertyName pn = (PropertyName) labelExp; |
100 |
final String propertyName = pn.getPropertyName(); |
final String propertyName = pn.getPropertyName(); |
101 |
return schema.getAttributeType(propertyName); |
return schema.getDescriptor(propertyName); |
102 |
} else { |
} else { |
103 |
// When does this happen |
// When does this happen |
104 |
|
throw new RuntimeException("labelExp "+labelExp+" IS NOT instanceof PropertyName!"); |
105 |
} |
} |
106 |
|
|
|
return null; |
|
107 |
} |
} |
108 |
|
|
109 |
public List<SearchResult> search(final String string) { |
public List<SearchResult> search(final String string) { |
128 |
continue; |
continue; |
129 |
} |
} |
130 |
|
|
131 |
final String typeName = ml.getFeatureSource().getSchema() |
// 26 CAST! |
132 |
.getTypeName(); |
final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = (FeatureSource<SimpleFeatureType, SimpleFeature>) ml.getFeatureSource(); |
133 |
|
|
134 |
|
final String typeName = featureSource.getSchema() |
135 |
|
.getName().getLocalPart(); |
136 |
|
|
137 |
// Expression labelExp = ts.getLabel(); |
// Expression labelExp = ts.getLabel(); |
138 |
// ff.like(labelExp, "*"+searchMe+"*"); |
// ff.like(labelExp, "*"+searchMe+"*"); |
141 |
// new DefaultQuery(typeName, ff.like(labelExp, |
// new DefaultQuery(typeName, ff.like(labelExp, |
142 |
// "*"+searchMe+"*"), properties)); |
// "*"+searchMe+"*"), properties)); |
143 |
|
|
144 |
final FeatureCollection features = ml.getFeatureSource().getFeatures( |
final FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource.getFeatures( |
145 |
new DefaultQuery(typeName, Filter.INCLUDE)); |
new DefaultQuery(typeName, Filter.INCLUDE)); |
146 |
|
|
147 |
// new MemoryDataStore().getFeatureSource(typeName) |
// new MemoryDataStore().getFeatureSource(typeName) |
160 |
if (ts == null) |
if (ts == null) |
161 |
continue; |
continue; |
162 |
|
|
163 |
final AttributeDescriptor labelAttribute = getLabelAttribute(ts, ml |
final AttributeDescriptor labelAttribute = getLabelAttribute(ts, featureSource.getSchema()); |
|
.getFeatureSource().getSchema()); |
|
164 |
|
|
165 |
if (labelAttribute == null) { |
if (labelAttribute == null) { |
166 |
continue; |
continue; |