Commits

Bogdan Savluk committed a7e16e7

Added optional params for coordinate picker : default position, zoom settings.

  • Participants
  • Parent commits a770ed9

Comments (0)

Files changed (2)

CoordinatePicker.php

     /** @var string An absolute URL to the published assets */
     public $assets;
 
+    /** @var float Default latitude for picked coordinates, by default set to Kiev */
+    public $defaultLatitude;
+    /** @var float Default longitude for picked coordinates, by default set to Kiev */
+    public $defaultLongitude;
+    /** @var int Map zoom level when editing already picked coordinates, by default at city level(12) */
+    public $editZoom;
+    /** @var int Map zoom level when picking new coordinates, by default at country level(7) */
+    public $pickZoom;
+
     /**
      *  Publish assets and generate input ids when they is not set
      */
 
         echo CHtml::link($this->label, '#', array('id' => $this->getId()));
 
-        $cs->registerScript($this->getId() . 'script', <<<EOD
-$('#{$this->getId()}').coordinate_picker({
-	'lat_selector':  '#{$this->latitudeInputId}',
-	'long_selector': '#{$this->longitudeInputId}'
-});
-EOD
+        $pluginSettings = array(
+            'lat_selector' => "#{$this->latitudeInputId}",
+            'long_selector' => "#{$this->longitudeInputId}",
         );
+        if (isset($this->defaultLatitude))
+            $pluginSettings['default_lat'] = $this->defaultLatitude;
+        if (isset($this->defaultLongitude))
+            $pluginSettings['default_long'] = $this->defaultLongitude;
+        if (isset($this->editZoom))
+            $pluginSettings['edit_zoom'] = $this->editZoom;
+        if (isset($this->pickZoom))
+            $pluginSettings['pick_zoom'] = $this->pickZoom;
+
+        $pluginSettings = CJavaScript::encode($pluginSettings);
+        $cs->registerScript($this->getId() . 'script', "$('#{$this->getId()}').coordinate_picker({$pluginSettings});");
 
     }
 

CoordinatePicker/coordinate_picker/map.js

             var settings = {
                 lat_selector:'#lat',
                 long_selector:'#long',
+                default_lat:50.443513052458044,
+                default_long:30.498046875,
+                edit_zoom:12,
+                pick_zoom:7,
                 onComplete:false
             };
 
             }
 
             //todo: save this in coockies
-            var zoom = 12; // town level
+            var zoom = settings.edit_zoom; // town level
 
             var coord_lat, coord_long;
             // try to load coords from inputs
+
             if ($(settings.long_selector, window.parent.document).length) {
                 coord_long = 0 + $(settings.long_selector, window.parent.document).attr('value');
             }
             }
 
             // Kyiv Coords
-            if (coord_lat < 0.0000000001 && coord_long < 0.0000000001) {
-                coord_lat = 50.443513052458044;
-                coord_long = 30.498046875;
-                zoom = 7; // counry level
+            if (Math.abs(coord_lat) < 0.0000000001 && Math.abs(coord_long) < 0.0000000001) {
+                coord_lat = settings.default_lat;
+                coord_long = settings.default_long;
+                zoom = settings.pick_zoom; // counry level
             }