Skip to content

Commit

Permalink
Item11187: Tweeked KML select popup when Clustering turned off
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/OpenLayersPlugin@12910 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulAlexander authored and PaulAlexander committed Oct 28, 2011
1 parent 08380b9 commit 05509e2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
7 changes: 4 additions & 3 deletions data/Applications/OpenLayers/Layers/MyKMLFeatures.txt
@@ -1,13 +1,14 @@
%META:TOPICINFO{author="BaseUserMapping_333" comment="save topic" date="1319768451" format="1.1" reprev="7" version="7"}%
%META:TOPICINFO{author="BaseUserMapping_333" comment="reprev" date="1319773500" format="1.1" reprev="7" version="7"}%
%META:TOPICPARENT{name="Sandbox.WebHome"}%
-- Main.AdminUser - 25 Oct 2011

%META:FORM{name="Applications/OpenLayers/KMLLayerForm"}%
%META:FIELD{name="Name" attributes="" title="Name" value="KML Attachment"}%
%META:FIELD{name="URL" attributes="" title="URL" value="http://element-bp.nexus.csiro.au/pub/Applications/OpenLayers/Layers/MyKMLFeatures/atrophotergum2.kml"}%
%META:FIELD{name="URL" attributes="" title="URL" value="http://element-bp.nexus.csiro.au/pub/Applications/OpenLayers/Layers/MyKMLFeatures/sundials-3.kml"}%
%META:FIELD{name="ExtractAttributes" attributes="" title="ExtractAttributes" value="on"}%
%META:FIELD{name="ExtractStyles" attributes="" title="ExtractStyles" value="on"}%
%META:FIELD{name="Clustering" attributes="" title="Clustering" value="20,5"}%
%META:FIELD{name="Clustering" attributes="" title="Clustering" value="off"}%
%META:FIELD{name="IsVisible" attributes="" title="IsVisible" value=""}%
%META:FILEATTACHMENT{name="atrophotergum2.kml" attachment="atrophotergum2.kml" attr="" comment="" date="1319518468" path="atrophotergum2.kml" size="93480" user="BaseUserMapping_333" version="1"}%
%META:FILEATTACHMENT{name="sundials-3.kml" attachment="sundials-3.kml" attr="" comment="" date="1319772407" path="sundials-3.kml" size="100243" user="BaseUserMapping_333" version="1"}%
%META:TOPICMOVED{by="BaseUserMapping_333" date="1319759825" from="Sandbox.MyKMLFeatures" to="Applications/OpenLayers/Layers.MyKMLFeatures"}%
66 changes: 59 additions & 7 deletions lib/Foswiki/Plugins/OpenLayersPlugin.pm
Expand Up @@ -231,11 +231,11 @@ sub typehandler_kml {
if ($clustering eq 'true') {
$style=<<"HERE";
//Create a style map object and set the 'default' intent to the
var vector_style_map$layertopic = new OpenLayers.StyleMap({
'default': style
});
var vector_style_map$layertopic = new OpenLayers.StyleMap({
'default': style
});
//Add the style map to the vector layer threshold, distance
kmllayer$layertopic.styleMap = vector_style_map$layertopic;
kmllayer$layertopic.styleMap = vector_style_map$layertopic;
HERE
}

Expand All @@ -256,13 +256,22 @@ HERE
url: "$data{URL}",
format: new OpenLayers.Format.KML({
extractStyles: $extractStyles,
placemarksDesc: 'flee',
extractAttributes: $extractAttributes
})
})
});
map.addLayers([kmllayer$layertopic]);
select = new OpenLayers.Control.SelectFeature(kmllayer$layertopic);
kmllayer$layertopic.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
map.addControl(select);
select.activate();
$style
HERE

Expand Down Expand Up @@ -573,7 +582,7 @@ HERE
return (feature.cluster) ? 2 : 1;
},
pointLabel: function(feature) {
return (feature.cluster) ? feature.attributes.count : "" ;
return (feature.cluster) ? feature.attributes.count : "feature.attributes.name" ;
},
radius: function(feature) {
var pix = 3;
Expand Down Expand Up @@ -664,9 +673,52 @@ HERE
"<script src='http://maps.google.com/maps/api/js?v=3.2&sensor=false'></script>"
);
}

my $mapFunctions = <<"HERE";
<script type="text/javascript">
function onPopupClose(evt) {
select.unselectAll();
}
function onFeatureSelect(event) {
var feature = event.feature;
// Since KML is user-generated, do naive protection against
// Javascript.
var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description;
if (content.search("<script") != -1) {
content = "Content contained Javascript! Escaped content below.<br>" + content.replace(/</g, "&lt;");
}
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,100),
content,
null, true, onPopupClose);
feature.popup = popup;
map.addPopup(popup);
}
function onFeatureUnselect(event) {
var feature = event.feature;
if(feature.popup) {
map.removePopup(feature.popup);
feature.popup.destroy();
delete feature.popup;
}
}
</script>
HERE

Foswiki::Func::addToZone(
"script",
"OPENLAYERSPLUGIN::OPENLAYERSMAP",
"$mapFunctions",
"OPENLAYERSPLUGIN"
);


my $scriptVariable = "<script type='text/javascript'> var map, select; function init() { \n".join("\n", @scriptVariable)."}\n</script>";

my $scriptVariable = "<script type='text/javascript'>var map;\nfunction init() { \n".join("\n", @scriptVariable)."}\n</script>";
Foswiki::Func::addToZone(
"script",
"OPENLAYERSPLUGIN::OPENLAYERSMAP::$mapElement",
Expand Down

0 comments on commit 05509e2

Please sign in to comment.