简体   繁体   English

单击地图外部的按钮时,为所选图层打开一个jquery ui对话框

[英]Open a jquery ui dialog box for the layer selected when clicking a button outside the map

I have a leaflet map with multiple layers. 我有一个包含多个图层的传单地图。 I can draw polylines, delete and edit them for a particular layer and then, send some informations with a jquery ui dialog box, to my postGis db. 我可以绘制折线,删除和编辑特定图层,然后使用jquery ui对话框发送一些信息到我的postGis数据库。

No problem for drawing and delete my polylines. 绘制和删除我的折线没有问题。 I click on a button outside the map and can continue drawing a selected layer or delete polylines from a layer. 我单击地图外部的按钮,可以继续绘制选定图层或从图层中删除折线。

But now, how can I click on a button outside my map and open a dialog box relative to the layer I'm editing ? 但现在,如何点击地图外的按钮并打开相对于我正在编辑的图层的对话框?

I've tried calling my save button on the "oneachfeature" of my layer, so then when I select a layer and click on my save button, it first opens the dialog box relative to the layer selected but after, it also opens the dialog box for my other layer. 我尝试在我的图层的“oneachfeature”上调用我的保存按钮,然后当我选择一个图层并单击我的保存按钮时,它首先打开相对于所选图层的对话框,但之后,它还会打开对话框我的另一层的框。

Here some code to explain what I'm doing : 这里有一些代码来解释我在做什么:

 //I'm calling my first WFS layer var ajaxlayer1 = $.ajax({ url : owsrootUrlAssainissement + L.Util.getParamString(parameterslayer1), dataType : 'jsonp', jsonpCallback: 'calllayer1' }); ajaxlayer1.done(layer1); function layer1 (reseaulayer1) { conduites_layer1 = new L.geoJson(reseaulayer1, { onEachFeature: eachfeaturelayer1 }); return layer1; } function eachfeaturelayer1 (feature, layer) { layer.on('click', function(e){ if(selectedFeature) selectedFeature.disableEdit(); map.closePopup(); selectedFeature = e.target; e.target.enableEdit(); }); layer.on('editable:enable',function (e) { //do some stuff here }); $('#saveBtn').on('click',function(e){ layer.disableEdit(); //open a jquery ui dialog box with informations from my second layer //var dialog1 = ... dialog_layer1.dialog("open"); }); layer.on('editable:disable',function (e) { // Some code to recover layer's coordinates, ... }); } //I'm calling my second WFS layer var ajaxlayer2 = $.ajax({ url : owsrootUrlAssainissement + L.Util.getParamString(parameterslayer2), dataType : 'jsonp', jsonpCallback: 'calllayer2' }); ajaxlayer2.done(layer2); function layer2 (reseaulayer2) { conduites_layer2 = new L.geoJson(reseaulayer2, { onEachFeature: eachfeaturelayer2 }); return layer2; } function eachfeaturelayer2 (feature, layer) { layer.on('click', function(e){ if(selectedFeature) selectedFeature.disableEdit(); map.closePopup(); selectedFeature = e.target; e.target.enableEdit(); }); layer.on('editable:enable',function (e) { //do some stuff here }); $('#saveBtn').on('click',function(e){ layer.disableEdit(); //open a jquery ui dialog box with informations from my second layer //var dialog2 = ... dialog_layer2.dialog("open"); }); layer.on('editable:disable',function (e) { // Some code to recover layer's coordinates, ... }); } 

I would suggest something like this, where the dialog is defined and later adjusted when the save action is needed. 我建议这样的事情,定义对话框,然后在需要保存操作时进行调整。

Working Example: https://jsfiddle.net/Twisty/f1gvo1h6/ 工作示例: https//jsfiddle.net/Twisty/f1gvo1h6/

HTML HTML

<div>
  <div class="artwork">
  </div>
  <button id="saveBtn">
    Save
  </button>
</div>

<div id="saveDialog" title="Save Layer">
  <p><span class="ui-icon ui-icon-alert" style="float:left; margin:12px 12px 20px 0;"></span>Do you wish to save the changes to this layer?</p>
</div>

jQuery jQuery的

$(function() {

  $("#saveDialog").dialog({
    autoOpen: false,
    resizable: false,
    height: "auto",
    width: 400,
    modal: true
  });
  $("#saveBtn").click(function() {
    // Gather the layer that is being edited
    // Create actions and buttons
    $("#saveDialog").dialog("option", "buttons", [{
      text: "Save",
      click: function() {
        // Do stuff for the layer save
        // layer.disableEdit();
        $(this).dialog("close");
      }
    }, {
      text: "Cancel",
      click: function() {
        $(this).dialog("close");
      }
    }]);
    // Open Save Dialog
    $("#saveDialog").dialog("open");
  });
});

Some of this is from the Modal Confirmation Example . 其中一些来自Modal确认示例 Basically, we know that on any layer, the save button might be called. 基本上,我们知道在任何图层上都可以调用保存按钮。 We do not need to create a unique dialog for each. 我们不需要为每个创建一个唯一的对话框。 We can create one, and then modify the buttons as needed. 我们可以创建一个,然后根据需要修改按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM