Javascript 如何在独立于事件Vaadin的类中建立click侦听器
我对Vaadin和v-传单很陌生。我创建了一个组件,它获取一些geojson数据并将其放在地图上。我可以点击任意多边形/多重多边形,并以通知的形式返回一些信息。问题是,我需要获取这些信息并单击事件,让它影响到它们各自独立类中的其他4个独立组件。在过去的两天里,我一直在绞尽脑汁想这个问题,但似乎无法理解 以下是我的地图/点击事件:Javascript 如何在独立于事件Vaadin的类中建立click侦听器,javascript,java,leaflet,vaadin,vaadin7,Javascript,Java,Leaflet,Vaadin,Vaadin7,我对Vaadin和v-传单很陌生。我创建了一个组件,它获取一些geojson数据并将其放在地图上。我可以点击任意多边形/多重多边形,并以通知的形式返回一些信息。问题是,我需要获取这些信息并单击事件,让它影响到它们各自独立类中的其他4个独立组件。在过去的两天里,我一直在绞尽脑汁想这个问题,但似乎无法理解 以下是我的地图/点击事件: private LMap map; String filePath = this.getClass().getResource("/fccpeasgeo
private LMap map;
String filePath = this.getClass().getResource("/fccpeasgeo.json").getPath();
File file = new File(filePath);
//ArrayList<String> peaNames = new ArrayList<String>();
//@Override
public LMap createMap() {
map = new LMap();
FeatureJSON io = new FeatureJSON();
try {
long currentTimeMillis = System.currentTimeMillis();
// Look ma, no proxy needed, how cool is that!
FeatureCollection fc = io.readFeatureCollection(file);
Logger.getLogger(LeafletMap.class.getName()).severe("Download in " + (System.currentTimeMillis() - currentTimeMillis));
currentTimeMillis = System.currentTimeMillis();
FeatureIterator iterator = fc.features();
try {
while (iterator.hasNext()) {
Feature feature = iterator.next();
final String name = feature.getProperty("PEA_Name").getValue().toString();
final String population = feature.getProperty("POPs_2010").getValue().toString();
Geometry geometry = (Geometry) feature.getDefaultGeometryProperty().getValue();
// The geojson provided in example is rather complex (several megabytes)
// Use JTS to simplyfy. Note that it is rather easy to use
// different settings on different zoom levels, as well as decide
// to drop the feature form client altogether
geometry = DouglasPeuckerSimplifier.simplify(geometry, 0.2);
// In this example can be Polygon/Multipolygon
Collection<LeafletLayer> toLayers = JTSUtil.toLayers(geometry);
for (LeafletLayer l : toLayers) {
map.addComponent(l);
if (l instanceof LPolygon) {
LPolygon lPolygon = (LPolygon) l;
lPolygon.addClickListener(new LeafletClickListener() {
@Override
public void onClick(LeafletClickEvent event) {
Notification.show("PEA: " + name + " Population: " + population);
}
});
}
}
}
Logger.getLogger(LeafletMap.class.getName()).severe("Reducing and creating layers " + (System.currentTimeMillis() - currentTimeMillis));
} finally {
iterator.close();
}
} catch (MalformedURLException ex) {
Logger.getLogger(LeafletMap.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(LeafletMap.class.getName()).log(Level.SEVERE, null, ex);
}
map.zoomToContent();
//map.setCenter(40, -95.2);
//map.setZoomLevel(2.5);
LTileLayer tf = new LTileLayer();
tf.setUrl("http://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png");
tf.setSubDomains(new String[]{"a", "b", "c"});
tf.setActive(true);
map.addBaseLayer(tf, "ThunderForest Transport");
return map;
}
私有LMap映射;
字符串filePath=this.getClass().getResource(“/fccpeasgeo.json”).getPath();
文件文件=新文件(文件路径);
//ArrayList peaNames=新的ArrayList();
//@凌驾
公共LMap createMap(){
map=新的LMap();
FeatureJSON io=新FeatureJSON();
试一试{
long currentTimeMillis=System.currentTimeMillis();
//看,妈,不需要代理,这多酷啊!
FeatureCollection fc=io.readFeatureCollection(文件);
getLogger.getLogger(folicemap.class.getName()).severy(“下载到”+(System.currentTimeMillis()-currentTimeMillis));
currentTimeMillis=System.currentTimeMillis();
FeatureIterator迭代器=fc.features();
试一试{
while(iterator.hasNext()){
Feature=iterator.next();
最终字符串名称=feature.getProperty(“PEA_name”).getValue().toString();
最终字符串填充=feature.getProperty(“POPs_2010”).getValue().toString();
几何图形=(几何图形)特征.getDefaultGeometryProperty().getValue();
//示例中提供的geojson相当复杂(数兆字节)
//使用JTS来简化。注意,它相当容易使用
//不同缩放级别上的不同设置,以及
//完全删除功能窗体客户端的步骤
几何=DouglasPeuckerSimplifier.simplify(几何,0.2);
//在本例中,可以是多边形/多多边形
收集toLayers=JTSUtil.toLayers(几何);
适用于(l层:托拉耶斯){
map.addComponent(l);
if(LPolygon的l实例){
LPolygon LPolygon=(LPolygon)l;
lPolygon.addClickListener(新传单ClickListener(){
@凌驾
public void onClick(传单ClickEvent事件){
通知。显示(“PEA:+姓名+”人口:+人口);
}
});
}
}
}
getLogger.getLogger(folicemap.class.getName()).severy(“减少和创建层”+(System.currentTimeMillis()-currentTimeMillis));
}最后{
iterator.close();
}
}捕获(格式错误){
Logger.getLogger(loapemap.class.getName()).log(Level.SEVERE,null,ex);
}捕获(IOEX异常){
Logger.getLogger(loapemap.class.getName()).log(Level.SEVERE,null,ex);
}
map.zoomToContent();
//地图设置中心(40,-95.2);
//地图setZoomLevel(2.5);
LTileLayer tf=新的LTileLayer();
setUrl(“http://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png”);
设置子域(新字符串[]{“a”、“b”、“c”});
tf.setActive(真);
地图。addBaseLayer(tf,“ThunderForest运输”);
返回图;
}
下面是将接收事件的组件之一
public Chart mhzPerSqMile() {
Chart chart = new Chart();
run();
chart.setCaption("Total MHz Per Square Mile");
chart.getConfiguration().setTitle("");
chart.getConfiguration().getChart().setType(ChartType.PIE);
chart.getConfiguration().getChart().setAnimation(false);
chart.setWidth("100%");
chart.setHeight("90%");
DataSeries series = new DataSeries();
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName()!=null)
{
if (evt.getPropertyName().equals("abcTask"))
{
}
}
for (int i = 0; i < 5; i++) {
Operator operator = operators.get(i);
if (selectedPea != null) {
if (operator.getPeaName().toLowerCase() == selectedPea.toLowerCase()){
DataSeriesItem item = new DataSeriesItem(operator.getName(),
operator.getTotalMHzSqMile());
series.add(item);
item.setColor(DummyDataGenerator.chartColors[i]);
}
}
}
chart.getConfiguration().setSeries(series);
PlotOptionsPie opts = new PlotOptionsPie();
opts.setBorderWidth(0);
opts.setShadow(false);
opts.setAnimation(false);
chart.getConfiguration().setPlotOptions(opts);
Credits c = new Credits("");
chart.getConfiguration().setCredits(c);
return chart;
}
}
}
公共图表mhzPerSqMile(){
图表=新图表();
run();
图表.设置标题(“每平方英里总兆赫”);
chart.getConfiguration().setTitle(“”);
chart.getConfiguration().getChart().setType(ChartType.PIE);
chart.getConfiguration().getChart().setAnimation(false);
图表.设置宽度(“100%”);
图表.设置高度(“90%”);
DataSeries系列=新的DataSeries();
@凌驾
公共作废属性更改(属性更改事件evt){
if(evt.getPropertyName()!=null)
{
if(evt.getPropertyName().equals(“abcTask”))
{
}
}
对于(int i=0;i<5;i++){
运算符=运算符.get(i);
if(selectedPea!=null){
if(operator.getPeaName().toLowerCase()==selectedPea.toLowerCase()){
DataSeriesItem item=newdataseriesitem(operator.getName(),
运算符getTotalmHzSqFile());
系列。添加(项目);
item.setColor(DummyDataGenerator.ChartColor[i]);
}
}
}
chart.getConfiguration().setSeries(系列);
PlotOptionsPie opts=新的PlotOptionsPie();
选择宽度(0);
选项setShadow(假);
opts.setAnimation(假);
chart.getConfiguration().setPlotOptions(选项);
学分c=新学分(“”);
chart.getConfiguration().setCredits(c);
收益表;
}
}
}
任何建议都将不胜感激 我认为您只需使用任何特定名称(甚至
PropertyChangeSupport pcs = new PropertyChangeSupport(this);
//this firing code will probably go inside your click method that actually causes an event to occur
pcs.firePropertyChange("abcTask", oldValue, newValue);
@Override
public void propertyChange(PropertyChangeEvent evt)
{
if (evt.getPropertyName()!=null)
{
if (evt.getPropertyName().equals("abcTask"))
{
//perform task
}
}
}