L.supermap.graphic里style参数设置为L.supermap.imageStyle,参考https://iclient.supermap.io/examples/leaflet/editor.html#12_graphicLayerImage示例
我已经引用了include-leaflet.js 但是还是会报Uncaught TypeError: Cannot read property 'imageStyle' of undefined
var points = []; var image = []; ar img = new Image(); img.src =obj.exhibitDatas[5].iconUrl; img.onload = function () { image.push(L.supermap.imageStyle({ img: img, anchor: [16, 16] })); for(var i = 0; i<obj.exhibitDatas.length; i++){ points.push( L.supermap.graphic({ latLng: L.latLng(obj.exhibitDatas[i].longitude,obj.exhibitDatas[i].latitude), style: image[0].getStyle() })) } L.supermap.graphicLayer(points, { render: 'canvas' }).addTo(map); }
参考例子里的方法去加载图片 使用SuperMap.Layer.Graphics调用会报Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'
graphicLayer = new SuperMap.Layer.Graphics("Graphic Layer", null, {hitDetection: true, useCanvasEvent: false}); var selectGraphic = new SuperMap.Control.SelectGraphic(graphicLayer, { onSelect: showPopup, hover: false }); var points = []; var image = []; var img = new Image(); img.src =obj.exhibitDatas[5].iconUrl; img.onload = function () { image.push(L.supermap.imageStyle({ img: img, anchor: [16, 16] })); for(var i = 0; i<obj.exhibitDatas.length; i++){ var point= new SuperMap.Geometry.Point(obj.exhibitDatas[i].longitude, obj.exhibitDatas[i].latitude); var pointVector = new SuperMap.Graphic(point); pointVector.style={ image: image[0].getStyle() }; pointVector.scope=obj.exhibitDatas[i]; points.push(pointVector) } graphicLayer.addGraphics(points); map.addLayers([markerLayer, graphicLayer]); map.addControl(selectGraphic); selectGraphic.activate(); }
如果使用L.supermap.graphicLayer调用 在最后面addTo(map)的时候会报Uncaught TypeError: Cannot set property 'className' of undefined
var points = []; var image = []; var img = new Image(); img.src =obj.exhibitDatas[5].iconUrl; img.onload = function () { image.push(L.supermap.imageStyle({ img: img, anchor: [16, 16] })); for(var i = 0; i<obj.exhibitDatas.length; i++){ if(typeof(obj.exhibitDatas[i].longitude)=="undefined"){ continue; } points.push( L.supermap.graphic({ latLng: L.latLng(obj.exhibitDatas[i].longitude,obj.exhibitDatas[i].latitude), style: image[0].getStyle() })) } L.supermap.graphicLayer(points, { render: 'canvas', onClick: function (graphic, evt) { L.popup().setLatLng(evt.latlng) .setContent('<p>' + resources.text_latLng + ':<br>' + graphic.getLatLng() .lng + ',<br>' + graphic.getLatLng().lat + '</p>') } }).addTo(map); }