world map tooltips
This commit is contained in:
parent
ae51542d2e
commit
3ee0264c22
|
@ -40,22 +40,14 @@ var AddMapLandmass = func(w *DfWorld, id int) template.HTML {
|
||||||
c2 := strings.Split(x.Coord2, ",")
|
c2 := strings.Split(x.Coord2, ",")
|
||||||
x2, _ := strconv.Atoi(c2[0])
|
x2, _ := strconv.Atoi(c2[0])
|
||||||
y2, _ := strconv.Atoi(c2[1])
|
y2, _ := strconv.Atoi(c2[1])
|
||||||
return template.HTML(fmt.Sprintf(`<script>addRegion('%s', %d, %d, %d, %d, '#FFF')</script>`, x.Name_, x1, y1, x2, y2))
|
return template.HTML(fmt.Sprintf(`<script>addLandmass(%d, %d, %d, %d, %d, '#FFF')</script>`, x.Id_, x1, y1, x2, y2))
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var AddMapRegion = func(w *DfWorld, id int) template.HTML {
|
var AddMapRegion = func(w *DfWorld, id int) template.HTML {
|
||||||
if x, ok := w.Regions[id]; ok {
|
if x, ok := w.Regions[id]; ok {
|
||||||
r := "<script>"
|
coords := strings.Join(util.Map(x.Outline(), func(c Coord) string { return fmt.Sprintf(`coord(%d,%d)`, c.X, c.Y-1) }), ",")
|
||||||
r += "var polygon = L.polygon(["
|
|
||||||
r += strings.Join(util.Map(x.Outline(), func(c Coord) string { return fmt.Sprintf(`coord(%d,%d)`, c.X, c.Y-1) }), ",")
|
|
||||||
r += "], { color : '#fff', opacity: 1, fillOpacity: 0, weight : 1 }).addTo(regionsLayer);\n"
|
|
||||||
r += "attachTooltip(polygon, '" + x.Name_ + "');\n"
|
|
||||||
|
|
||||||
r += "polygon.on('mouseover', function (e) { this.setStyle({weight: 10}); });\n"
|
|
||||||
r += "polygon.on('mouseout', function (e) { this.setStyle({ weight: 3}); });\n"
|
|
||||||
|
|
||||||
fillColor := "transparent"
|
fillColor := "transparent"
|
||||||
switch x.Evilness {
|
switch x.Evilness {
|
||||||
case RegionEvilness_Evil:
|
case RegionEvilness_Evil:
|
||||||
|
@ -63,12 +55,7 @@ var AddMapRegion = func(w *DfWorld, id int) template.HTML {
|
||||||
case RegionEvilness_Good:
|
case RegionEvilness_Good:
|
||||||
fillColor = "aqua"
|
fillColor = "aqua"
|
||||||
}
|
}
|
||||||
if fillColor != "transparent" {
|
return template.HTML(fmt.Sprintf(`<script>addRegion(%d, [%s], '%s')</script>`, x.Id_, coords, fillColor))
|
||||||
r += "var evilPolygon = L.polygon(polygon.getLatLngs(), { color: 'transparent', opacity: 1, fillColor: '" + fillColor + "', fillOpacity: .3, interactive: false });\n"
|
|
||||||
r += "evilPolygon.addTo(evilnessLayer);\n"
|
|
||||||
}
|
|
||||||
r += "</script>"
|
|
||||||
return template.HTML(r)
|
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -110,7 +97,7 @@ var AddMapWorldConstruction = func(w *DfWorld, id int) template.HTML {
|
||||||
color := util.If(x.Type_ == WorldConstructionType_Tunnel, "#000", "#fff")
|
color := util.If(x.Type_ == WorldConstructionType_Tunnel, "#000", "#fff")
|
||||||
line := x.Line()
|
line := x.Line()
|
||||||
if len(line) == 1 {
|
if len(line) == 1 {
|
||||||
return template.HTML(fmt.Sprintf(`<script>addWc('%s', %d, %d, '%s')</script>`, x.Name_, line[0].X, line[0].Y, color))
|
return template.HTML(fmt.Sprintf(`<script>addWc(%d, %d, %d, '%s')</script>`, x.Id_, line[0].X, line[0].Y, color))
|
||||||
} else {
|
} else {
|
||||||
r := "<script>"
|
r := "<script>"
|
||||||
r += "var polyline = L.polyline(["
|
r += "var polyline = L.polyline(["
|
||||||
|
|
|
@ -151,7 +151,7 @@ function addWc(id, y, x, color) {
|
||||||
attachTooltip(polygon, urlToolTip("worldconstruction", id));
|
attachTooltip(polygon, urlToolTip("worldconstruction", id));
|
||||||
}
|
}
|
||||||
|
|
||||||
function addRegion(name, y1, x1, y2, x2, color) {
|
function addLandmass(id, y1, x1, y2, x2, color) {
|
||||||
x1--; y2++;
|
x1--; y2++;
|
||||||
var polygon = L.polygon(
|
var polygon = L.polygon(
|
||||||
[coord(y1, x1), coord(y2, x1), coord(y2, x2), coord(y1, x2)], {
|
[coord(y1, x1), coord(y2, x1), coord(y2, x2), coord(y1, x2)], {
|
||||||
|
@ -160,7 +160,7 @@ function addRegion(name, y1, x1, y2, x2, color) {
|
||||||
weight: 1
|
weight: 1
|
||||||
}).addTo(landmassesLayer);
|
}).addTo(landmassesLayer);
|
||||||
|
|
||||||
attachTooltip(polygon, name);
|
attachTooltip(polygon, urlToolTip("landmass", id));
|
||||||
}
|
}
|
||||||
|
|
||||||
function addMountain(id, y, x, color) {
|
function addMountain(id, y, x, color) {
|
||||||
|
@ -210,3 +210,16 @@ function addBattle(name, y, x) {
|
||||||
maxx = Math.max(x, maxx);
|
maxx = Math.max(x, maxx);
|
||||||
maxy = Math.max(y, maxy);
|
maxy = Math.max(y, maxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addRegion(id, coords, fillColor) {
|
||||||
|
var polygon = L.polygon(coords, { color: '#fff', opacity: 1, fillOpacity: 0, weight: 1 }).addTo(regionsLayer);
|
||||||
|
attachTooltip(polygon, urlToolTip('region', id));
|
||||||
|
|
||||||
|
polygon.on('mouseover', function (e) { this.setStyle({ weight: 10 }); });
|
||||||
|
polygon.on('mouseout', function (e) { this.setStyle({ weight: 3 }); });
|
||||||
|
|
||||||
|
if (fillColor != "transparent") {
|
||||||
|
var evilPolygon = L.polygon(polygon.getLatLngs(), { color: 'transparent', opacity: 1, fillColor: fillColor, fillOpacity: .3, interactive: false });
|
||||||
|
evilPolygon.addTo(evilnessLayer);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue