无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

mapbox-gl開發(fā):動態(tài)畫線標(biāo)繪

2022-07-19 08:56 作者:地理信息技術(shù)雜談  | 我要投稿

在mapbox-gl地圖上,實現(xiàn)動態(tài)畫線的效果,點(diǎn)擊左鍵增加畫線的點(diǎn),鼠標(biāo)移動,實現(xiàn)線隨著鼠標(biāo)移動位置的效果,點(diǎn)擊右鍵結(jié)束畫線。

mapbox-gl接口實現(xiàn)標(biāo)繪數(shù)據(jù)存儲在geojson數(shù)據(jù)中,通過添加數(shù)據(jù)源、修改數(shù)據(jù)源,實現(xiàn)地圖上的標(biāo)繪數(shù)據(jù)實時更新。

添加geojson數(shù)據(jù)源:

? ? ??this.map.addSource(this.sourceid,?{

? ? ? ? ? ??type:?'geojson',

? ? ? ? ???data:?this.geojsondata

? ?????})

添加線標(biāo)繪圖層,設(shè)置線標(biāo)繪的屬性信息:

? ???this.map.addLayer({

? ? ? ?id:?this.linelayerid,

? ? ? ?type:?'line',

? ? ? ?source:?this.sourceid,

? ? ????layout:?{

? ? ? ? ?'line-cap':?'round',

? ? ? ? ??'line-join':?'round'

? ? ? ?},

? ? ? ? paint:?{

? ? ? ? ?'line-color':?'#f00',

? ? ? ? ?'line-width':?2

? ? ? ?},

? ?????filter:?['in',?'$type',?'LineString']

? ? })

鼠標(biāo)動態(tài)移動事件,線的終點(diǎn)隨著鼠標(biāo)移動

this.mapmousemovefunc?=?function?(e)?{

????const?_editfeature?=?scope.geojsondata.features[scope.getEditFeatureid()]

????_editfeature.geometry.coordinates.splice(_editfeature.geometry.coordinates.length?-?1,?1,?[e.lngLat.lng,?e.lngLat.lat])

????scope.map.getSource(scope.sourceid).setData(scope.geojsondata)

??}

鼠標(biāo)點(diǎn)擊事件,分為初次點(diǎn)擊和之后點(diǎn)擊的事件

??this.mapclickfunc?=?function?(e)?{

????if?(_isfirst)?{

再次點(diǎn)擊鼠標(biāo),修改最后一個點(diǎn),并新增點(diǎn)

??????const?_editfeature?=?scope.geojsondata.features[scope.getEditFeatureid()]

??????_editfeature.geometry.coordinates.splice(_editfeature.geometry.coordinates.length?-?1,?1,?[e.lngLat.lng,?e.lngLat.lat])

??????_editfeature.geometry.coordinates.push([e.lngLat.lng,?e.lngLat.lat])

??????let?_centerpos?=?turf.centroid(scope.geojsondata)?

??????_editfeature.properties.centerpos?=??_centerpos.geometry.coordinates

??????scope.map.getSource(scope.sourceid).setData(scope.geojsondata)

????}?else?{

? ?初次點(diǎn)擊鼠標(biāo),創(chuàng)建線數(shù)據(jù)

??????_isfirst?=?true

??????scope.editfeatureid?=?scope.createuuid()

??????scope.geojsondata.features.push({

????????type:?'Feature',

????????geometry:?{

??????????type:?'LineString',

??????????coordinates:?[

????????????[e.lngLat.lng,?e.lngLat.lat],

????????????[e.lngLat.lng?+?0.000001,?e.lngLat.lat]

??????????]

????????},

????????properties:?{

??????????id:?scope.editfeatureid,

??????????sourceid:?scope.sourceid,

??????????isdraw:?true,

??????????centerpos:?[e.lngLat.lng,?e.lngLat.lat],?

??????????color:?'#f00',

??????????opacity:?0.7

????????}

??????})

??????scope.map.on('mousemove',?scope.mapmousemovefunc)

????}

??}

//增加鼠標(biāo)點(diǎn)擊,右鍵結(jié)束標(biāo)繪事件

this.map.on('click',?this.mapclickfunc)

this.maprightclickfunc?=?function?()?{

????scope.stop()

??}

??this.map.on('contextmenu',?this.maprightclickfunc)



mapbox-gl開發(fā):動態(tài)畫線標(biāo)繪的評論 (共 條)

分享到微博請遵守國家法律
拉萨市| 乌鲁木齐县| 瑞安市| 射阳县| 汽车| 江华| 花莲县| 施秉县| 庆云县| 廊坊市| 察雅县| 皋兰县| 呼和浩特市| 靖宇县| 临沧市| 甘南县| 华蓥市| 肃宁县| 承德县| 赤峰市| 虹口区| 三门县| 新安县| 漳州市| 宁化县| 长丰县| 江都市| 巴林右旗| 云林县| 新竹县| 黄大仙区| 巴楚县| 鹤庆县| 元谋县| 万盛区| 京山县| 探索| 慈溪市| 宜昌市| 大洼县| 阜新|