java - How to Execute Custom Javascript Vaadin -
i building vaadin app , need use leafletjs map visualization. have created necessary javascript functions , java classes (or @ least think did), when run program on server, not show up. ideas on why happening?
here javascript code:
window.com_vaadin_demo_dashboard_component_mymap = function() { var peaelement = this.getelement(); var mapboxaccesstoken = pk.eyj1ijoibmlja2vtbw9ucyisimeioijjawy2cm45ag0wb285c3vrdgi1yxnzc2y5in0.adsztbun58fcupsr-vvh4q; var map = l.map('map').setview([37.8, -96], 4); var geojson; l.tilelayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=' + mapboxaccesstoken, { id: 'mapbox.light'}).addto(map); function getcolor(d) { return d > 1000 ? '#800026' : d > 500 ? '#bd0026' : d > 200 ? '#e31a1c' : d > 100 ? '#fc4e2a' : d > 50 ? '#fd8d3c' : d > 20 ? '#feb24c' : d > 10 ? '#fed976' : '#ffeda0'; } function style(feature) { return { fillcolor: getcolor(feature.properties.density), weight: 2, opacity: 1, color: 'white', dasharray: '3', fillopacity: 0.7 }; } function highlightfeature(e) { var layer = e.target; layer.setstyle({ weight: 5, color: '#666', dasharray: '', fillopacity: 0.7 }); if (!l.browser.ie && !l.browser.opera) { layer.bringtofront(); } } function resethighlight(e) { geojson.resetstyle(e.target); } function zoomtofeature(e) { map.fitbounds(e.target.getbounds()); } function oneachfeature(feature, layer) { layer.on({ mouseover: highlightfeature, mouseout: resethighlight, click: zoomtofeature }); } geojson = l.geojson(peas, { style: style, oneachfeature: oneachfeature }).addto(map); } here java classes extending abstractjavascriptcomponent:
package com.vaadin.demo.dashboard.component; import com.vaadin.annotations.*; import com.vaadin.ui.abstractjavascriptcomponent; @javascript({"http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.js", "pea_map.js"}) @stylesheet({"http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.css"}) public class peamap extends abstractjavascriptcomponent { public void setid(final integer id) { getstate().setid(id); } public void setname(final string name) { getstate().setname(name); } public void setpopulation(final integer population) { getstate().setpopulation(population); } @override public mymapstate getstate() { return (mymapstate) super.getstate(); } } here java class keeps track of state:
package com.vaadin.demo.dashboard.component; import com.vaadin.shared.ui.javascriptcomponentstate; public class mymapstate extends javascriptcomponentstate { private integer id; private string name; private integer population; public integer getid() { return id; } public void setid(integer id) { this.id = id; } public string getname() { return name; } public void setname(string name) { this.name = name; } public integer getpopulation() { return population; } public void setpopulation(integer population) { this.population = population; } } and here component gets tied to:
package com.vaadin.demo.dashboard.component; import com.vaadin.demo.dashboard.component.peamap; import com.vaadin.ui.*; import com.vaadin.server.page; public class mymapui extends customcomponent { final mymap mymap = new mymap(); final verticallayout layout = new verticallayout(); public void mymap(){ page.getcurrent().getjavascript().execute("com_vaadin_demo_dashboard_component_mymap()"); //now build layout. layout.setspacing(true); layout.addcomponent(mymap); } } it supposed added panel have on 1 of pages of project, not show up.
Comments
Post a Comment