Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 开放层3。如何向线条和标记添加标签_Typescript_Openlayers 3 - Fatal编程技术网

Typescript 开放层3。如何向线条和标记添加标签

Typescript 开放层3。如何向线条和标记添加标签,typescript,openlayers-3,Typescript,Openlayers 3,我正在创建Openlayers3地图。与给出的示例不同,我必须先为每个图层创建样式,然后才能知道特性是什么。我使用以下顺序: 初始化地图 为每个组/ol.layer.vector设置样式 例如: this.addGroup('testPackages', { normalStyle: new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#c407d3', width:

我正在创建Openlayers3地图。与给出的示例不同,我必须先为每个图层创建样式,然后才能知道特性是什么。我使用以下顺序:

  • 初始化地图
  • 为每个组/ol.layer.vector设置样式
  • 例如:

        this.addGroup('testPackages', {
                normalStyle: new ol.style.Style({
                    stroke: new ol.style.Stroke({ color: '#c407d3', width: 3, lineDash: [.1, 5] }),
                    fill: new ol.style.Fill({ color: 'rgba(196, 7, 211, 0.1)' })
                }),
                hoverStyle: new ol.style.Style({
                    stroke: new ol.style.Stroke({ color: '#c407d3', width: 3, lineDash: [.1, 5] }),
                    fill: new ol.style.Fill({ color: 'rgba(196, 7, 211, 0.4)' })
                }),
                selectedStyle: new ol.style.Style({
                    stroke: new ol.style.Stroke({ color: '#c407d3', width: 3 }),
                    fill: new ol.style.Fill({ color: 'rgba(196, 7, 211, 0.4)' })
                })
    
            });
    
        this.addGroup('cabinets', {
                normalStyle: new ol.style.Style({
                    image: new ol.style.Icon(({
                        scale: 0.25,
                        anchor: [0.5, 1],
                        anchorXUnits: 'fraction',
                        anchorYUnits: 'fraction',
                        opacity: 1,
                        src: '/images/olMaps/house.png'
                    }))
                }),
                hoverStyle: new ol.style.Style({
                    image: new ol.style.Icon(({
                        scale: 0.25,
                        anchor: [0.5, 1],
                        anchorXUnits: 'fraction',
                        anchorYUnits: 'fraction',
                        opacity: 1,
                        src: '/images/olMaps/house.png'
                    }))
                }),
                selectedStyle: new ol.style.Style({
                    image: new ol.style.Icon(({
                        scale: 0.25,
                        anchor: [0.5, 1],
                        anchorXUnits: 'fraction',
                        anchorYUnits: 'fraction',
                        opacity: 1,
                        src: '/images/olMaps/house.png'
                    }))
                })
    
            })
    
        drawLine(geoShape: any, assetId: string, group: IAssetGroup) { // vectorLine: ol.source.Vector, style?: ol.style.Style) {
    
            // Transform the geometry for a map line-string.
            const transformedGeometry = this.transformCoordinates(geoShape);
            const lineString = new ol.geom.LineString(<any>transformedGeometry);
    
            // Create the line-string feature.
            const feature = new ol.Feature({
                geometry: lineString,
                id: assetId,
                group: group
            });
    
            // Set the style on the feature?
            if (!!group.normalStyle)
                feature.setStyle(group.normalStyle);
    
            // new lines
    
            var myStyle = group.normalStyle;
            myStyle = this.styleFunction(myStyle, feature);
            feature.setStyle(myStyle);
    
            // end
    
    
            // Add the feature to the vector-set.
            group.vector.addFeature(feature);
    
            // Add to list of all features.
            this.allFeatures.push(feature);
            this.lookupFeatures[assetId] = feature;
    
        }
    
  • 在地图上画特征
  • 例如:

        this.addGroup('testPackages', {
                normalStyle: new ol.style.Style({
                    stroke: new ol.style.Stroke({ color: '#c407d3', width: 3, lineDash: [.1, 5] }),
                    fill: new ol.style.Fill({ color: 'rgba(196, 7, 211, 0.1)' })
                }),
                hoverStyle: new ol.style.Style({
                    stroke: new ol.style.Stroke({ color: '#c407d3', width: 3, lineDash: [.1, 5] }),
                    fill: new ol.style.Fill({ color: 'rgba(196, 7, 211, 0.4)' })
                }),
                selectedStyle: new ol.style.Style({
                    stroke: new ol.style.Stroke({ color: '#c407d3', width: 3 }),
                    fill: new ol.style.Fill({ color: 'rgba(196, 7, 211, 0.4)' })
                })
    
            });
    
        this.addGroup('cabinets', {
                normalStyle: new ol.style.Style({
                    image: new ol.style.Icon(({
                        scale: 0.25,
                        anchor: [0.5, 1],
                        anchorXUnits: 'fraction',
                        anchorYUnits: 'fraction',
                        opacity: 1,
                        src: '/images/olMaps/house.png'
                    }))
                }),
                hoverStyle: new ol.style.Style({
                    image: new ol.style.Icon(({
                        scale: 0.25,
                        anchor: [0.5, 1],
                        anchorXUnits: 'fraction',
                        anchorYUnits: 'fraction',
                        opacity: 1,
                        src: '/images/olMaps/house.png'
                    }))
                }),
                selectedStyle: new ol.style.Style({
                    image: new ol.style.Icon(({
                        scale: 0.25,
                        anchor: [0.5, 1],
                        anchorXUnits: 'fraction',
                        anchorYUnits: 'fraction',
                        opacity: 1,
                        src: '/images/olMaps/house.png'
                    }))
                })
    
            })
    
        drawLine(geoShape: any, assetId: string, group: IAssetGroup) { // vectorLine: ol.source.Vector, style?: ol.style.Style) {
    
            // Transform the geometry for a map line-string.
            const transformedGeometry = this.transformCoordinates(geoShape);
            const lineString = new ol.geom.LineString(<any>transformedGeometry);
    
            // Create the line-string feature.
            const feature = new ol.Feature({
                geometry: lineString,
                id: assetId,
                group: group
            });
    
            // Set the style on the feature?
            if (!!group.normalStyle)
                feature.setStyle(group.normalStyle);
    
            // new lines
    
            var myStyle = group.normalStyle;
            myStyle = this.styleFunction(myStyle, feature);
            feature.setStyle(myStyle);
    
            // end
    
    
            // Add the feature to the vector-set.
            group.vector.addFeature(feature);
    
            // Add to list of all features.
            this.allFeatures.push(feature);
            this.lookupFeatures[assetId] = feature;
    
        }
    
    //结束

                drawMarker(geoLocation: [number, number], assetId: string, type: string, group: IAssetGroup) {
    
            // Transform the geometry for a map point.
            const coordinates = this.transformCoordinates(geoLocation);
            const pointGeometry = new ol.geom.Point(<any>coordinates);
    
            // Create the point feature.
            const feature = new ol.Feature({
                geometry: pointGeometry,
                id: assetId,
                group: group
            });
    
            // Set the style on the feature?
            if (!!group.normalStyle)
                feature.setStyle(group.normalStyle);
    
            // Add the feature to the vector-set.
            group.vector.addFeature(feature);
    
            // Add to list of all features.
            this.allFeatures.push(feature);
            this.lookupFeatures[assetId] = feature;
    
        }
    
    drawMarker(地理位置:[编号,编号],assetId:string,type:string,group:IAssetGroup){
    //变换贴图点的几何体。
    常量坐标=此坐标(地理位置);
    常量点几何=新的ol.几何点(坐标);
    //创建点要素。
    常量特征=新的ol.特征({
    几何:点几何,
    id:assetId,
    组:组
    });
    //在功能上设置样式?
    如果(!!group.normalStyle)
    特征.setStyle(组.normalStyle);
    //将特征添加到向量集。
    group.vector.addFeature(特征);
    //添加到所有功能的列表中。
    此.allFeatures.push(功能);
    this.lookupFeatures[assetId]=特征;
    }
    

    然后如何为每个功能添加标签名称?

    Openlayers 3之间可能存在重复:将文本标签添加到功能和我的问题。我们正在使用完全不同的方法。您的答案就在那里,无论您采用何种方法,添加标签的方式都是相同的。drawLine和drawMarker中都有一条线用于检查样式:group.normalStyle。可能有办法在这里添加标签,但我不知道如何添加。好的。我已经在原来的帖子上添加了我的答案。