简体   繁体   English

保存输入表单后ImageMap颜色更改

[英]ImageMap color change after saving an Input Form

I'd like to create a map with sections that are assigned a color based on a checkbox selection on an Input Form. 我想创建一个地图,其中包含根据输入表单上的复选框选择分配颜色的部分。 Most of what I've read describes clickable Image Maps that change colors onclick or onhover. 我读过的大部分内容都描述了可点击的图片映射,它们会在点击或悬停时更改颜色。 This would not be necessary for my map. 这对于我的地图而言不是必需的。 The intent would be to save the chosen sections within the Input Form and subsequently display the colored areas on a Display screen that cannot be changed onclick or onhover. 目的是将所选部分保存在输入表单中,然后在无法单击或悬停时更改的显示屏幕上显示彩色区域。 I'd like to use this as an Evacuation Map to let users know what areas to evacuate. 我想以此作为疏散地图,让用户知道要疏散哪些区域。

I've looked into ImageMapster which could be useful but I haven't figured out how to incorporate it. 我研究了ImageMapster,它可能很有用,但是我还没有弄清楚如何将其合并。

Here are a couple examples that I'd like to use in some sort of combination. 以下是一些我想结合使用的示例。

jsfiddle.net/jamietre/hD6bM/ jsfiddle.net/jamietre/hD6bM/

jsfiddle.net/BH79/xqaFX/ jsfiddle.net/BH79/xqaFX/

Again, all I really need is basic form with checkbox options which then updates the map selection with a color upon saving. 同样,我真正需要的是带有复选框选项的基本表单,然后在保存时用颜色更新地图选择。 Thanks for any help! 谢谢你的帮助!

If you need to use an imagemap and are ok with using imagemapster (which is actually quite good), then you could do the following: 如果您需要使用图像映射,并且可以使用imagemapster(这实际上非常好),那么可以执行以下操作:

Working example: http://jsfiddle.net/hD6bM/130/ 工作示例: http : //jsfiddle.net/hD6bM/130/

The HTML HTML

  1. Give each of your checkboxes a unique identifier so you will know which map area to highlight (in this example an id with value "Washington"). 为您的每个复选框提供一个唯一的标识符,以便您知道要突出显示的地图区域(在此示例中,值为“华盛顿”的ID)。
  2. Give each area the same identifier (I just used the default "full" attribute that came with the imagemapster example). 为每个区域赋予相同的标识符(我只是使用了imagemapster示例随附的默认“完整”属性)。

The jQuery jQuery的

  1. Enable imagemapster on the map and disable default highlighting and selection of areas. 在地图上启用imagemapster,并禁用默认的突出显示和区域选择。

     $('img').mapster({ isSelectable: false, highlight: false }); 
  2. Create a style for the clicked map area (just an example, see imagemapster documentation for the different possibilities). 为单击的地图区域创建样式(仅作为示例,请参见imagemapster文档以了解不同的可能性)。

     clickedOptions = { fill: true, fillColor: '00ff00', stroke: true, strokeColor: '000000', strokeWidth: 1 }; 
  3. Toggle the new style when a checkbox is clicked. 单击复选框时切换新样式。

     $('.checkbox').toggle(function () { $("[full='" + $(this).attr('id') + "']").mapster('set', true, clickedOptions); // Clicked fill }, function () { $("[full='" + $(this).attr('id') + "']").mapster('set', false); // Back to no fill }); 

This is just an example... there may be a better way to target your elements, but it all depends on how the rest of your code ends up working. 这只是一个示例……可能有一种更好的方法来定位您的元素,但是这完全取决于其余代码的工作方式。


EDIT 编辑

Just noticed that I misread your question, the above is for onclick of the checkboxes. 只是注意到我误读了您的问题,以上内容是针对复选框的onclick。 If you want the map to update only after a form submit, you can modify the above code to something like this: 如果您希望仅在提交表单后更新地图,则可以将上面的代码修改为如下形式:

// On submit highlight selected areas.
$( "form" ).submit(function( event ) {
    $('.checkbox').each(function(i, obj) {
        if ($(this).is(':checked')) {
            $("[full='" + $(this).attr('id') + "']").mapster('set', true, clickedOptions);
        } else {
            $("[full='" + $(this).attr('id') + "']").mapster('set', false);
        }
    });
  event.preventDefault();
});

Here another working example: http://jsfiddle.net/hD6bM/132/ 这是另一个工作示例: http : //jsfiddle.net/hD6bM/132/

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

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