├── .gitattributes ├── .gitignore ├── README.md └── libraries └── Leaflet.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | */config/development 2 | */logs/log-*.php 3 | */logs/!index.html 4 | */cache/* 5 | */cache/!index.html 6 | */cache/!.htaccess 7 | 8 | # ========================= 9 | # Operating System Files 10 | # ========================= 11 | 12 | # OSX 13 | # ========================= 14 | 15 | .DS_Store 16 | .AppleDouble 17 | .LSOverride 18 | 19 | # Icon must end with two \r 20 | Icon 21 | 22 | # Thumbnails 23 | ._* 24 | 25 | # Files that might appear on external disk 26 | .Spotlight-V100 27 | .Trashes 28 | 29 | # Directories potentially created on remote AFP share 30 | .AppleDB 31 | .AppleDesktop 32 | Network Trash Folder 33 | Temporary Items 34 | .apdisk 35 | 36 | # Windows 37 | # ========================= 38 | 39 | # Windows image file caches 40 | Thumbs.db 41 | ehthumbs.db 42 | 43 | # Folder config file 44 | Desktop.ini 45 | 46 | # Recycle Bin used on file shares 47 | $RECYCLE.BIN/ 48 | 49 | # Windows Installer files 50 | *.cab 51 | *.msi 52 | *.msm 53 | *.msp 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Codeigniter-Leaflet-Library 2 | =========================== 3 | 4 | ![Simple Leaflet JS library for Codeigniter](http://anggriyulio.com/public/images/leaflet-codeigniter.png) 5 | 6 | 7 | Simple Leaflet JS library for Codeigniter 8 | 9 | Features : 10 | - Create Simple Map 11 | - Add marker / multiple marker 12 | - Custom marker icon 13 | 14 | 15 | Installation : 16 | 17 | Upload Leaflet.php file application/libraries/ directory 18 | 19 | Using the libraries : 20 | 21 | 1. Loading library 22 | 23 | $this->load->library('leaflet'); 24 | 25 | 2. Include Leaflet CSS & JS file in the head section of your document: 26 | 27 | // or latest jquery 28 | 29 | 30 | 31 | 32 | 33 | 3. Let's show the map ! 34 | Controller : 35 | 36 | $config = array( 37 | 'center' => '-0.959, 100.39716', // Center of the map 38 | 'zoom' => 12, // Map zoom 39 | ); 40 | $this->leaflet->initialize($config); 41 | 42 | $marker = array( 43 | 'latlng' =>'-0.959, 100.39716', // Marker Location 44 | 'popupContent' => 'Hi, iam a popup!!', // Popup Content 45 | ); 46 | $this->leaflet->add_marker($marker); 47 | 48 | 49 | $this->data['map'] = $this->leaflet->create_map(); 50 | 51 | On the view file : 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | Feel free to send me an email if you have any problems ;) 60 | 61 | Regards, 62 | 63 | 64 | Anggri Yulio P 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /libraries/Leaflet.php: -------------------------------------------------------------------------------- 1 | OpenStreetMap, Tiles courtesy of Humanitarian OpenStreetMap Team'; 20 | 21 | // Map State Options 22 | var $center ="-0.959, 100.39716"; 23 | var $zoom ="13"; 24 | var $layers =""; 25 | var $map_name ="map"; 26 | var $minZoom =""; 27 | var $maxZoom =""; 28 | var $user =""; 29 | var $crs ="L.CRS.EPSG3857"; 30 | 31 | // Interaction options 32 | var $dragging = TRUE; 33 | var $touchZoom = TRUE; 34 | var $scrollWheelZoom = TRUE; 35 | var $doubleClickZoom = TRUE; 36 | var $boxZoom = TRUE; 37 | var $tap = TRUE; 38 | var $tapTolerance = 15; 39 | var $trackResize = TRUE; 40 | var $worldCopyJump = FALSE; 41 | var $closePopupOnClick = TRUE; 42 | var $bounceAtZoomLimits = TRUE; 43 | 44 | // Control options 45 | var $zoomControl = TRUE; 46 | var $attributionControl = TRUE; 47 | 48 | // Events 49 | var $click = ''; 50 | var $dblclick = ''; 51 | var $mousedown = ''; 52 | var $mouseup = ''; 53 | var $mouseover = ''; 54 | var $mouseout = ''; 55 | var $mousemove = ''; 56 | var $press = ''; 57 | var $focus = ''; 58 | var $blur = ''; 59 | var $existing = ''; 60 | var $load = ''; 61 | var $unload = ''; 62 | var $creating = ''; 63 | var $movestart = ''; 64 | var $move = ''; 65 | var $moveend = ''; 66 | var $dragstart = ''; 67 | var $drag = ''; 68 | var $dragend = ''; 69 | var $zoomstart = ''; 70 | var $zoomend = ''; 71 | var $zoomlevelschange = ''; 72 | var $resize = ''; 73 | var $autopanstart = ''; 74 | var $layeradd = ''; 75 | var $layerremove = ''; 76 | var $baselayerchange = ''; 77 | var $overlayadd = ''; 78 | var $overlayremove = ''; 79 | var $locationfound = ''; 80 | var $locationerror = ''; 81 | var $popupopen = ''; 82 | var $popupclose = ''; 83 | var $customFunction =''; 84 | 85 | var $markers = array(); 86 | 87 | 88 | public function __construct(){ 89 | $this->ci =& get_instance(); 90 | } 91 | 92 | function leaflet($config = array()) { 93 | if (count($config) > 0) { 94 | $this->initialize($config); 95 | } 96 | } 97 | 98 | function initialize($config = array()) { 99 | foreach ($config as $key => $val) 100 | { 101 | if (isset($this->$key)) 102 | { 103 | $this->$key = $val; 104 | } 105 | } 106 | } 107 | 108 | function add_marker($params = array()) { 109 | 110 | $marker = array(); 111 | //$this->markersInfo['marker_'.count($this->markers)] = array(); 112 | 113 | $marker['latlng'] = "-0.9583407792361563,100.3982162475586"; 114 | $marker['icon'] = ""; 115 | $marker['clickable'] = TRUE; 116 | $marker['draggable'] = FALSE; 117 | $marker['keyboard'] = TRUE; 118 | $marker['title'] = ""; 119 | $marker['alt'] = ""; 120 | $marker['zIndexOffset'] = 0; 121 | $marker['opacity'] = 1.0; 122 | $marker['riseOnHover'] = FALSE; 123 | $marker['riseOffset'] = 250; 124 | 125 | // Marker Event 126 | $marker['dragend'] =""; 127 | $marker['customFunction'] =""; 128 | $marker['iconColor'] =""; 129 | $marker['spin'] = FALSE; 130 | $marker['extraClasses'] =""; 131 | $marker['popupContent'] = ""; 132 | 133 | // Marker Icon 134 | $marker['customicon'] = FALSE; 135 | $marker['iconUrl'] = ""; 136 | $marker['iconRetinaUrl'] = ""; 137 | $marker['iconSize'] = "[20,20]"; 138 | $marker['iconAnchor'] = ""; 139 | $marker['popupAnchor'] = ""; 140 | $marker['shadowUrl'] = ""; 141 | $marker['shadowRetinaUrl'] = ""; 142 | $marker['shadowSize'] = ""; 143 | $marker['shadowAnchor'] = ""; 144 | $marker['className'] = "icon-marker"; 145 | 146 | $marker_output = ''; 147 | foreach ($params as $key => $value) { 148 | if (isset($marker[$key])) { 149 | $marker[$key] = $value; 150 | } 151 | } 152 | 153 | // Create the marker 154 | $marker_output .='marker = new L.marker(['.$marker['latlng'].'],({'; 155 | 156 | // Start of marker options 157 | if (!$marker['clickable']) { 158 | $marker_output .= 'clickable: false,'; 159 | } 160 | if (!$marker['draggable']==false) { 161 | $marker_output .= 'draggable: true,'; 162 | } 163 | 164 | if (!$marker['keyboard']) { 165 | $marker_output .= '"keyboard":false,'; 166 | } 167 | if ($marker['title']) { 168 | $marker_output .= '"title":"'.$marker['title'].'",'; 169 | } 170 | if ($marker['alt']) { 171 | $marker_output .= '"alt":"'.$marker['alt'].'",'; 172 | } 173 | if ($marker['zIndexOffset']) { 174 | $marker_output .= '"zIndexOffset":'.$marker['zIndexOffset'].','; 175 | } 176 | if (!$marker['opacity']) { 177 | $marker_output .= '"opacity":'.$marker['opacity'].','; 178 | } 179 | if ($marker['riseOnHover']) { 180 | $marker_output .= '"riseOnHover":true,'; 181 | } 182 | if (!$marker['riseOffset']) { 183 | $marker_output .= '"riseOffset":'.$marker['riseOffset'].','; 184 | } 185 | if ($marker['extraClasses']) { 186 | $marker_output .= '"extraClasses" : "'.$marker['extraClasses'].'",'; 187 | } 188 | 189 | // Custom Marker Icon 190 | if ($marker['customicon']==TRUE) { 191 | $marker_output .= 'icon: L.icon({'; 192 | 193 | $marker_output .= 'iconUrl: "'.$marker['iconUrl'].'",'; 194 | 195 | if (!$marker['iconRetinaUrl']=="") { 196 | $marker_output .= 'iconRetinaUrl: "'.$marker['iconRetinaUrl'].'",'; 197 | } 198 | if (!$marker['iconSize']=="") { 199 | $marker_output .= 'iconSize: '.$marker['iconSize'].','; 200 | } 201 | if (!$marker['iconAnchor']=="") { 202 | $marker_output .= 'iconAnchor: '.$marker['iconAnchor'].','; 203 | } 204 | if (!$marker['popupAnchor']=="") { 205 | $marker_output .= 'popupAnchor: '.$marker['popupAnchor'].','; 206 | } 207 | if (!$marker['shadowUrl']=="") { 208 | $marker_output .= 'shadowUrl: "'.$marker['shadowUrl'].'",'; 209 | } 210 | if (!$marker['shadowRetinaUrl']=="") { 211 | $marker_output .= 'shadowRetinaUrl: "'.$marker['shadowRetinaUrl'].'",'; 212 | } 213 | if (!$marker['shadowSize']=="") { 214 | $marker_output .= 'shadowSize: '.$marker['shadowSize'].','; 215 | } 216 | if (!$marker['shadowAnchor']=="") { 217 | $marker_output .= 'shadowAnchor: '.$marker['shadowAnchor'].','; 218 | } 219 | if (!$marker['className']=="") { 220 | $marker_output .= 'className: "'.$marker['className'].'",'; 221 | } 222 | $marker_output .= '}),'; 223 | } 224 | // End of Custom icon 225 | 226 | 227 | // End of marker options 228 | $marker_output .='}))'; 229 | 230 | 231 | 232 | if ($marker['popupContent'] != "") { 233 | $marker_output .= '.bindPopup("'.$marker['popupContent'].'")'; 234 | } 235 | $marker_output .='.addTo(map);'; 236 | 237 | if ($marker['dragend'] != "") { 238 | $marker_output .= 'marker.on("dragend", '.$marker['dragend'].');'; 239 | } 240 | 241 | if ($marker['customFunction'] != "") { 242 | $marker_output .= $marker['customFunction']; 243 | } 244 | 245 | array_push($this->markers, $marker_output); 246 | } 247 | 248 | 249 | function create_map() { 250 | $this->output_js = ''; 251 | $this->output_js_contents = ''; 252 | $this->output_html = ''; 253 | $this->output_html .= '
'; 254 | 255 | 256 | $this->output_js .= ' 257 | '; 304 | 305 | return array('js'=>$this->output_js, 'html'=>$this->output_html); 306 | 307 | 308 | } 309 | 310 | } 311 | 312 | /* End of file leaflet.php */ 313 | /* Location: ./application/libraries/leaflet.php */ 314 | --------------------------------------------------------------------------------