Icon Pixel Operations——图标像素操作
来源:互联网 发布:松下程控交换机软件 编辑:程序博客网 时间:2024/06/16 14:29
Example using an icon to symbolize a point. Click on the icon to select it, and it will be rendered using its negative image.
使用图标来为点设置样式的例子。单击图标并选择它,它就会使用负片进行渲染。
代码:
使用图标来为点设置样式的例子。单击图标并选择它,它就会使用负片进行渲染。
代码:
<!DOCTYPE html><html> <head> <title>Icon Pixel Operations</title> <link rel="stylesheet" href="https://openlayers.org/en/v4.2.0/css/ol.css" type="text/css"> <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x --> <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script> <script src="https://openlayers.org/en/v4.2.0/build/ol.js"></script> </head> <body> <div id="map" class="map"></div> <script> // 样式函数 function createStyle(src, img) { return new ol.style.Style({ image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({ anchor: [0.5, 0.96], crossOrigin: 'anonymous', src: src, img: img, imgSize: img ? [img.width, img.height] : undefined })) }); } // 点要素 var iconFeature = new ol.Feature(new ol.geom.Point([0, 0])); // 设置样式 iconFeature.set('style', createStyle('https://openlayers.org/en/v4.2.0/examples/data/icon.png', undefined)); var map = new ol.Map({ layers: [ new ol.layer.Tile({ source: new ol.source.Stamen({layer: 'watercolor'}) }), new ol.layer.Vector({ style: function(feature) { return feature.get('style'); }, source: new ol.source.Vector({features: [iconFeature]}) }) ], target: document.getElementById('map'), view: new ol.View({ center: [0, 0], zoom: 3 }) }); var selectStyle = {}; // 创建选择交互控件 var select = new ol.interaction.Select({ style: function(feature) { var image = feature.get('style').getImage().getImage(); // 如果选择样式中不存在该样式,则重新创建样式 if (!selectStyle[image.src]) { // 创建canvas元素 var canvas = document.createElement('canvas'); // 获取绘图环境 var context = canvas.getContext('2d'); // 画布宽高 canvas.width = image.width; canvas.height = image.height; // 绘制图像 context.drawImage(image, 0, 0, image.width, image.height); var imageData = context.getImageData(0, 0, canvas.width, canvas.height); var data = imageData.data; // 图片像素反向,创建负片 for (var i = 0, ii = data.length; i < ii; i = i + (i % 4 == 2 ? 2 : 1)) { data[i] = 255 - data[i]; } context.putImageData(imageData, 0, 0); // 创建样式并添加到选择呢样式中 selectStyle[image.src] = createStyle(undefined, canvas); } return selectStyle[image.src]; } }); map.addInteraction(select); // 鼠标移到要素上时改变鼠标样式 map.on('pointermove', function(evt) { map.getTargetElement().style.cursor = map.hasFeatureAtPixel(evt.pixel) ? 'pointer' : ''; }); </script> </body></html>
阅读全文
0 0
- Icon Pixel Operations——图标像素操作
- Custom Icon——自定义图标
- Icon Colors——图标颜色
- Icon Symbolizer——图标符号
- ionic-Android-icon图标-splash启动页-常用尺寸(像素)
- 响应式布局—设备像素密度(-webkit-min-device-pixel-ratio)
- 亚像素(Pixel)
- 次像素[sub-pixel]
- 像素化pixel shader
- 亚像素 Sub Pixel
- 2.1pixel像素基础
- 2.1pixel像素基础
- 资源——图标(ICON)、鼠标、字符串资源、自定义资源
- Icon Sprites with WebGL——WebGL图标精灵
- ICON图标,
- 像素字体 pixel font 入门
- 像素字体 pixel font 入门
- 像素填充率 Pixel Fillrate
- 提高设计档次的8个方法
- 子类引用变量可以赋给父类引用变量
- WIN10下安装配置MongoDB流程及常见错误!
- get到一个访问XXX的好方法
- 面向切面编程AOP
- Icon Pixel Operations——图标像素操作
- Ubuntu14.04 opencv2.4.8和opencv3.1.0共存
- springMVC-day01
- Android开发之--studio中使用svn提交代码与检出代码
- JVM(java 虚拟机)内存设置
- C++ MoveFileA Error code is 0x2
- C++学习笔记
- Recall, Precision, and Average Precision
- spring + springMVC + spring Data jpa + maven 项目框架搭建