Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript][PHP]Aktywacja/dezaktywacja funkcji
rafik73
post 2.05.2019, 08:48:59
Post #1





Grupa: Zarejestrowani
Postów: 182
Pomógł: 0
Dołączył: 19.03.2014

Ostrzeżenie: (0%)
-----


Witam
Mam taki skrypt:

[JAVASCRIPT] pobierz, plaintext
  1. var highlightStyle = new ol.style.Style({
  2. stroke: new ol.style.Stroke({
  3. color: 'navy',
  4. width: 1
  5. }),
  6. fill: new ol.style.Fill({
  7. color: 'rgba(255,165,0,0.5)'
  8. }),
  9. text: new ol.style.Text({
  10. font: '16px Arial',
  11. fill: new ol.style.Fill({
  12. color: 'white'
  13. }),
  14. stroke: new ol.style.Stroke({
  15. color: 'white',
  16. width: 0
  17. })
  18. ,overflow:true
  19. ,placement:'point'
  20. ,backgroundFill: new ol.style.Fill({
  21. color: 'none'
  22. })
  23. ,backgroundStroke: new ol.style.Stroke({
  24. color: 'none',
  25. width: 0
  26. })
  27. ,padding:[3,3,3,3]
  28. ,offsetY: -60
  29. })
  30. });
  31.  
  32. var featureOverlay = new ol.layer.Vector({
  33. source: new ol.source.Vector(),
  34. map: map,
  35. style: function(feature) {
  36.  
  37. highlightStyle.getText().setText(feature.get('text_text'));
  38. return highlightStyle;
  39. }
  40. });
  41.  
  42.  
  43. var highlight;
  44. var displayFeatureInfo = function(pixel) {
  45.  
  46. var feature = map.forEachFeatureAtPixel(pixel, function(feature) {
  47. return feature;
  48. });
  49.  
  50.  
  51. if (feature !== highlight) {
  52. if (highlight) {
  53. featureOverlay.getSource().removeFeature(highlight);
  54. }
  55. if (feature) {
  56. featureOverlay.getSource().addFeature(feature);
  57. }
  58. highlight = feature;
  59. }
  60.  
  61. };
  62.  
  63. map.on('pointermove', function(evt) {
  64. if (evt.dragging) {
  65. return false;
  66. }
  67. var pixel = null;
  68.  
  69. displayFeatureInfo(null);
  70. });
  71.  
  72. map.on('click', function(evt) {
  73. displayFeatureInfo(null);
  74. });
[JAVASCRIPT] pobierz, plaintext


Chciałbym go aktywować i dezaktywować za pomocą takiego zdarzenia:

[JAVASCRIPT] pobierz, plaintext
  1. $(document).on("change","#highlight_on_check", function () {
  2.  
  3. if(this.checked)
  4.  
  5.  
  6. {
  7. //.... tutaj aktywacja
  8.  
  9. }
  10. if(!this.checked)
  11. {
  12.  
  13. //.... tutaj dezaktywacja
  14.  
  15. }
  16. });
[JAVASCRIPT] pobierz, plaintext


Ni w ząb nie wiem jak się do tego zabrać. Myślałem o takim konstruktorze:

[JAVASCRIPT] pobierz, plaintext
  1. var High = {
  2. init : function(){},
  3. setActive : function(){}
  4. }
  5.  
  6. High.init();
  7.  
  8. $(document).on("change","#highlight_on_check", function () {
  9.  
  10. if(this.checked)
  11.  
  12.  
  13. {
  14. High.setActive(true);
  15.  
  16. }
  17. if(!this.checked)
  18. {
  19.  
  20. High.setActive(false);
  21.  
  22. }
  23. });
[JAVASCRIPT] pobierz, plaintext


Jak aktywować - dezaktywować działanie tegi skryptu?
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 31.05.2024 - 04:56