在 Google 个地图中使用来自 Geojson 的 Sprite 自定义标记
Custom Marker with Sprite from Geojson in Google Maps
我正在使用 geoJSON 作为 Google 地图的数据源。我想使用精灵中的自定义标记,仅更改 iconOrigin。
map.data.setStyle(function(feature) {
var origin=null;
var iconUrl = 'library/css/marker-sprite.png';
var iconSize = new google.maps.Size(50, 50);
var iconAnchor = new google.maps.Point(25, 50);
var iconScaledSize = new google.maps.Size(150, 150);
if (feature.getProperty('origin')) {
origin = feature.getProperty('origin');
var iconOrigin = 'new google.maps.Point(' + origin + ')';
}
return ({
icon: {
url: iconUrl,
size: iconSize,
anchor: iconAnchor,
origin: iconOrigin,
scaledSize: iconScaledSize
}
});
});
geoJSON(部分)
"properties": {
"id-intern": "123",
"title": "Marker Title",
"content": "lorem ipsum",
"origin": "0, 100"
},
有人看到我的方法有误吗?
谢谢。
感谢@Craicerjack 展示曲目!这样就可以了。
map.data.setStyle(function(feature) {
var iconoriginx = null;
var iconoriginy = null;
var iconUrl = 'library/css/marker-sprite.png';
var iconSize = new google.maps.Size(50, 50);
var iconAnchor = new google.maps.Point(25, 50);
var iconScaledSize = new google.maps.Size(150, 150);
if (feature.getProperty('iconoriginy')) {
iconoriginy = feature.getProperty('iconoriginy');
iconoriginx = feature.getProperty('iconoriginx');
var iconOrigin = new google.maps.Point(iconoriginx,iconoriginy);
}
return ({
icon: {
url: iconUrl,
size: iconSize,
anchor: iconAnchor,
origin: iconOrigin,
scaledSize: iconScaledSize
}
});
});
和带有两个分隔值(数字!)的 geoJSON。
"properties": {
"id-intern": "123",
"title": "Marker Title",
"content": "lorem ipsum",
"iconoriginx": 0,
"iconoriginy": 100
},
我正在使用 geoJSON 作为 Google 地图的数据源。我想使用精灵中的自定义标记,仅更改 iconOrigin。
map.data.setStyle(function(feature) {
var origin=null;
var iconUrl = 'library/css/marker-sprite.png';
var iconSize = new google.maps.Size(50, 50);
var iconAnchor = new google.maps.Point(25, 50);
var iconScaledSize = new google.maps.Size(150, 150);
if (feature.getProperty('origin')) {
origin = feature.getProperty('origin');
var iconOrigin = 'new google.maps.Point(' + origin + ')';
}
return ({
icon: {
url: iconUrl,
size: iconSize,
anchor: iconAnchor,
origin: iconOrigin,
scaledSize: iconScaledSize
}
});
});
geoJSON(部分)
"properties": {
"id-intern": "123",
"title": "Marker Title",
"content": "lorem ipsum",
"origin": "0, 100"
},
有人看到我的方法有误吗?
谢谢。
感谢@Craicerjack 展示曲目!这样就可以了。
map.data.setStyle(function(feature) {
var iconoriginx = null;
var iconoriginy = null;
var iconUrl = 'library/css/marker-sprite.png';
var iconSize = new google.maps.Size(50, 50);
var iconAnchor = new google.maps.Point(25, 50);
var iconScaledSize = new google.maps.Size(150, 150);
if (feature.getProperty('iconoriginy')) {
iconoriginy = feature.getProperty('iconoriginy');
iconoriginx = feature.getProperty('iconoriginx');
var iconOrigin = new google.maps.Point(iconoriginx,iconoriginy);
}
return ({
icon: {
url: iconUrl,
size: iconSize,
anchor: iconAnchor,
origin: iconOrigin,
scaledSize: iconScaledSize
}
});
});
和带有两个分隔值(数字!)的 geoJSON。
"properties": {
"id-intern": "123",
"title": "Marker Title",
"content": "lorem ipsum",
"iconoriginx": 0,
"iconoriginy": 100
},