SlideShare a Scribd company logo
Maps - Part III
MapContainer mc = new MapContainer(JS_API_KEY);
mapDemo.add(CENTER, mc);
Coord moscone = new Coord(37.7831, -122.401558);
mc.addMarker(null, moscone,
"Moscone Center",
"Moscone Center is the largest convention and "
+ "exhibition complex in San Francisco, California",
ee -> ToastBar.showMessage("You clicked it...",
FontImage.MATERIAL_MAP));
mc.zoom(moscone, (int)mc.getZoom());
Add Marker/Position Camera
A Better Way?
© Codename One 2017 all rights reserved
✦ Why not place a component on top of the Map?
✦ Historically that was technically impossible because of z-
ordering of peer components, this is no longer the case
✦ The only thing stopping us now is screen coordinates
✦ We can use GlassPane but I prefer working with
components so I’ll focus on that
public class MapLayout extends Layout implements MapListener {
private static final String COORD_KEY = "$coord";
private MapContainer map;
private Container actual;
public MapLayout(MapContainer map, Container actual) {
this.map = map;
this.actual = actual;
map.addMapListener(this);
}
public void addLayoutComponent(Object value, Component comp, Container c) {
comp.putClientProperty(COORD_KEY, (Coord)value);
}
public boolean isConstraintTracking() {
return true;
}
public Object getComponentConstraint(Component comp) {
return comp.getClientProperty(COORD_KEY);
}
Map Layout
public class MapLayout extends Layout implements MapListener {
private static final String COORD_KEY = "$coord";
private MapContainer map;
private Container actual;
public MapLayout(MapContainer map, Container actual) {
this.map = map;
this.actual = actual;
map.addMapListener(this);
}
public void addLayoutComponent(Object value, Component comp, Container c) {
comp.putClientProperty(COORD_KEY, (Coord)value);
}
public boolean isConstraintTracking() {
return true;
}
public Object getComponentConstraint(Component comp) {
return comp.getClientProperty(COORD_KEY);
}
Map Layout
public class MapLayout extends Layout implements MapListener {
private static final String COORD_KEY = "$coord";
private MapContainer map;
private Container actual;
public MapLayout(MapContainer map, Container actual) {
this.map = map;
this.actual = actual;
map.addMapListener(this);
}
public void addLayoutComponent(Object value, Component comp, Container c) {
comp.putClientProperty(COORD_KEY, (Coord)value);
}
public boolean isConstraintTracking() {
return true;
}
public Object getComponentConstraint(Component comp) {
return comp.getClientProperty(COORD_KEY);
}
Map Layout
public boolean isOverlapSupported() {
return true;
}
public void layoutContainer(Container parent) {
for(Component current : parent) {
Coord crd = (Coord)current.getClientProperty(COORD_KEY);
Point p = map.getScreenCoordinate(crd);
current.setSize(current.getPreferredSize());
current.setX(p.getX() - current.getWidth() / 2);
current.setY(p.getY() - current.getHeight());
}
}
public Dimension getPreferredSize(Container parent) {
return new Dimension(100, 100);
}
public void mapPositionUpdated(Component source, int zoom, Coord center) {
actual.setShouldCalcPreferredSize(true);
actual.revalidate();
}
}
Map Layout
public boolean isOverlapSupported() {
return true;
}
public void layoutContainer(Container parent) {
for(Component current : parent) {
Coord crd = (Coord)current.getClientProperty(COORD_KEY);
Point p = map.getScreenCoordinate(crd);
current.setSize(current.getPreferredSize());
current.setX(p.getX() - current.getWidth() / 2);
current.setY(p.getY() - current.getHeight());
}
}
public Dimension getPreferredSize(Container parent) {
return new Dimension(100, 100);
}
public void mapPositionUpdated(Component source, int zoom, Coord center) {
actual.setShouldCalcPreferredSize(true);
actual.revalidate();
}
}
Map Layout
public boolean isOverlapSupported() {
return true;
}
public void layoutContainer(Container parent) {
for(Component current : parent) {
Coord crd = (Coord)current.getClientProperty(COORD_KEY);
Point p = map.getScreenCoordinate(crd);
current.setSize(current.getPreferredSize());
current.setX(p.getX() - current.getWidth() / 2);
current.setY(p.getY() - current.getHeight());
}
}
public Dimension getPreferredSize(Container parent) {
return new Dimension(100, 100);
}
public void mapPositionUpdated(Component source, int zoom, Coord center) {
actual.setShouldCalcPreferredSize(true);
actual.revalidate();
}
}
Map Layout
public boolean isOverlapSupported() {
return true;
}
public void layoutContainer(Container parent) {
for(Component current : parent) {
Coord crd = (Coord)current.getClientProperty(COORD_KEY);
Point p = map.getScreenCoordinate(crd);
current.setSize(current.getPreferredSize());
current.setX(p.getX() - current.getWidth() / 2);
current.setY(p.getY() - current.getHeight());
}
}
public Dimension getPreferredSize(Container parent) {
return new Dimension(100, 100);
}
public void mapPositionUpdated(Component source, int zoom, Coord center) {
actual.setShouldCalcPreferredSize(true);
actual.revalidate();
}
}
Map Layout
public boolean isOverlapSupported() {
return true;
}
public void layoutContainer(Container parent) {
for(Component current : parent) {
Coord crd = (Coord)current.getClientProperty(COORD_KEY);
Point p = map.getScreenCoordinate(crd);
current.setSize(current.getPreferredSize());
current.setX(p.getX() - current.getWidth() / 2);
current.setY(p.getY() - current.getHeight());
}
}
public Dimension getPreferredSize(Container parent) {
return new Dimension(100, 100);
}
public void mapPositionUpdated(Component source, int zoom, Coord center) {
actual.setShouldCalcPreferredSize(true);
actual.revalidate();
}
}
Map Layout
public boolean isOverlapSupported() {
return true;
}
public void layoutContainer(Container parent) {
for(Component current : parent) {
Coord crd = (Coord)current.getClientProperty(COORD_KEY);
Point p = map.getScreenCoordinate(crd);
current.setSize(current.getPreferredSize());
current.setX(p.getX() - current.getWidth() / 2);
current.setY(p.getY() - current.getHeight());
}
}
public Dimension getPreferredSize(Container parent) {
return new Dimension(100, 100);
}
public void mapPositionUpdated(Component source, int zoom, Coord center) {
actual.setShouldCalcPreferredSize(true);
actual.revalidate();
}
}
Map Layout
public boolean isOverlapSupported() {
return true;
}
public void layoutContainer(Container parent) {
for(Component current : parent) {
Coord crd = (Coord)current.getClientProperty(COORD_KEY);
Point p = map.getScreenCoordinate(crd);
current.setSize(current.getPreferredSize());
current.setX(p.getX() - current.getWidth() / 2);
current.setY(p.getY() - current.getHeight());
}
}
public Dimension getPreferredSize(Container parent) {
return new Dimension(100, 100);
}
public void mapPositionUpdated(Component source, int zoom, Coord center) {
actual.setShouldCalcPreferredSize(true);
actual.revalidate();
}
}
Map Layout
Form mapDemo = new Form("Maps", new LayeredLayout());
if(BrowserComponent.isNativeBrowserSupported()) {
MapContainer mc = new MapContainer(JS_API_KEY);
mapDemo.add(mc);
Container markers = new Container();
markers.setLayout(new MapLayout(mc, markers));
mapDemo.add(markers);
Coord moscone = new Coord(37.7831, -122.401558);
Button mosconeButton = new Button("");
FontImage.setMaterialIcon(mosconeButton, FontImage.MATERIAL_PLACE);
markers.add(moscone, mosconeButton);
mc.zoom(moscone, 5);
} else {
// iOS Screenshot process...
mapDemo.add(new Label("Loading, please wait...."));
}
mapDemo.show();
Native Map Demo
Thank You

More Related Content

PDF
Maps - Part 3 - Transcript.pdf
PDF
Creating an Uber Clone - Part XXI - Transcript.pdf
PDF
Creating an Uber Clone - Part XXIII.pdf
PPTX
Introducing the Microsoft Virtual Earth Silverlight Map Control CTP
PDF
Mashup caravan android-talks
PDF
Creating an Uber Clone - Part XXIII - Transcript.pdf
PDF
Creating an Uber Clone - Part XIX.pdf
PPTX
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Maps - Part 3 - Transcript.pdf
Creating an Uber Clone - Part XXI - Transcript.pdf
Creating an Uber Clone - Part XXIII.pdf
Introducing the Microsoft Virtual Earth Silverlight Map Control CTP
Mashup caravan android-talks
Creating an Uber Clone - Part XXIII - Transcript.pdf
Creating an Uber Clone - Part XIX.pdf
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC

More from ShaiAlmog1 (20)

PDF
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
PDF
create-netflix-clone-06-client-ui.pdf
PDF
create-netflix-clone-01-introduction_transcript.pdf
PDF
create-netflix-clone-02-server_transcript.pdf
PDF
create-netflix-clone-04-server-continued_transcript.pdf
PDF
create-netflix-clone-01-introduction.pdf
PDF
create-netflix-clone-06-client-ui_transcript.pdf
PDF
create-netflix-clone-03-server.pdf
PDF
create-netflix-clone-04-server-continued.pdf
PDF
create-netflix-clone-05-client-model_transcript.pdf
PDF
create-netflix-clone-03-server_transcript.pdf
PDF
create-netflix-clone-02-server.pdf
PDF
create-netflix-clone-05-client-model.pdf
PDF
Creating a Whatsapp Clone - Part II.pdf
PDF
Creating a Whatsapp Clone - Part IX - Transcript.pdf
PDF
Creating a Whatsapp Clone - Part II - Transcript.pdf
PDF
Creating a Whatsapp Clone - Part V - Transcript.pdf
PDF
Creating a Whatsapp Clone - Part IV - Transcript.pdf
PDF
Creating a Whatsapp Clone - Part IV.pdf
PDF
Creating a Whatsapp Clone - Part I - Transcript.pdf
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-01-introduction.pdf
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-03-server.pdf
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-02-server.pdf
create-netflix-clone-05-client-model.pdf
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Getting Started with Data Integration: FME Form 101
PDF
August Patch Tuesday
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
The various Industrial Revolutions .pptx
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Architecture types and enterprise applications.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
NewMind AI Weekly Chronicles – August ’25 Week III
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Getting Started with Data Integration: FME Form 101
August Patch Tuesday
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
O2C Customer Invoices to Receipt V15A.pptx
Assigned Numbers - 2025 - Bluetooth® Document
Hindi spoken digit analysis for native and non-native speakers
1 - Historical Antecedents, Social Consideration.pdf
A comparative study of natural language inference in Swahili using monolingua...
NewMind AI Weekly Chronicles - August'25-Week II
Module 1.ppt Iot fundamentals and Architecture
The various Industrial Revolutions .pptx
1. Introduction to Computer Programming.pptx
Tartificialntelligence_presentation.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Architecture types and enterprise applications.pdf
Group 1 Presentation -Planning and Decision Making .pptx

Maps - Part 3.pdf

  • 2. MapContainer mc = new MapContainer(JS_API_KEY); mapDemo.add(CENTER, mc); Coord moscone = new Coord(37.7831, -122.401558); mc.addMarker(null, moscone, "Moscone Center", "Moscone Center is the largest convention and " + "exhibition complex in San Francisco, California", ee -> ToastBar.showMessage("You clicked it...", FontImage.MATERIAL_MAP)); mc.zoom(moscone, (int)mc.getZoom()); Add Marker/Position Camera
  • 3. A Better Way? © Codename One 2017 all rights reserved ✦ Why not place a component on top of the Map? ✦ Historically that was technically impossible because of z- ordering of peer components, this is no longer the case ✦ The only thing stopping us now is screen coordinates ✦ We can use GlassPane but I prefer working with components so I’ll focus on that
  • 4. public class MapLayout extends Layout implements MapListener { private static final String COORD_KEY = "$coord"; private MapContainer map; private Container actual; public MapLayout(MapContainer map, Container actual) { this.map = map; this.actual = actual; map.addMapListener(this); } public void addLayoutComponent(Object value, Component comp, Container c) { comp.putClientProperty(COORD_KEY, (Coord)value); } public boolean isConstraintTracking() { return true; } public Object getComponentConstraint(Component comp) { return comp.getClientProperty(COORD_KEY); } Map Layout
  • 5. public class MapLayout extends Layout implements MapListener { private static final String COORD_KEY = "$coord"; private MapContainer map; private Container actual; public MapLayout(MapContainer map, Container actual) { this.map = map; this.actual = actual; map.addMapListener(this); } public void addLayoutComponent(Object value, Component comp, Container c) { comp.putClientProperty(COORD_KEY, (Coord)value); } public boolean isConstraintTracking() { return true; } public Object getComponentConstraint(Component comp) { return comp.getClientProperty(COORD_KEY); } Map Layout
  • 6. public class MapLayout extends Layout implements MapListener { private static final String COORD_KEY = "$coord"; private MapContainer map; private Container actual; public MapLayout(MapContainer map, Container actual) { this.map = map; this.actual = actual; map.addMapListener(this); } public void addLayoutComponent(Object value, Component comp, Container c) { comp.putClientProperty(COORD_KEY, (Coord)value); } public boolean isConstraintTracking() { return true; } public Object getComponentConstraint(Component comp) { return comp.getClientProperty(COORD_KEY); } Map Layout
  • 7. public boolean isOverlapSupported() { return true; } public void layoutContainer(Container parent) { for(Component current : parent) { Coord crd = (Coord)current.getClientProperty(COORD_KEY); Point p = map.getScreenCoordinate(crd); current.setSize(current.getPreferredSize()); current.setX(p.getX() - current.getWidth() / 2); current.setY(p.getY() - current.getHeight()); } } public Dimension getPreferredSize(Container parent) { return new Dimension(100, 100); } public void mapPositionUpdated(Component source, int zoom, Coord center) { actual.setShouldCalcPreferredSize(true); actual.revalidate(); } } Map Layout
  • 8. public boolean isOverlapSupported() { return true; } public void layoutContainer(Container parent) { for(Component current : parent) { Coord crd = (Coord)current.getClientProperty(COORD_KEY); Point p = map.getScreenCoordinate(crd); current.setSize(current.getPreferredSize()); current.setX(p.getX() - current.getWidth() / 2); current.setY(p.getY() - current.getHeight()); } } public Dimension getPreferredSize(Container parent) { return new Dimension(100, 100); } public void mapPositionUpdated(Component source, int zoom, Coord center) { actual.setShouldCalcPreferredSize(true); actual.revalidate(); } } Map Layout
  • 9. public boolean isOverlapSupported() { return true; } public void layoutContainer(Container parent) { for(Component current : parent) { Coord crd = (Coord)current.getClientProperty(COORD_KEY); Point p = map.getScreenCoordinate(crd); current.setSize(current.getPreferredSize()); current.setX(p.getX() - current.getWidth() / 2); current.setY(p.getY() - current.getHeight()); } } public Dimension getPreferredSize(Container parent) { return new Dimension(100, 100); } public void mapPositionUpdated(Component source, int zoom, Coord center) { actual.setShouldCalcPreferredSize(true); actual.revalidate(); } } Map Layout
  • 10. public boolean isOverlapSupported() { return true; } public void layoutContainer(Container parent) { for(Component current : parent) { Coord crd = (Coord)current.getClientProperty(COORD_KEY); Point p = map.getScreenCoordinate(crd); current.setSize(current.getPreferredSize()); current.setX(p.getX() - current.getWidth() / 2); current.setY(p.getY() - current.getHeight()); } } public Dimension getPreferredSize(Container parent) { return new Dimension(100, 100); } public void mapPositionUpdated(Component source, int zoom, Coord center) { actual.setShouldCalcPreferredSize(true); actual.revalidate(); } } Map Layout
  • 11. public boolean isOverlapSupported() { return true; } public void layoutContainer(Container parent) { for(Component current : parent) { Coord crd = (Coord)current.getClientProperty(COORD_KEY); Point p = map.getScreenCoordinate(crd); current.setSize(current.getPreferredSize()); current.setX(p.getX() - current.getWidth() / 2); current.setY(p.getY() - current.getHeight()); } } public Dimension getPreferredSize(Container parent) { return new Dimension(100, 100); } public void mapPositionUpdated(Component source, int zoom, Coord center) { actual.setShouldCalcPreferredSize(true); actual.revalidate(); } } Map Layout
  • 12. public boolean isOverlapSupported() { return true; } public void layoutContainer(Container parent) { for(Component current : parent) { Coord crd = (Coord)current.getClientProperty(COORD_KEY); Point p = map.getScreenCoordinate(crd); current.setSize(current.getPreferredSize()); current.setX(p.getX() - current.getWidth() / 2); current.setY(p.getY() - current.getHeight()); } } public Dimension getPreferredSize(Container parent) { return new Dimension(100, 100); } public void mapPositionUpdated(Component source, int zoom, Coord center) { actual.setShouldCalcPreferredSize(true); actual.revalidate(); } } Map Layout
  • 13. public boolean isOverlapSupported() { return true; } public void layoutContainer(Container parent) { for(Component current : parent) { Coord crd = (Coord)current.getClientProperty(COORD_KEY); Point p = map.getScreenCoordinate(crd); current.setSize(current.getPreferredSize()); current.setX(p.getX() - current.getWidth() / 2); current.setY(p.getY() - current.getHeight()); } } public Dimension getPreferredSize(Container parent) { return new Dimension(100, 100); } public void mapPositionUpdated(Component source, int zoom, Coord center) { actual.setShouldCalcPreferredSize(true); actual.revalidate(); } } Map Layout
  • 14. Form mapDemo = new Form("Maps", new LayeredLayout()); if(BrowserComponent.isNativeBrowserSupported()) { MapContainer mc = new MapContainer(JS_API_KEY); mapDemo.add(mc); Container markers = new Container(); markers.setLayout(new MapLayout(mc, markers)); mapDemo.add(markers); Coord moscone = new Coord(37.7831, -122.401558); Button mosconeButton = new Button(""); FontImage.setMaterialIcon(mosconeButton, FontImage.MATERIAL_PLACE); markers.add(moscone, mosconeButton); mc.zoom(moscone, 5); } else { // iOS Screenshot process... mapDemo.add(new Label("Loading, please wait....")); } mapDemo.show(); Native Map Demo