(一)Geoserver安装:
官网网址:http://geoserver.org/download/
(二)Geoserver添加mysql数据源:
1、在mysql数据库中建表
-- ----------------------------
-- Table structure for points
-- ----------------------------
DROP TABLE IF EXISTS `points`;
CREATE TABLE `points` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
`x` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`y` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`location` point NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
SPATIAL INDEX `sp_index`(`location`)
) ENGINE = MyISAM AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of points
-- ----------------------------
INSERT INTO `points` VALUES (1, '圆明园', '116.310558', '40.014033', ST_GeomFromText('POINT(116.311 40.014)'));
INSERT INTO `points` VALUES (2, '清华大学', '116.335279', '40.010497', ST_GeomFromText('POINT(116.335 40.0105)'));
INSERT INTO `points` VALUES (3, '颐和园', '116.277787', '116.277787', ST_GeomFromText('POINT(116.278 40.0065)'));
INSERT INTO `points` VALUES (4, '天安门', '116.404844', '39.915378', ST_GeomFromText('POINT(116.405 39.9154)'));
INSERT INTO `points` VALUES (5, '北京站', '116.434164', '39.910065', ST_GeomFromText('POINT(116.434 39.9101)'));
INSERT INTO `points` VALUES (6, '卢沟桥', '116.224895', '39.85647', ST_GeomFromText('POINT(116.225 39.8565)'));
INSERT INTO `points` VALUES (7, '北京西站', '116.32723', '39.901652', ST_GeomFromText('POINT(116.327 39.9025)'));
INSERT INTO `points` VALUES (8, '北京首都国际机场', '116.612388', '40.085613', ST_GeomFromText('POINT(116.612 39.9025)'));
2、安装mysql插件:
下载插件网址:https://zh.osdn.net/projects/sfnet_geoserver/releases/
将下载好的插件压缩包解压后,将其中的所有jar包,放入geoserver/webapps/WEB-INF/lib目录下
3、启动geoserver,点击geoserver的bin目录下startup.bat
登录地址:http://localhost:8090/geoserver/web/
默认的用户名是admin,密码geoserver
(1)添加工作区
点击数据栏 工作区 -> 添加新的工作区
(2)添加数据存储
(3)用openlayers发布
geoserver发布mysql中数据图层: