Book Image

Primefaces Cookbook Second Edition

Book Image

Primefaces Cookbook Second Edition

Overview of this book

Table of Contents (20 chapters)
PrimeFaces Cookbook Second Edition
Credits
Foreword
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Adding, selecting, and dragging markers in maps


It is possible to add markers onto the map via a data model and then select or drag it by interacting with the map.

How to do it…

The marker should be an instance of org.primefaces.model.map.Marker. Markers can be easily constructed by providing an instance of org.primefaces.model.map.LatLng to define their position. The latitude and longitude values could be provided to the LatLng class as constructor parameters. Markers will be added to the data model via the addOverlay method. This is shown in the following code:

MapModel markerModel = new DefaultMapModel();
markerModel.addOverlay(new Marker(new LatLng(41.073399,
  29.051971), "Bosphorus"));
markerModel.addOverlay(new Marker(new LatLng(41.118418,
  29.134026), "Bosphorus"));

The attributes of org.primefaces.model.map.Marker are listed in the following table:

Property

Default

Type

Description

title

null

String

This is the text to display on rollover

latlng

null

LatLng

This is the location...