我有在設置使用 https://github.com/googlemaps/js-map-label獲得來自谷歌地圖的所有標記設置文本標籤
設置標籤USNG庫中的文本標籤的麻煩做這樣的事情:
//var marker = ...
var textLabel = new MapLabel({
text: 'some text'
position: position, //google maps LatLng position
map: map,
fontSize: 35,
align: 'right'
});
textLabel.set('position', position);
marker.bindTo('map', textLabel);
marker.bindTo('position', textLabel);
我用addGeoJson方法導入所有數據,我無法訪問標記。有什麼辦法可以解決這個問題嗎?
我需要爲顯示的每個標記設置一個文本。 這裏是我目前的實施:
map.data.addGeoJson(response.data, {idPropertyName: "id"});
map.data.setStyle(function(feature){
var color = feature.getProperty('color');
var zIndex = feature.getProperty('zIndex');
if(feature.getGeometry().getType().toLowerCase() == "point"){
return {
icon: globalOptions.textMarkerPath
}
}else{
return {
fillColor: 'rgb(' + color + ')',
strokeColor: 'rgb(' + color + ')',
fillOpacity: 0.4,
strokeOpacity: 1,
strokeWeight: 1,
zIndex: zIndex
}
}
});
map.data.forEach(function(feature){
if(feature.getGeometry().getType().toLowerCase() == "point") {
var textLabel = new MapLabel({
text: feature.getProperty("text"),
position: feature.position,
map: map,
fontSize: 35,
align: 'right'
});
textLabel.set('position', feature.position);
feature.bindTo('map', textLabel);
feature.bindTo('position', textLabel);
feature.setProperty('textLabel', textLabel);
}
});
再次感謝。
編輯 這裏是一個GeoJSON的響應(修剪一個)的例子:
{
"viewable": true,
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"id": 11766,
"text": "",
"layer": "limitaimobil",
"color": "35,40,50",
"zIndex": 7,
"area": 448,
"is_associated": false
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
26.1373083033642,
47.7787618059076
],
[
26.1371254511354,
47.778684435143
],
[
26.1370035662918,
47.7789188945034
],
[
26.1371962266472,
47.779000415299
],
[
26.1373083033642,
47.7787618059076
]
]
]
}
},
{
"type": "Feature",
"properties": {
"id": 12541,
"text": "2",
"layer": "limitaparcela",
"color": "51,153,255",
"zIndex": 48,
"area": 0,
"is_associated": false
},
"geometry": {
"type": "Point",
"coordinates": [
26.1372642328728,
47.7785316061887
]
}
}
]
}
}
什麼是您的GeoJSON的樣子?請提供演示此問題的[最小,完整,測試和可讀示例](http://stackoverflow.com/help/mcve)(包括示例GeoJSON)。 – geocodezip
添加了一個geojson示例 –