diff --git a/examples/image-vector-layer.html b/examples/image-vector-layer.html index b8a37b6d5f..9531bbc7a4 100644 --- a/examples/image-vector-layer.html +++ b/examples/image-vector-layer.html @@ -30,22 +30,28 @@
-
+

Image vector example

Example of an image vector layer.

This example uses a ol.source.ImageVector source. That source gets vector features from the - ol.source.Vector it's configured with and draw these features to an HTML5 canvas element that + ol.source.Vector it's configured with, and draw these features to an HTML5 canvas element that is then used as the image of an image layer.

See the image-vector-layer.js source to see how this is done.

vector, image
+
+
+   +
+
+ diff --git a/examples/image-vector-layer.js b/examples/image-vector-layer.js index 76e6e83dae..279bb5f284 100644 --- a/examples/image-vector-layer.js +++ b/examples/image-vector-layer.js @@ -1,8 +1,9 @@ goog.require('ol.Map'); -goog.require('ol.RendererHints'); +goog.require('ol.RendererHint'); goog.require('ol.View2D'); goog.require('ol.layer.Image'); goog.require('ol.layer.Tile'); +goog.require('ol.render.FeaturesOverlay'); goog.require('ol.source.GeoJSON'); goog.require('ol.source.ImageVector'); goog.require('ol.source.MapQuest'); @@ -37,10 +38,63 @@ var map = new ol.Map({ }) }) ], - renderers: ol.RendererHints.createFromQueryData(), + renderer: ol.RendererHint.CANVAS, target: 'map', view: new ol.View2D({ center: [0, 0], zoom: 1 }) }); + +var highlightStyleArray = [new ol.style.Style({ + stroke: new ol.style.Stroke({ + color: '#f00', + width: 1 + }), + fill: new ol.style.Fill({ + color: 'rgba(255,0,0,0.1)' + }) +})]; + +var featuresOverlay = new ol.render.FeaturesOverlay({ + map: map, + styleFunction: function(feature, resolution) { + return highlightStyleArray; + } +}); + +var highlight; +var displayFeatureInfo = function(pixel) { + + var feature = map.forEachFeatureAtPixel(pixel, function(feature, layer) { + return feature; + }); + + var info = document.getElementById('info'); + if (feature) { + info.innerHTML = feature.getId() + ': ' + feature.get('name'); + } else { + info.innerHTML = ' '; + } + + if (feature !== highlight) { + if (highlight) { + featuresOverlay.removeFeature(highlight); + } + if (feature) { + featuresOverlay.addFeature(feature); + } + highlight = feature; + } + +}; + +$(map.getViewport()).on('mousemove', function(evt) { + var pixel = map.getEventPixel(evt.originalEvent); + displayFeatureInfo(pixel); +}); + +map.on('singleclick', function(evt) { + var pixel = evt.getPixel(); + displayFeatureInfo(pixel); +});