1

I'm trying to understand how Leaflet works. I'm trying this tutorial. I deleted some code from tutorial for more clean code. Now have a problem with L.control.layers.

If i want to add overlay like this

var overlays = {
          "Cities": cities
            };

var layersControl = L.control.layers(null, overlays);

There is no problem with adding overlays to control. With this code, I can show/hide layer with clicking checkbox

But if I want to add overlay like this

 var overlays = {
              "Cities": cities
                };
var layersControl = L.control.layers();
layersControl.addOverlay(overlays);

There is problem with overlays. Here when i want to show/hide layer with clicking checkbox, an error appearing.

Uncaught TypeError: Object # has no method 'onAdd' at file:///android_asset/www/leaflet.js:6

Uncaught TypeError: Object # has no method 'onRemove' at file:///android_asset/www/leaflet.js:6

I have to use 2. piece of code. Can anyone help me ?

Full code is here

var cities = new L.LayerGroup();

 L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.').addTo(cities),
            L.marker([39.74, -104.99]).bindPopup('This is Denver, CO.').addTo(cities),
            L.marker([39.73, -104.8]).bindPopup('This is Aurora, CO.').addTo(cities),
            L.marker([39.77, -105.23]).bindPopup('This is Golden, CO.').addTo(cities);


            var cmAttr = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
                cmUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/{styleId}/256/{z}/{x}/{y}.png';



            var map = L.map('map');


            map.addLayer(cities,true);
            map.setView([39.73, -104.99],10);

            var overlays = {

                "Cities": cities

            };

    var layersControl = L.control.layers(null, overlays);

     layersControl.setPosition("bottomleft");

     layersControl.addTo(map);

codeigniter submit ajax alert success

i have this form that submits personal details

here is my view

<?php $attributes=a rray( 'autocomplete'=>"off", 'id' => 'theForm');?>
<?php echo form_open_multipart( 'employee/personaldetails', $attributes); ?>
<div class="row">
<div class="span3 offset1">
    <label>First Name</label>
    <input onkeypress="return fnAllowAlpha(event);" maxlength="50" type="text" value="<?php echo $info['first_name']; ?>" name="first_name" disabled>
    <input type="hidden" value="<?php echo $info['employee_image']; ?>" name="employee_image" disabled>
</div>
<div class="span3">
    <label>Middle Name</label>
    <input onkeypress="return fnAllowAlpha(event);" maxlength="50" type="text" value="<?php echo $info['middle_name']; ?>" name="middle_name" disabled>
</div>
<div class="span3">
    <label>Last Name</label>
    <input onkeypress="return fnAllowAlpha(event);" maxlength="50" type="text" value="<?php echo $info['last_name']; ?>" name="last_name" disabled>
</div>
<div class="span1">
    <div class="down1">
        <button type="submit" class="button-orange" id="btnSave" style="display:none;">Save</button>
    </div>
</div>  

CONTROLLER

$this->load->model('mdl_employee','emp');
$id = $this->session->userdata('id');
$P1 = $this->input->post('first_name');
$P2 = $this->input->post('middle_name');
$P3 = $this->input->post('last_name');
$this->emp->update_myinfo($id, $P1, $P2, $P3);

model

public function update_myinfo($id, $P1, $P2, $P3){
  $employee_data = array(
           'first_name' => $P1,
           'middle_name' => $P2,
           'last_name' => $P3);
$this->db->where('employee_id', $id);
$this->db->update('employee', $employee_data);
}

i dont know how to use ajax. i want to alert the ajax if success or not. after updating my database.. im just new programmer

4

1 回答 1

5

我自己找到了解决方案。

我直接添加了城市对象,而不是尝试添加叠加层

var layersControl = L.control.layers();
layersControl.addOverlay(cities,'Cities');
于 2013-10-28T14:57:38.343 回答